distance checking

Topics regarding Scripting with Reality Factory
Post Reply
User avatar
darksmaster923
Posts: 1857
Joined: Wed Jan 03, 2007 10:32 pm
Location: Huntington Beach, California, USA

distance checking

Post 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
Herp derp.
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post 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.
User avatar
darksmaster923
Posts: 1857
Joined: Wed Jan 03, 2007 10:32 pm
Location: Huntington Beach, California, USA

Post by darksmaster923 »

thats a cool idea. i should use arrays more
Herp derp.
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

yeah. Arrays were a great discovery for me...
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Post 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.
Everyone can see the difficult, but only the wise can see the simple.
-----
User avatar
darksmaster923
Posts: 1857
Joined: Wed Jan 03, 2007 10:32 pm
Location: Huntington Beach, California, USA

Post 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;
			}
		}
	} ]
}
Herp derp.
Post Reply