Jump to content
Sign in to follow this  
alexluthor

Spawning units in random direction - Dedicated Server

Recommended Posts

Guys, I'm having some problems using a script in multiplayer. My intent is to use this on a training mission, where the instructor would be able to spawn units in front of the players in a somewhat random position. He should be able to do it by using an addaction

I've built a script using samples from Kylania (http://www.kylania.com/site/) and it works fine in my machine, but when I play it on the dedicated server the units never spawn. Below follow the code:

Addaction placed on the init of the instructor

this addAction ["ContactFront","ContactFront.sqf",(3)];

ContactFron.sqf in the mission folder

// Select the user of the addaction and the number of enemy units.
_sourcePoint = _this select 1;
_enemyCount = _this select 3;

// Select random direction in front of the addaction’s user.
_randDir = getDir vehicle _sourcePoint - 45;
_randDir = _randDir + random(90);
_randDist = (random 100) + 200;
_enemyLoc =	[(getPos vehicle _sourcePoint select 0) + (_randDist * sin(_randDir)), (getPos vehicle _sourcePoint select 1) + (_randDist * cos(_randDir)), 0];

// Create attack group and lead them to the player’s location.
grp = [_enemyLoc, east, _enemyCount] call BIS_fnc_spawnGroup;
null = [grp,(getPos vehicle _sourcePoint)] call BIS_fnc_taskAttack;
grp reveal _sourcePoint;

Does anyone have a clue why it is not working in the dedicated server?

Appreciate the help guys.

Share this post


Link to post
Share on other sites

Thanks for the clarification and for the framework. They`ll be good additions to my library : )

I`ve remembered that I`ve read here that the triggers send the commands to all machines, so I figure it might solve my problem.

I`ve changed the idea from the addactions to radio activated triggers. For that, I`ve placed the following code into the activation field of a radio activation trigger

nul = [(Instructor), 8] execVM "ContatoFrente.sqf";

Whereas Instructor is the name of the Instructor model. And I`ve pretty much copied Kylania`s script as follows.

if (isServer) then {

// Select instructor and number of enemies
_sourcePoint = _this select 0;
_enemyCount = _this select 1;

// Select random enemy position in front of player.
_randDir = getDir vehicle _sourcePoint - 45;
_randDir = _randDir + random(90);
_randDist = (random 100) + 200;
_enemyLoc =	[(getPos vehicle _sourcePoint select 0) + (_randDist * sin(_randDir)), (getPos vehicle _sourcePoint select 1) + (_randDist * cos(_randDir)), 0];

// Create group and reveal players position
grp = [_enemyLoc, east, _enemyCount] call BIS_fnc_spawnGroup;
null = [grp,(getPos vehicle _sourcePoint)] call BIS_fnc_taskAttack;
grp reveal _sourcePoint;

};

It is working in my machine again. Once I test it on a dedicated server I`ll post the results below.

Thanks again for the help.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×