Jump to content
Sign in to follow this  
aushilfsalien

Init Eventhandler in CfgVehicles

Recommended Posts

Hey guys! I hope someone can shed some light on the use of the "init" eventhandler I use in my addon.
 
My goal is to add a container with unique ACE3 actions (player can choose their loadout via ACE3 interaction menu), so I don't have to include the scripts in every mission (changing the loadouts can be very painfull, when you have to do that for a bunch of missions).
 
Since I want to create my addon for use on a dedicated server I'm not shure, when the init eventhandler is executed. I know, that the code is globally executed when the object is created. But what happens, when players jip? Does the eventhandler show the same behaviour as the object initialisation field in the editor?
 
Since the effects of ace_interact_menu_fnc_addActionToObject are local I'm guessing that I should make shure, that the function only fires once for each object and player locally.
 
Thanks in advance!
 
Edit: Forgot to add my scripts

Further edit: The code works in SP but won't execute properly on a dedicated server. E.g. I can spawn an armory box as Zeus but neither will the ACE actions be nor the logo will be attached. The logo will only spawn shortly after I delete the box.
 
Here is the CfgVehicles class for the container,

  class usArmoryContainer: Land_Cargo20_sand_F
  {
    displayName = "RHS US Armory";
    scope = 2;
    scopeCurator = 2;
    class EventHandlers
    {
      init = "_null = [(_this select 0)] call AH_fnc_initUsArmoryContainer";
    };
  };

and my function AH_fnc_initUsArmoryContainer
 

// Variables
private ["_usArmoryBox","_usArmoryLogo"];
_usArmoryBox = _this select 0;

// Only execute on server
if (!isServer) exitWith {};

// Let every client call armory function on _usArmoryBox
[_usArmoryBox] remoteExec ["AH_fnc_createUsArmory", -2, true];

// check if allready executed
if (!isNil{_usArmoryBox getVariable "logoAdded"}) exitWith {};

_usArmoryLogo = createVehicle ['UserTexture1m_F', position _usArmoryBox, [], 0, ''];
_usArmoryLogo setObjectTextureGlobal [0,'\rhs_armory\images\usArmory\logo.paa'];
_usArmoryLogo attachto [_usArmoryBox,[0,-1.25,0]];

_usArmoryBox setVariable ["logoAdded",true];

and the AH_fnc_createUsArmory function

/*
createUsAmory.sqf by Aushilfsalien
Adds ACE 3 based armory to the given object
*/

/*
Unit Icons Overview
iconMan = "\A3\ui_f\data\map\vehicleicons\iconMan_ca.paa";
iconManMedic = "\A3\ui_f\data\map\vehicleicons\iconManMedic_ca.paa";
iconManEngineer = "\A3\ui_f\data\map\vehicleicons\iconManEngineer_ca.paa";
iconManExplosive = "\A3\ui_f\data\map\vehicleicons\iconManExplosive_ca.paa";
iconManRecon = "\A3\ui_f\data\map\vehicleicons\iconManRecon_ca.paa";
iconManVirtual = "\A3\ui_f\data\map\vehicleicons\iconManVirtual_ca.paa";
iconManAT = "\A3\ui_f\data\map\vehicleicons\iconManAT_ca.paa";
iconManLeader = "\A3\ui_f\data\map\vehicleicons\iconManLeader_ca.paa";
iconManMG = "\A3\ui_f\data\map\vehicleicons\iconManMG_ca.paa";
iconManOfficer = "\A3\ui_f\data\map\vehicleicons\iconManOfficer_ca.paa";
*/

// Private vars
private ["_locker","_addedAction","_roleList","_roleCategories","_compString","_codeString"];

// Stop exec if allready running
_locker = _this select 0;
if (!isNil{_locker getVariable "armoryAdded"}) exitWith {};

// Role list
// select 0 = name, select 1 = path of sqf, select 3 = cfg icon, 4 = role category in ACE3 menu
_roleList = [];
_roleList = [
  ["US Squadlead","\rhs_armory\armory\us\us_sql.sqf","\A3\ui_f\data\map\vehicleicons\iconManOfficer_ca.paa","Leaders"],
  ["US Medic","\rhs_armory\armory\us\us_m.sqf","\A3\ui_f\data\map\vehicleicons\iconmanmedic_ca.paa","Medics"],
  ["US Rifleman","\rhs_armory\armory\us\us_rm.sqf","\A3\ui_f\data\map\vehicleicons\iconMan_ca.paa","Riflemen"],
  ["US Grenadier","\rhs_armory\armory\us\us_grnd.sqf","\A3\ui_f\data\map\vehicleicons\iconMan_ca.paa","Riflemen"],
  ["US Rifleman M136","\rhs_armory\armory\us\us_rmm136.sqf","\A3\ui_f\data\map\vehicleicons\iconMan_ca.paa","Riflemen"],
  ["US Des. Marksman","\rhs_armory\armory\us\us_dmm.sqf","\A3\ui_f\data\map\vehicleicons\iconMan_ca.paa","Riflemen"],
  ["US AR Man M249","\rhs_armory\armory\us\us_arm.sqf","\A3\ui_f\data\map\vehicleicons\iconManMG_ca.paa","Riflemen"],
  ["US Ass. AR Man","\rhs_armory\armory\us\us_asarm.sqf","\A3\ui_f\data\map\vehicleicons\iconManMG_ca.paa","Riflemen"],
  ["US Demo Specialist","\rhs_armory\armory\us\us_dsp.sqf","\A3\ui_f\data\map\vehicleicons\iconManExplosive_ca.paa","Specialists"],
  ["US Repair Specialist","\rhs_armory\armory\us\us_rsp.sqf","\A3\ui_f\data\map\vehicleicons\iconManEngineer_ca.paa","Specialists"],
  ["US Sniper","\rhs_armory\armory\us\us_snpr.sqf","\A3\ui_f\data\map\vehicleicons\iconManRecon_ca.paa","Snipers"],
  ["US Spotter","\rhs_armory\armory\us\us_sptr.sqf","\A3\ui_f\data\map\vehicleicons\iconManRecon_ca.paa","Snipers"],
  ["US UAV Operator","\rhs_armory\armory\us\us_uavop.sqf","\A3\ui_f\data\map\vehicleicons\iconManRecon_ca.paa","Recon"],
  ["US UAV Operator Raven","\rhs_armory\armory\us\us_uavop_raven.sqf","\A3\ui_f\data\map\vehicleicons\iconManRecon_ca.paa","Recon"],
  ["US AT Man SMAW","\rhs_armory\armory\us\us_rmsmaw.sqf","\A3\ui_f\data\map\vehicleicons\iconManAT_ca.paa","AA and AT"],
  ["US Ass. AT Man SMAW","\rhs_armory\armory\us\us_rmsmawass.sqf","\A3\ui_f\data\map\vehicleicons\iconManAT_ca.paa","AA and AT"],
  ["US AT Man Javelin","\rhs_armory\armory\us\us_atm.sqf","\A3\ui_f\data\map\vehicleicons\iconManAT_ca.paa","AA and AT"],
  ["US Ass. AT Man Javelin","\rhs_armory\armory\us\us_aatm.sqf","\A3\ui_f\data\map\vehicleicons\iconManAT_ca.paa","AA and AT"],
  ["US AA Man Stinger","\rhs_armory\armory\us\us_aam.sqf","\A3\ui_f\data\map\vehicleicons\iconManAT_ca.paa","AA and AT"],
  ["US Ass. AA Man Stinger","\rhs_armory\armory\us\us_asaam.sqf","\A3\ui_f\data\map\vehicleicons\iconManAT_ca.paa","AA and AT"],
  ["US Helicopter Pilot","\rhs_armory\armory\us\us_helipilot.sqf","\A3\ui_f\data\map\vehicleicons\iconMan_ca.paa", "Pilots"]
];

_roleCategories = [];
_roleCategories = [
  ["Leaders","\A3\ui_f\data\map\vehicleicons\iconManOfficer_ca.paa"],
  ["Medics","\A3\ui_f\data\map\vehicleicons\iconmanmedic_ca.paa"],
  ["Riflemen","\A3\ui_f\data\map\vehicleicons\iconMan_ca.paa"],
  ["AA and AT","\A3\ui_f\data\map\vehicleicons\iconManAT_ca.paa"],
  ["Specialists","\A3\ui_f\data\map\vehicleicons\iconManEngineer_ca.paa"],
  ["Snipers","\A3\ui_f\data\map\vehicleicons\iconManRecon_ca.paa"],
  ["Recon","\A3\ui_f\data\map\vehicleicons\iconManRecon_ca.paa"],
  ["Pilots","\A3\ui_f\data\map\vehicleicons\iconMan_ca.paa"]
];

// Add Parent Action to Main Interaction Node
_addedAction = {};
_addedAction = ['armory',"Open US armory",'\a3\weapons_f\data\ui\icon_mg_ca.paa', {true} ,{true}] call ace_interact_menu_fnc_createAction;
[_locker, 0, ["ACE_MainActions"], _addedAction] call ace_interact_menu_fnc_addActionToObject;

// Add category nodes
{
  _compString = "_addedAction = [" + str (_x select 0) + "," + str (_x select 0) + "," + str  (_x select 1) + ", {true} ,{true}] call ace_interact_menu_fnc_createAction;";
  _codeString = compile _compString;
  call _codeString;
  [_locker, 0, ["ACE_MainActions","armory"], _addedAction] call ace_interact_menu_fnc_addActionToObject;
} forEach _roleCategories;

// Add actions under category
{
  _compString = "_addedAction = [" + str (_x select 0) + "," + str (_x select 0) + "," + str  (_x select 2) + ", {_null = [player] execVM " +  str (_x select 1) + "} ,{true}] call ace_interact_menu_fnc_createAction;";
  _codeString = compile _compString;
  call _codeString;
  _compString = "[_locker, 0, ['ACE_MainActions','armory'," + str (_x select 3) + "], _addedAction] call ace_interact_menu_fnc_addActionToObject;";
  _codestring = compile _compString;
  call _codestring;
} forEach _roleList;

// mark execution of function
_locker setVariable ["armoryAdded", true];

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
Sign in to follow this  

×