Jump to content
Mr.clean132

Help making script multiplayer compatible

Recommended Posts

Hi, I'm pretty new to scripting/coding and have largely been stalking the forums and repurposing other people's codes to get stuff to work for my personal missions.

 

I have a tank control script that works perfectly in single-player/when there is only one player per side, but when there are 2 people on the same team, it seems to give control of the created group to the other person. I'm not sure how to fix it, I've looked online but can't seem to find anything.
I could always go back to having a unit recruitment script but for my dedicated tank pvp mission I thought this would be better, so any help getting it working would be appreciated. (if it makes any difference, I'm hosting this as a multiplayer game from my PC)

 

the script is this, placed in the init of each vehicle I want the script to apply to. 

this addEventHandler ["GetIn", {  
_tank = _this select 0;  
_unit = _this select 2;  
If(isplayer _unit) then {  
createVehicleCrew _tank;  
crew _tank select {!isplayer _x} joinSilent group player;  
} ;  
}] ;  
this addEventHandler ["GetOut",   
{  
   _tank = _this select 0;  
   _role = _this select 1;  
   _unit = _this select 2;  
   If(_role != "cargo")then  
   {  
      If(isplayer _unit) then   
      {  
         {deleteVehicle _x;} forEach crew _tank;  
      }  
      else  
      {  
         deleteVehicle _unit;  
      };  
   };  
}];

this is the script I have in the vehicle respawn modules expression field:

 

_this select 0 addEventHandler ["GetIn", {
_tank = _this select 0;
_unit = _this select 2;
If(isplayer _unit) then {
createVehicleCrew _tank;
crew _tank select {!isplayer _x} joinSilent group player;
} ;
}] ;
_this select 0 addEventHandler ["GetOut", 
{
   _tank = _this select 0;
   _role = _this select 1;
   _unit = _this select 2;
   If(_role != "cargo")then
   {
      If(isplayer _unit) then 
      {
         {deleteVehicle _x;} forEach crew _tank;
      }
      else
      {
         deleteVehicle _unit;
      };
   };
}];

 

Share this post


Link to post
Share on other sites

At first glance, this:

crew _tank select {!isplayer _x} joinSilent group player;  

should be this:

crew _tank select {!isplayer _x} joinSilent group _unit;  

In SP, the first works because there is only the one player unit. But in MP, there can be multiple players, which is why using the command "player" is generally not recommended in MP scripting. 

 

In the EH, the relevant unit is already represented by "_unit" (which is further being filtered by the earlier "isPlayer" check) so just use that in either case.

  • Like 4

Share this post


Link to post
Share on other sites

sorry for the late reply, I forgot to reply after testing this. but thank you very much, this fixed it.

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

×