Jump to content
WPK-ArmedVeteran

Vehicle respawn loop - multiple vehicles instead of one

Recommended Posts

Hi all.
I'm a total noob to Arma scripting (or scripting at all). I've read some tutorials, but still, nothing better than expirience.
But, back to the point. I've been creating a MULTIPLAYER mission with Mobile HQ. I've done some testing with my friends, and generally most of things work, but there's this one issue I can't solve.
Here's the code of the script I'm going to reference (the file name is mhq1.sqf and it is executed by execVM in init.sqf):
 

Spoiler

while {true} do 
      { 
      "MHQ1" setMarkerPos getPos mhq1; sleep 0.1;
        if((damage mhq1)==1) then
        {

            hint "MHQ1 destroyed!"; 
            sleep 2;
            mhq1 = "CUP_I_SUV_Armored_ION" createVehicle getMarkerPos "mhq1SpawnMarker";
        };
      };

 

MHQ1 is obviously a name of a marker I have set.
mhq1 is the variable, name of object - SUV I have spawned in the editor.

mhq1SpawnMarker is another marker I've put down in the base.


The marker moving works fine.

Now, when I am alone on the server and destroy the MHQ only one MHQ respawns. But then, when a friend of mine joins and we do the same, 2 of them spawn. If another friend join there are 3 vehicles spawning and so on. I've tried multiple variations of this code, including using remoteExec function, but no luck. I can't understand what's the issue, why this isn't working. I am aware that I could use a ready script from the net, but I'd like to learn scripting the way I'm doing it now instead of using other's work. Anyway, thans in advance for helping me out.

Share this post


Link to post
Share on other sites

Can you guys explain how does it work? I understand that I need it to force the execution of the code for machines other than server, but why?

Share this post


Link to post
Share on other sites

No, you need to do the code only on the server.  Generally, it is a good idea to only do mission stuff on the server, as it guaranteed to be connected throughout the duration of the mission.  (Clients can come and go).

 

Firstly, you need to understand that "init.sqf" is executed on every machine in the game (so the server, and all clients)

 

"!" means "not", and "isServer" means "is the server".

 

"exitWith {};" means "quit now"

 

So what you are doing is saying that if the machine running this code is not the server then exit the script.

 

Otherwise, you are executing your code on the server and each connected client (I guess you are locally hosted and not using a dedicated server).

 

So your loop is ran on each PC and this line:

 

mhq1 = "CUP_I_SUV_Armored_ION" createVehicle getMarkerPos "mhq1SpawnMarker"; 

 

is executed on every machine.

 

Therefore, each connected player is trying to spawn an MHQ

  • Like 1

Share this post


Link to post
Share on other sites
8 hours ago, das attorney said:

No, you need to do the code only on the server.  Generally, it is a good idea to only do mission stuff on the server, as it guaranteed to be connected throughout the duration of the mission.  (Clients can come and go).

 

Firstly, you need to understand that "init.sqf" is executed on every machine in the game (so the server, and all clients)

 

"!" means "not", and "isServer" means "is the server".

 

"exitWith {};" means "quit now"

 

So what you are doing is saying that if the machine running this code is not the server then exit the script.

 

Otherwise, you are executing your code on the server and each connected client (I guess you are locally hosted and not using a dedicated server).

 

So your loop is ran on each PC and this line:

 


mhq1 = "CUP_I_SUV_Armored_ION" createVehicle getMarkerPos "mhq1SpawnMarker"; 

 

is executed on every machine.

 

Therefore, each connected player is trying to spawn an MHQ

THANK YOU :D

Share this post


Link to post
Share on other sites

Although, there is a new problem. After destroying the MHQ while my friend tries to teleport he teleports into wreckage of the previous MHQ, instead of new one, because the script is only executed for me.

@Update Nevermind lol. I managed to fix this using publicVariable in this script and getVariable before moveInCargo in teleporting script.

Edited by Ranlab99
  • Like 1

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

×