Forum Jump :

Author Message

Posts: 5

Level: Member

Country: us
In-game name:

#1 Posted at 2013-08-27 21:02        
Okay so here's my problem. I'm trying to create a Horde-type mission similar to that in Gears of War or whatever. I have a number of triggers set to spawn in new waves after all the members of the previous wave have been killed. The group is set to spawn on a preset Opfor unit, who is at the beginning of the mission, set to hideobject. After the trigger is activated, he is set to hideobject false, becoming part of the next wave. The "invisible" Opfor unit is also set to follow a waypoint of Seek and Destroy to create a kind of random spawn pattern of the wave. The triggers and everything work beautifully, however when the new units are spawned they just stand there. What I would like to do is have the new units follow the "invisible" guy so that they will run around hunting players down.

The Invisible guy is named "a" and his Init field looks as such :
red = groupthis ; a hideobject true ; removeallweapons this ;

The trigger, when activated, looks like this:
hint "Wave 1 Cleared          Begin Wave 2" ; red = creategroup east;"TK_INS_Soldier_3_EP1" createUnit [position a, red, "newUnit = this; addSwitchableUnit newUnit;", .2, "private"];
The line is repeated several times for each individual unit in the next wave.
If everything went smoothly, the new unit(s) would join the group of the invisible guy, red, and would follow him. Maybe my issue is due to the addswitchable part of the line, I don't know. The code was pulled from the Bohemia Wiki, I'm more of a copy and paste artist. If anyone can help me figure this small issue out it would be greatly appreciated.

Author Message

Posts: 48

Level: Member

Country: fr
In-game name:

#2 Posted at 2013-09-05 23:32        
Here is a little script I made for one of my missions that I believe might help you, check it out! (it works on dedicated as well as on single player).

spawn.sqf :
_array = ["TK_INS_Soldier_EP1","TK_INS_Bonesetter_EP1","ACE_TK_INS_Soldier_AKM_EP1","TK_INS_Soldier_2_EP1","TK_INS_Soldier_MG_EP1"]; //array of units you want to spawn.
compteur = 0;//var to count the number of alive ennemies in the current wave/overall wave.

while {!contactDone} do {//put whatever you want instead of contactDone var

	for "_i" from 1 to ((5 * (count units group_resist)) - compteur) step 1 do {//note that you can change the limits of for loop
		_group 	= createGroup east;//make sure the side matches the side of the unit you want to spawn. Note that this is inside the for loop, so each unit will have its own group
		_pos 	= getMarkerPos ("spawn_gue" + str(floor(random 4)));//random pos from 4 different markers,you can use a different method to calculate a position for your group to spawn
		_r 		= floor (random (count _array));//random variable to select one of the soldier inside the array
		_vehi 	= _array select _r;//soldier picked inside array
		_unit 	= _group createUnit [_vehi, _pos, [], 0, "NONE"];
		_unit addMPEventHandler ["MPKilled", {compteur = compteur - 1;}];//event handler that fires once the unit is killed, not really needed depending on what you want
		[_unit] join _group;
		_unit move pos_med ;//makes the unit move to a certain position (in this case pos_med)
		_group setBehaviour "COMBAT";
		compteur = compteur + 1;
	sleep 30;

//The following lines are a blind guess about how much time I think the attack will last.
//It's useful when you want something to happen once the attack is over.
//For instance I could use my compteur variable (which count the unit of alive units in the wave).
//I just use the following lines to make sure the next part of the mission triggers correctly.
sleep 600;
enoughTime = true;
publicVariable "enoughTime";

Call this script whenever needed (if multiplayer make sure it's only called once). Just make sure you have at least one unit, of the side you want the unit to spawn, already present on the field.

I hope this is clear and it helps you, if not feel free to ask any question!

Note that I now use a better method to calculate the spawn position of units using SHK pos script. I can provide you with the code if needed.