Jump to content
ninja8889

preventing a script from running on all clients

Recommended Posts

hello

 

so I've put together a mod for my clan which includes custom vests with nametags. The script itself functions fine the issue I run into is that the script re initialises whenever someone JIP's and despite my searching I cannot figure out how to stop it from doing that. Can anyone tell me how to fix this. The script is below. It's currently just being launched from the init line of the unit.

 

Thanks

 

 

//////////////////////unit variables///////////////
_soldier = player;
_place = typeOf player;
_uid = getPlayerUID player;
////////////vest variables//////////////////
_DefaultVest = "AUS_2014_Multicam_PlateCarrier";
_MrNinjaVest = "39th_Platecarrier_ninja";
_AnfoVest = "39th_Platecarrier_Anfo";
_LeroyVest = "39th_Platecarrier_Leroy";
_SeagullVest = "39th_Platecarrier_cgull";
_RooVest = "39th_Platecarrier_roo";
_RoyceVest = "39th_Platecarrier_Royce";
_BudVest = "39th_Platecarrier_bud";
_KieranVest = "39th_Platecarrier_kieran";
////////////////weapon variables///////////////

_pmag = "16Rnd_9x21_Mag";
_rmag = "hlc_30Rnd_556x45_t_AUG";
_armag = "hlc_200rnd_556x45_M_SAW";
_frag = "HandGrenade";
_gsmoke = "SmokeShellGreen";
_wsmoke = "SmokeShell";
_he40 = "1Rnd_HE_Grenade_shell";


////////////////////scripting////////////////////


switch(_uid)do {;


  case "76561198062581536": {;//mrninja


  removevest _soldier;
  _soldier addVest _MrNinjaVest;
  hint "Welcome MrNinja";


  };


  case "76561198045470871": {;//anfo


  removevest _soldier;
  _soldier addVest _AnfoVest;
  hint "Welcome Anfo";


  };
  case "76561198026165009": {;//leroy


  removevest _soldier;
  _soldier addVest _LeroyVest;
  hint "Welcome Leroy";


  };
  case "76561197998658898": {;//seagull


  removevest _soldier;
  _soldier addVest _SeagullVest;
  hint "Welcome Seagull";


  };


    case "76561198058556675": {;//roo


  removevest _soldier;
  _soldier addVest _RooVest;
  hint "Welcome Roo";


  };
    case "76561198037779146": {;//royce


  removevest _soldier;
  _soldier addVest _RoyceVest;
  hint "Welcome Royce";


  };


    case "76561197994707681": {;//bud


  removevest _soldier;
  _soldier addVest _BudVest;
  hint "Welcome Bud";


  };


    case "76561197977997617": {;//kieran


  removevest _soldier;
  _soldier addVest _KieranVest;
  hint "Welcome Kieran";




  };
  case "_SP_PLAYER_": {;


  removevest _soldier;
  _soldier addVest _Defaultvest;






  };


  default {;
      removevest _soldier;
    _soldier addvest _Defaultvest;




  };
};





switch(_place)do {;


  case "39th_Multicam_Squadleader": {;


  _soldier additemtovest _pmag;
  _soldier additemtovest _frag;
  _soldier additemtovest _frag;
  _soldier additemtovest _gsmoke;








  };
case "39th_Multicam_FireteamLeader": {;


  _soldier additemtovest _pmag;
  _soldier additemtovest _frag;
  _soldier additemtovest _frag;
  _soldier additemtovest _gsmoke;
  _soldier additemtovest _wsmoke;




  };
  case "39th_Multicam_Grenadier": {;


  _soldier additemtovest _pmag;
  _soldier additemtovest _frag;
  _soldier additemtovest _frag;
  _soldier additemtovest _wsmoke;
  _soldier additemtovest _wsmoke;
  _soldier additemtovest _he40;
  _soldier additemtovest _he40;
  _soldier additemtovest _he40;
  _soldier additemtovest _he40;
  _soldier additemtovest _he40;






  };
case "39th_Multicam_Marksman": {;


  _soldier additemtovest _pmag;
  _soldier additemtovest _frag;
  _soldier additemtovest _frag;
  _soldier additemtovest _wsmoke;
  _soldier additemtovest _wsmoke;




};
case "39th_Multicam_Medic": {;
_soldier additemtovest _pmag;
_soldier additemtovest _frag;
  _soldier additemtovest _frag;
  _soldier additemtovest _wsmoke;
  _soldier additemtovest _wsmoke;
  _soldier additemtovest _wsmoke;
  _soldier additemtovest _wsmoke;
  _soldier additemtovest _wsmoke;




  };
case "39th_Multicam_RiflemanAT":{;
  _soldier additemtovest _pmag;
  _soldier additemtovest _frag;
  _soldier additemtovest _frag;
  _soldier additemtovest _wsmoke;
  _soldier additemtovest _wsmoke;






  };
case "39th_Multicam_AssistantAutorifleman": {;


  _soldier additemtovest _armag;
  _soldier additemtovest _armag;
  _soldier additemtovest _wsmoke;






  };
case "39th_Multicam_Autorifleman": {;


  _soldier additemtovest _armag;
  _soldier additemtovest _armag;




  };
  default {;


     _soldier additemtovest _pmag;
  _soldier additemtovest _frag;
  _soldier additemtovest _frag;
  _soldier additemtovest _gsmoke;


  };
 };

 

Share this post


Link to post
Share on other sites

Have you tried putting that script into the initPlayerLocal.sqf? Should be much easier and trouble free.

Share this post


Link to post
Share on other sites

i had thought about that however im hoping to activate it within the mod itself im currently using an event handler within the config of the mod to automatically attach the script to the unit is there a way to do that from within the config like you can with the init line?

Share this post


Link to post
Share on other sites

So, if I understand you correctly, you want this script to automatically run only once as soon as the mission is started.

 

In that case, you can simply start the script as soon as the addon is loaded and make a wait loop which loops until the player is initialized, so it waits until a mission is started.

 

In the addons config.cpp, put this:

class CfgFunctions {
    class YourAddon {
        class SomeSubClass {
            file = "\addon_pbo_name";
            
            class init {    //fn_init.sqf
                postInit = 1;    //run script when addon is loaded
            };
        };
    };
};

In the fn_init.sqf, put this:

while {true} do {
	if (isNull player) {
		waitUntil {!isNull player};
		[] call fnc_yourScript;
	};
	sleep 10;
};

Probably not the best solution, but assumingly A solution (untested though).

Share this post


Link to post
Share on other sites

The extent of my knowledge lays with what Johnny put above, but to specifically put it in the "init" line, I believe there is an attribute within the Man class (or one of its daughters) that you could override with a function or string of functions on unit spawn/init.

Share this post


Link to post
Share on other sites

Selective execute from initPlayerLocal.sqf

if ((typeOf player) == "rhsusf_army_ucp_squadleader") then  {

..code

    };

Share this post


Link to post
Share on other sites

The extent of my knowledge lays with what Johnny put above, but to specifically put it in the "init" line, I believe there is an attribute within the Man class (or one of its daughters) that you could override with a function or string of functions on unit spawn/init.

 

I guess you're refering to the init parameter for createUnit:

type createUnit [position, group, init, skill, rank]

 

BUT I personally discourage from using createUnit that way and encourage to use it as in the BIKI page for createUnit array, which has no init parameter, but has the same syntax as createVehicle (I wonder why they didn't call it "createObject"...).

Share this post


Link to post
Share on other sites

I guess you're refering to the init parameter for createUnit:

type createUnit [position, group, init, skill, rank]

 

BUT I personally discourage from using createUnit that way and encourage to use it as in the BIKI page for createUnit array, which has no init parameter, but has the same syntax as createVehicle (I wonder why they didn't call it "createObject"...).

No I'm talking config, where you actually override the unit init attribute of the Man (or subclass there of), but I may just be thinking of something else, not too sure...

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

×