Page 1 of 1

For Loop help pls

Posted: Thu Feb 10, 2005 7:39 pm
by fuhrer
hello, i dont understand for loops, could someone pls help me, i just need the compass to point to a different obj(depending on situation) for each player in the game..

so far i have

Code: Select all

plans_compass:

while(1)
{
	if(($player.dmteam != allies) || ($player.origin != $plans.origin))
	{
	set_objective_pos $plans
	}
	else
	if(($player.dmteam == allies) || ($player.origin == $plans.origin))
	{
	set_objective_pos $radio_trigger
	}
	
waitframe
}	

end
which works with 1 person, maybe a simple for loop to count each player and assign their compass depending on the situation above.

thx

Posted: Thu Feb 10, 2005 10:01 pm
by lizardkid
while loops for for as long as the argument they have is true, so do for loops.

for(
[statement declaration]
local.i = 0;
[what variable to use and what value to use it at start]
local.i < 1;
[as long as this is true...]
local.i++)
[change the variable so it's not an infinite loop]

Code: Select all

for(local.i = 0; local.i < 1; local.i++)
{
// code
}
this only goes once, then stops.

Posted: Thu Feb 10, 2005 10:28 pm
by fuhrer
so if ur using it to add players what does it do with the info? say 5 people join, local.i will go from 1 - 5 .... then the loop stops?

im confused lol mummy

Posted: Fri Feb 11, 2005 12:43 am
by lizardkid
no, local.i is just a variable. it starts at 0, (local.i = 0;) the statement here (local.i < 1;) makes the loop stop when the variable reaches that stage in time, and this (local.i++) adds one to the variable each time the loop goes through. you can make it local.i-- as well to make it subract one.

i dont know the best way to use a for loop in an MP map, never had the inclination to try to script for MP.

Posted: Fri Feb 11, 2005 1:02 am
by fuhrer
yeah i understand that part, i dont understand what its use is

Posted: Fri Feb 11, 2005 3:04 am
by Elgan
the for loop loops through each player setting what ya want then at the end does it again cos ur inside a while never ending lop/.


Code: Select all


while(1)
{	
for(local.i=1;local.i<=$player.size;local.i++)
{
   if(($player[local.i].dmteam == axis) || ($player[local.i].origin != $plans.origin))
   {
   	set_objective_pos $plans
   }
   else  if(($player[local.i].dmteam != spectator) || ($player[local.i].origin == $plans.origin))
   {
  	 set_objective_pos $radio_trigger
   }
  }
waitframe
}   


i changed ur dmteam thign so that it checks if they are axis if not it then checks if they are not a speccy so they are a allie.

Posted: Fri Feb 11, 2005 6:53 pm
by fuhrer
i think my problem lies in the fact that the command.... set_objective_pos sets the objective position for everyone, maybe its used in single player i dont know...

but with that loop its trying to set the objective in 2 positions at the same time therefore renderign the compass very confused :?

Posted: Mon Feb 14, 2005 3:29 pm
by Grassy
You dont state if it's AA or SH you are working with.
For SH have a look in this thread.
http://dynamic4.gamespy.com/~map/mohaa/ ... php?t=9726

Posted: Thu Feb 17, 2005 1:03 pm
by fuhrer
sorry i keep forgetting things differ between the 2, im actually runnin the game in BT, n that thread ty but it appears to be for "everyone" not for individual people

Posted: Thu Feb 17, 2005 8:38 pm
by Grassy
Ahh :oops:

Well the commands are used in BT as well.
BT in my opinion is the best as it is backward compatible with SH and AA.
It sometimes has no problems with AA only maps and scripts whereas SH will. If you use the same method as shown in that thread for your script in BT it will work fine.