For Loop help pls

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
fuhrer
Captain
Posts: 253
Joined: Sun Mar 14, 2004 3:36 am

For Loop help pls

Post 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
lizardkid
Windows Zealot
Posts: 3672
Joined: Fri Mar 19, 2004 7:16 pm
Location: Helena MT

Post 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.
Moderator

۞
Abyssus pro sapientia
Olympus pro Ignarus
۞

AND STUFF™ © 2006
fuhrer
Captain
Posts: 253
Joined: Sun Mar 14, 2004 3:36 am

Post 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
lizardkid
Windows Zealot
Posts: 3672
Joined: Fri Mar 19, 2004 7:16 pm
Location: Helena MT

Post 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.
Moderator

۞
Abyssus pro sapientia
Olympus pro Ignarus
۞

AND STUFF™ © 2006
fuhrer
Captain
Posts: 253
Joined: Sun Mar 14, 2004 3:36 am

Post by fuhrer »

yeah i understand that part, i dont understand what its use is
Elgan
Site Admin
Posts: 890
Joined: Tue Apr 13, 2004 10:43 pm
Location: uk
Contact:

Post 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.
fuhrer
Captain
Posts: 253
Joined: Sun Mar 14, 2004 3:36 am

Post 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 :?
Grassy
First Lieutenant
Posts: 221
Joined: Sun Aug 22, 2004 11:36 am

Post 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
fuhrer
Captain
Posts: 253
Joined: Sun Mar 14, 2004 3:36 am

Post 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
Grassy
First Lieutenant
Posts: 221
Joined: Sun Aug 22, 2004 11:36 am

Post 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.
Post Reply