cnt

Smellis

New member
Joined
May 22, 2011
Messages
22
Could anyone give me any tips with "[cnt]"  im trying to make a script that creates 10  platoons in a random spot, that respawn after killed. in previous versions i got one platoon to respawn after they died and stopped the loop after i press escape but once i started messing with count to try and get many platoons to do this i started to get in over my head hehe. anyone know how to repair this?
Code:
define script Fight




begin script Fight
cnt = 0
qplatoon[cnt] = 0
qRandomnumber = 0
Randomnumber = 0
Middle = marker at {1250,29,1110}
		
start

begin loop
	qRandomnumber = number from -423 to 423
	Randomnumber = number from -423 to 423
	
		//randomnumber is radius of map from middle
	
	if qplatoon[cnt] not exists
		qplatoon[cnt] = create platoon PLATOON_INFO_AZTEC_RANGED_3 at {Middle}+{Randomnumber,0,qRandomnumber} with 100 men and 0 women
		cnt ++
	end if


	wait until cnt == 10

end loop

end script Fight

this is the code that worked to spawn infinite platoons after each one died.

Code:
define script Fight




begin script Fight

qplatoon = 0
qRandomnumber = 0
Randomnumber = 0
Middle = marker at {1250,29,1110}
		
start

begin loop
	qRandomnumber = number from -423 to 423
	Randomnumber = number from -423 to 423
	
		//randomnumber is radius of map from middle
	
	if qplatoon not exists
		qplatoon = create platoon PLATOON_INFO_AZTEC_RANGED_3 at {Middle}+{Randomnumber,0,qRandomnumber} with 100 men and 0 women
	
	end if


	until key KB_ESC down

end loop

end script Fight
 
  I think something like this will work. There are a few different ways to do this..

  Remember arrays start from 0, so for 10 platoons, the array should actually be 0-9. I think this script compiler uses the declared number as the last index rather than a count ( [9] means 0 - 9, not "9 items" which would be 0 - 8).

  It occurred to me while looking at this, and I think this is correct: If you want a loop to stop when some condition is met, like pressing escape, you should probably only include one 'pass' per loop iteration. If you checked all 10 platoons in one loop, there may be a significant delay in the condition being met and the loop actually ending. In reality, I don't think it matters in this case, but if you have a more complicated loop, this can become annoying for the player.

Code:
define script Fight


begin script Fight

cnt = 0
qplatoon[9]
qRandomnumber = 0
Randomnumber = 0
Middle = marker at {1250,29,1110}
		
start

begin loop

	//randomnumber is radius of map from middle

	if qplatoon[cnt] not exists
		qRandomnumber = number from -423 to 423
		Randomnumber = number from -423 to 423
		qplatoon[cnt] = create platoon PLATOON_INFO_AZTEC_RANGED_3 at {Middle}+{Randomnumber,0,qRandomnumber} with 100 men and 0 women
	end if


	if cnt == 9
		cnt = 0
	else
		cnt++
	end if


until key KB_ESC down
end loop

end script Fight


-ego533
 
that works great thank you. i intend to change the esc stuff im just trying to teach myself  the basics before i put it into my map.

how would one set attack orders and or set players for these platoons?

on an unrelated subject ive made a megablast similar to daxters, not sure i can post code, but it fires on left mouse down with key A down until not leftmouse down ( so it is one shot) what line could i use to deduct mana? i can set player 0 mana but thats about it.

cheers.
 
I think it would be [ set player 0 mana get player 0 mana - 400 ]. I've noticed that alot of commands or variations of commands are not documented. In this case, the 'get player X mana' is never actually mentioned anywhere, but you can just basically guess that it exists since 'set player X mana' exists...

Setting platoon players is just [ set qplatoon[cnt] player X ]. Issuing orders can technically be done in several ways.. How and why you decided to give the orders is the complication. If you want the platoons to do a single thing, just create the order like [ add action PLATOON_AGENDA_ACTION_ATTACK using playercreature to qplatoon[cnt] action queue ] or [ set qplatoon[cnt] attack playercreature with severity X ]. If you want them to decide what to attack, you will need to write a simple AI script.. like "find weakest wall section and attack it" or "find weakest enemy platoon and attack it".

-ego533
 
Back
Top