Page 1 of 1

distance checking

Posted: Tue Jul 24, 2007 10:17 pm
by darksmaster923
hello all, i have a few qs
1. Can pawns have mulitple targets?
2.i want to check the distance with mulitple pawns WITH OUT going to a new order or needing entity names

Posted: Wed Jul 25, 2007 12:02 am
by federico
Call your Pawns ENEMY0, ENEMY1, ENEMY2, ENEMY3... and so on.
then in your order:

Code: Select all

for i=0 to NUMBER_OF_ENEMIES
{
     if(DistanceTo("ENEMY" # Integer(i)) < DISTANCE_THAT_WAKE_ME_UP )
     {
         // do things ...
     }
}
eventually you can declare an array as variable to store those datas:

Code: Select all

PAWN_DISTANCE
{
     PAWN_DISTANCE0 [0]
     PAWN_DISTANCE1 [0]
     PAWN_DISTANCE2 [0]
     PAWN_DISTANCE3 [0]
     PAWN_DISTANCE4 [0]
     PAWN_DISTANCE5 [0]
     PAWN_DISTANCE6 [0]
}
I made seven members for this array, create how many you need. Then...

Code: Select all

for i=0 to NUMBER_OF_ENEMIES
{
     PAWN_DISTANCE[i] = DistanceTo("ENEMY" # Integer(i));
}
...so PAWN_DISTANCE[5] will store DistanceTo("ENEMY5");

Be careful: if NUMBER_OF_ENEMIES is bigger than your array, you will get an error.

Posted: Wed Jul 25, 2007 5:33 am
by darksmaster923
thats a cool idea. i should use arrays more

Posted: Thu Jul 26, 2007 3:11 pm
by federico
yeah. Arrays were a great discovery for me...

Posted: Sat Jul 28, 2007 6:01 pm
by Jay
wow. that's cool. i never knew you could use arrays. i have one question though: Does the index of an array start with 0 (like in c/C++) or with 1?

EDIT: Nevermind, i found out that the index starts with 0.

Posted: Mon Aug 20, 2007 9:59 pm
by darksmaster923
hm its not working. maybe becuz some of the other allies are out of zone...
script

Code: Select all

{

	timer 		[0]
	ustime		[0]
	ttime		[0]
	playerdis	[0]
	terrorist	[4]
	us		[3]
	killt		[false]
	killus		[false]

	usdis
	{
		usdis0	[0]
		usdis1	[0]
		usdis2	[0]
	}
	tdis
	{
		tdis0	[0]
		tdis1	[0]
		tdis2	[0]
		tdis3	[0]
	}
	caprange	[2000]
	


	Spawn[ ()
	{
		Console(true);
		LowLevel("Setup");
	} ]
	
	Setup[ ()
	{
		self.think = "check";
	} ]

	check[ ()
	{
		for i=0 to terrorist
		{
			tdis[i] = GetDistanceTo("ENEMY" # Integer(i));
     			if(GetDistanceTo("ENEMY" # Integer(i)) < caprange)
     			{
				ttime = ttime + 0.01;
				ModifyAttribute("terr",ttime,"Player");
				killt = false;
				
    			}
			else
			{
				if(killt = false)
				{
					SetAttribute("terr", 0, "Player" );
					killt = true;
				}
			}
		}
		for i=0 to us
		{
			debug(usdis[i]);
			usdis[i] = GetDistanceTo("ALLY" # Integer(i));
     			if(GetDistanceTo("ALLY" # Integer(i)) < caprange)
     			{
				ustime = ustime + 0.01;
				ModifyAttribute("usmc",ustime,"Player");
				killus = false;
    			}
			else
			{
				if(killus = false)
				{
					SetAttribute("usmc", 0, "Player" );
					killus = true;
				}
			}
		}
		if(self.player_range < caprange)
		{
				ustime = ustime + 0.01;
				ShowText(1, self.EntityName, "", "The Zone", 12, "", 0, 2, "center", 200);
				ModifyAttribute("usmc",ustime,"Player");
				killus = false;
		}
		else
		{
			if(killus = false)
			{
				SetAttribute("usmc", 0, "Player" );
				killus = true;
			}
		}
	} ]
}