Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Sign in to follow this  
Wait4Code

Multiplyer addAction button

Recommended Posts

Hi,
Sorry beforehand for my bad english : it is not my mother tongue.

I want to create en addAction button to load gear depending upon the player class.
below, what i already made :
Initfield for addAction :

this addAction ["Take Stuff","scripts\Stuff\initClasse.sqf",player];

File initClasse.sqf :

private ["_ply","_class"];
_ply = _this select 3;
_class = typeOf _ply;

switch (_class) do {
	case "B_soldier_exp_F":{null = [_ply] execVM "scripts\Stuff\Demo.sqf";};
	case "B_soldier_LAT_F":{null = [_ply] execVM "scripts\Stuff\AT4.sqf";};
	case "B_medic_F":{null = [_ply] execVM "scripts\Stuff\Medic.sqf";};
	case "B_soldier_AR_F":{null = [_ply] execVM "scripts\Stuff\Gunner.sqf";};
	case "B_soldier_AT_F":{null = [_ply] execVM "scripts\Stuff\ERYX.sqf";};
	default {hint "No Stuff for your class."};
};

When I try this on the preview, it works but when I setup it on the server, it always display the "No Stuff for your class." string.

 

Thanks for your help.

Share this post


Link to post
Share on other sites
I have heavily commented the code to help you understand what is going on and have added debug lines which will help you track any issues.
Take note how I am using systemchat not hint.
This allows you to enter the chat mode and scroll up to see earlier messages.
I also added diag_log to the debug, so that it also dumps these debug lines to your rpt file.
Debugging is something you need to master to help you track why a script isn't working, you can find more information on debugging
 
 
Playable unit's Init field in Mission editor

this addAction ["Take Stuff","scripts\Stuff\initClasse.sqf"];
 
InitClasse.sqf
 
 
//_this select 0 - Object the addaction is attached to
//_this select 1 - Object that run the addaction
//If this is a dedicated server or headless client, exit the script
  if!(HasInterface)exitwith{};
 
// If the player activating the addaction is not the unit the addaction is attached to, exit the script)
  if!((_this select 0)==Player)exitwith
  {
     [_this select 0]spawn 
     {
          systemchat format  ["<<<DEBUG >>> Object %1 is running the action on %2, these are not the same objects",_this select 1, _this select 0];
          diag_log format    ["<<<DEBUG >>> Object %1 is running the action on %2, these are not the same objects",_this select 1, _this select 0];
     }; 
  };
 
 
// When comparing strings, (which are always case sensitive), always ToUpper the string to avoid case sensitivity compairosn issues
  _script = switch (ToUpper (typeof (_this select 0))) do 
  {
     case "B_SOLDIER_EXP_F": {"scripts\Stuff\Demo.sqf"   };
     case "B_SOLDIER_LAT_F": {"scripts\Stuff\AT4.sqf"    };
     case "B_MEDIC_F":       {"scripts\Stuff\Medic.sqf"  };
     case "B_SOLDIER_AR_F":  {"scripts\Stuff\Gunner.sqf" };
     case "B_SOLDIER_AT_F":  {"scripts\Stuff\ERYX.sqf"   };
     default  {"" };
  };
 
    if(_script=="")exitwith
    {
          [_this select 0]spawn 
          {
               systemchat format  ["<<<DEBUG >>> Passed object %1 is class  %2 and does not have a loadout defined",_this select 0, typeof (_this select 0)];
               diag_log format    ["<<<DEBUG >>> Passed object %1 is class  %2 and does not have a loadout defined",_this select 0, typeof (_this select 0)];
          };
    };
 
  [_this select 0] execVM _script;
 

Share this post


Link to post
Share on other sites

Ok it works ! I modified your code a little bit (the addaction is not attached to a player but to a sign) and it works.

Thank you !

Share this post


Link to post
Share on other sites
Sign in to follow this  

×