Home   Help Search Login Register  

Author Topic: createVehicle problem in multiplayer.  (Read 3230 times)

0 Members and 1 Guest are viewing this topic.

Offline ZuppR

  • Members
  • *
createVehicle problem in multiplayer.
« on: 24 Jul 2009, 18:37:11 »
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.

How do I prevent it from creating the vehicle X times the X players on?

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: createVehicle problem in multiplayer.
« Reply #1 on: 24 Jul 2009, 19:18:54 »
Welcome to OFPEC  :good:

Check out the locality part of Spooner/Mandoble's Multiplayer Tutorial.
« Last Edit: 24 Jul 2009, 19:33:39 by bedges »

Offline ZuppR

  • Members
  • *
Re: createVehicle problem in multiplayer.
« Reply #2 on: 24 Jul 2009, 20:55:31 »
Hello bedges, thanks for the welcome.

I've read through the tutorial that you linked to, tried a few other methods however the result is still the same.

Here's a snippet of my init, and script file.


My init:
Code: [Select]
[] exec "script\heli.sqf"

My heli.sqf:
Code: [Select]
_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.


Offline cptHook

  • Members
  • *
Re: createVehicle problem in multiplayer.
« Reply #3 on: 25 Jul 2009, 16:50:42 »
Hi there
I have made a create m1a1 sqf that works for me ,havnt tryed with heli but you could give it a go or just change it to make any vehicle.
TO work this script place an object ,say a heavy factory then place this in init..    this addAction ["Build me an M1A1", "createM1A1.sqf"]  ..   then place  a marker at same point with the name.  createM1A1..
« Last Edit: 26 Jul 2009, 18:54:30 by cptHook »

Offline BATTLE-TOAD

  • Members
  • *
Re: createVehicle problem in multiplayer.
« Reply #4 on: 26 Jul 2009, 02:29:33 »
As far as i know the Init will always be executed just once at the very beginning of the mission. regaurdless of other people joining. sounds to me like the init is being called on elsewhere in the mission.

Do you have any other scripts or perhaps some unit/vehicle/object inits that are calling init.sqf?


Depending on how you want the heli to be spawned you could consider using a trigger that will execute just once when a player has spawned on the map or when a certain condition has been met.


Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: createVehicle problem in multiplayer.
« Reply #5 on: 26 Jul 2009, 16:37:35 »
Quote
As far as i know the Init will always be executed just once at the very beginning of the mission. regaurdless of other people joining

My experiences with attempts to make JIP players neglect an intro says otherwise.
Meaning: init.sqf is ALWAYS read/active for any player, JIP or not.

I would put in the init script:

If you use .sqf:

waitUntil { !isNil {player} };
waitUntil { player == player };
if (player == myHeliSpawningUnit) then {call {[] execVM "script\heli.sqf"}};


If you use .sqs:

@ ! isNil player;
@ player == player;
if (player == myHeliSpawningUnit) then {call {[] execVM "script\heli.sqf"}};


In the editor, name a unit (the leader or who ever wanted) myHeliSpawningUnit.
Only the player playing that unit will then spawn the heli.

OR just do it on the server:

if (isServer) then {call {[] execVM "script\heli.sqf"}};

The hint needs to be run on all machines though if everyone should see it, so you might want to put that function in a trigger or something.

(To my knowledge your [] exec "script\heli.sqf" won't work, because execVM must be used with .sqf)

Good luck!

Laggy
« Last Edit: 26 Jul 2009, 17:01:57 by laggy »
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.