Jump to content
Sign in to follow this  
december

spawn vehicle function

Recommended Posts

I am using a script to spawn some tanks but on a dedicated server it looks like it is spawning vehicles for each player even though I have "if (!isServer) exitWith {};" at the start. Anyone see why it should be doing this? I am using the same script when I have random vehicle types spawned. This case I only want the T90.

if (!isServer) exitWith {};

_vehicle_types = ["T90"];

_max_dist_between_waypoints = 700;

_grpe1 = createGroup east;

_vec_type = floor (random count _vehicle_types);

[(getpos posm21), random 360, _vehicle_types select _vec_type, _grpe1] call BIS_fnc_spawnVehicle;

_grpe2 = createGroup east;

_vec_type = floor (random count _vehicle_types);

[(getpos posm22), random 360, _vehicle_types select _vec_type, _grpe2] call BIS_fnc_spawnVehicle;

};

Share this post


Link to post
Share on other sites

What's up with the }; at the end? full code or part of the code? if it's full code then remove it.

Share this post


Link to post
Share on other sites

Thanks for the suggestion but it didn't help with the problem. The script creates 6 tanks, I guess 2 for each player and 2 for the server. (2 players on the server testing)

Share this post


Link to post
Share on other sites

It's a urban legend that the line

if (!isServer) exitWith {};

does the same as (in sqs scripts)

?(!isServer): exit 

They are NOT and do NOT the same!

http://community.bistudio.com/wiki/exitwith

exitWith exits the execution of a loop defined by one of commands do, for, count or forEach. When you use exitWith not inside a loops, the behaviour is undefined - sometimes it may exit the script, sometimes some other scope, but this is not intended and designed behaviour of this command, and it is not guaranteed to work reliably.

It exits the loop only, not the script.

Do it this way instead:

if (isServer) then {
   // code to be executed on the server only
};

Edited by dengibtsschon

Share this post


Link to post
Share on other sites

I think I tried it that way also which is why I had the "};" at the end of the script but it didn't work. I will test it again.

Share this post


Link to post
Share on other sites

Tested as you recommended but still creating units for players and server.

Share this post


Link to post
Share on other sites

How are you calling the script? via Radio trigger? If so, then yes, it will run once for every player (including server itself) All the units will be local to the server, but there will be 2 for every player on the server.

This is one of the draw backs of using radio triggers. No way of knowing who ran the script, or allowing it to only be run on one person.

Better way around would be to use an addaction command.

Share this post


Link to post
Share on other sites

It is run in a trigger activated by Blufor when they enter an area.

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  

×