Jump to content
Sign in to follow this  
ZuppR

createVehicle problem in multiplayer.

Recommended Posts

Hey guys.

Through my init, I have executed a script which creates a vehicle.

It works as supposed in singleplayer, however if other people joins, it'll create the vehicle one time per player that is online.

Here's a snippet of my init, and sqf.

My init:

[] exec "script\heli.sqf"

My heli.sqf:

_heli = createVehicle ["UH1Y", _heli, [], 0, "None"];
_heli setPosASL [getposASL _heli select 0, getposASL _heli select 1, 15.9];
_heli setdir 180;
_heli engineon false;

_pilot = createGroup (west);
"USMC_Soldier_Pilot" createUnit [_heli, _pilot];
(units _pilot select 0) assignAsDriver _heli;
(units _pilot select 0) moveInDriver _heli;

hint "Your Helicopter starts in one minute."
_heli engineon true;
~60

Now, sure he doesn't fly anywhere, I'm aware of that, but that is not the problem.

If i start the mode, and go join myself, it all works as supposed, but due to (i guess) the whole locality thing, if other people join me, it will spawn the chopper and the pilots for every player that is in.

Meaning, that if I and another guy would be online, it would spawn two, if I another guy, and a third guy, it would spawn it three times.

What I'm trying to accomplish is prevent it from spawning multiple times.

Any help, or a good hint in the right direction would be more than appreciated.

Share this post


Link to post
Share on other sites

use

if (isServer) then {

[] exec "script\heli.sqf" ;

} ;

Share this post


Link to post
Share on other sites

Hey sbsmac.

Thanks for your reply.

However, your solution did not make any difference whatsoever.

It still spawns the helicopter once, per player connected. (which is 2 times with two players, 3 with three, etc.)

Share this post


Link to post
Share on other sites

maybe try launching script from trigger that fires once, and put the isserver command in the script. init.sqs or sqf are ran for each player connecting. That is why intros and such are good to have in there. For JIP though puting various script executions may result in repeated events.

Share this post


Link to post
Share on other sites

try this

? (Not(Isserver)) : Exit
_heli = createVehicle ["UH1Y", _heli, [], 0, "None"];
_heli setPosASL [getposASL _heli select 0, getposASL _heli select 1, 15.9];
_heli setdir 180;
_heli engineon false;

_pilot = createGroup (west);
"USMC_Soldier_Pilot" createUnit [_heli, _pilot];
(units _pilot select 0) assignAsDriver _heli;
(units _pilot select 0) moveInDriver _heli;

hint "Your Helicopter starts in one minute."
_heli engineon true;
~60

Share this post


Link to post
Share on other sites

Yes, what Junker has posted should work. It should make the script only run on the server, and not run again everytime a client connects. (From what has been explained to me :P)

? (Not(Isserver)) : Exit (sqs, I think you can use ! instead of Not if you wanted)

if (!isServer) exitWith {} (sqf)

Share this post


Link to post
Share on other sites

exitWith doesn't exit a script in SQF, only a codeblock.

That's why sbsmac wrapped his execute code in the isServer instead of just using a !isServer then quitting.

Share this post


Link to post
Share on other sites

Ah ok, nice to know...thanks for that :)

Either way, from what I am reading I think ZuppR has the information he is after. Let us know how it goes :)

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  

×