ovibag 10 Posted August 26, 2015 I'm trying to create a module that checks all units class names and alters their loadout if their class name is correct. I'm getting an error when loading into the game with the module placed. Any help is really appreciated! The error is [bIS_fnc_moduleExecute] Cannot execute module, error found in 'trgu_fnc_gear' Here is the config for the module class CfgPatches{ class TRGU_Modules { units[] = {"TRGU_ModuleGear"}; requiredVersion = 1.0; requiredAddons[] = {"A3_Modules_F"}; }; }; class CfgFactionClasses { class NO_CATEGORY; class TRGU_Modules_Cat: NO_CATEGORY { displayName = "TRGU Modules"; icon = "\TRGU_Modules\TRGU_LOGO.paa"; }; }; class CfgVehicles { class Logic; class Module_F: Logic { class ArgumentsBaseUnits { class Units; }; class ModuleDescription { class AnyBrain; }; }; class TRGU_ModuleGear: Module_F { scope = 2; displayName = "Section Gear"; icon = "\TRGU_Modules\TRGU_LOGO.paa"; category = "TRGU_Modules_Cat"; author = "TRGU"; function = "trgu_fnc_Gear"; functionPriority = 1; isGlobal = 1; isTriggerActivated = 0; isDisposable = 0; curatorInfoType = "RscDisplayAttributeModuleTRGU"; class Arguments: ArgumentsBaseUnits { class Units: Units {}; }; class ModuleDescription: ModuleDescription { description = "Place down the module and all TRGU units will have their loadouts set to their role."; sync[] = {}; }; }; }; class CfgFunctions { class TRGU_Modules { class TRGU_Modules_Cat { class TRGU_fnc_gear {file = "TRGU_Modules\functions\fnc_gear.sqf"}; }; }; }; This is the fnc_gear.sqf _activate = [_this,3,true,[true]] call bis_fnc_param; _units = [_this,1,[],[[]]] call BIS_fnc_param; if (_activated) then { { if (typeof _x == "TRGU_Rfn") then { removeAllWeapons _x; removeAllItems _x; removeAllAssignedItems _x; removeUniform _x; removeVest _x; removeBackpack _x; removeHeadgear _x; removeGoggles _x; _x forceAddUniform "STKR_UBACS_ROLL"; for "_i" from 1 to 4 do {_x addItemToUniform "ACE_fielddressing";}; for "_i" from 1 to 2 do {_x addItemToUniform "ACE_elasticbandage";}; for "_i" from 1 to 1 do {_x addItemToUniform "ACE_tourniquet";}; for "_i" from 1 to 4 do {_x addItemToUniform "ACE_quikclot";}; for "_i" from 1 to 1 do {_x addItemToUniform "ACE_morphine";}; for "_i" from 1 to 4 do {_x addItemToUniform "ACE_packingBandage";}; for "_i" from 1 to 1 do {_x addItemToUniform "ACE_epinephrine";}; _x addVest "UK3CB_BAF_V_Osprey_SL_D"; for "_i" from 1 to 7 do {_x addItemToVest "UK3CB_BAF_30Rnd";}; for "_i" from 1 to 2 do {_x addItemToVest "UK3CB_BAF_30Rnd_T";}; for "_i" from 1 to 2 do {_x addItemToVest "UK3CB_BAF_17Rnd_9mm";}; for "_i" from 1 to 2 do {_x addItemToVest "HandGrenade";}; for "_i" from 1 to 6 do {_x addItemToVest "SmokeShell";}; for "_i" from 1 to 2 do {_x addItemToVest "SmokeShellYellow";}; _x addItemToVest "R3F_25Rnd_556x45_TRACER_FAMAS"; _x addItemToVest "HandGrenade"; _x addItemToVest "SmokeShell"; _x addBackpack ["UK3CB_BAF_B_Bergen_MTP_Rifleman_H_A","UK3CB_BAF_B_Bergen_MTP_Rifleman_H_B","UK3CB_BAF_B_Bergen_MTP_Rifleman_H_C"] call BIS_fnc_selectRandom; _x addHeadgear ["UK3CB_BAF_H_Mk7_Camo_D","UK3CB_BAF_H_Mk7_Net_D","UK3CB_BAF_H_Mk7_Net_CESS_D","UK3CB_BAF_H_Mk7_Scrim_D"] call BIS_fnc_selectRandom; _x addWeapon "UK3CB_BAF_L85A2_RIS"; _x addPrimaryWeaponItem "UK3CB_BAF_LLM_IR_Black"; _x addPrimaryWeaponItem "RKSL_optic_LDS"; _x addPrimaryWeaponItem "UK3CB_BAF_SFFH"; _x linkItem "ItemMap"; _x linkItem "ItemCompass"; _x linkItem "tf_microdagr"; _x linkItem "tf_rf7800str"; _x linkItem "ItemGPS"; _x linkItem "UK3CB_BAF_HMNVS"; }; } foreach allunits; }; true Any help is appreciated! Share this post Link to post Share on other sites
R3vo 2654 Posted August 26, 2015 Haven't found any mistake, did you try to run fnc_gear.sqf via the debug console? Did it show any errors? In addition I would suggest you to replace _activate = [_this,3,true,[true]] call bis_fnc_param; _units = [_this,1,[],[[]]] call BIS_fnc_param; with the param or params command, it's faster. https://community.bistudio.com/wiki/param Share this post Link to post Share on other sites
ovibag 10 Posted August 27, 2015 Haven't found any mistake, did you try to run fnc_gear.sqf via the debug console? Did it show any errors? In addition I would suggest you to replace _activate = [_this,3,true,[true]] call bis_fnc_param; _units = [_this,1,[],[[]]] call BIS_fnc_param; with the param or params command, it's faster. https://community.bistudio.com/wiki/param How would I go about doing that? This is the first module I've attempted to make so a bit out of my depth I think Share this post Link to post Share on other sites
benargee 20 Posted August 28, 2015 How would I go about doing that? This is the first module I've attempted to make so a bit out of my depth I think This should do: _activate = _this param [3, true, [true]]; _units = _this param [1, [], [[]]]; https://community.bistudio.com/wiki/BIS_fnc_param [input,index,(defaultValue,dataTypes,requiredCount)] call BIS_fnc_param; https://community.bistudio.com/wiki/param argument param [index, defaultValue, expectedDataTypes, expectedArrayCount]; Share this post Link to post Share on other sites
Larrow 2817 Posted August 28, 2015 Is believe this is incorrect class CfgFunctions { class TRGU_Modules { class TRGU_Modules_Cat { class TRGU_fnc_gear {file = "TRGU_Modules\functions\fnc_gear.sqf"}; }; }; }; and would create a function called TRGU_Modules_fnc_TRGU_fnc_gear. Open up the debugConsole and in one of the watch lines type TRGU_fnc_gear. If nothing appears in the line below type TRGU_Modules_fnc_TRGU_fnc_gear and see if there is code returned. I should be something like.. //TAG_fnc_FUNCTION class CfgFunctions { class TRGU //TAG { class TRGU_Modules //CATEGORY { class gear //FUNCTION { file = "TRGU_Modules\functions\fnc_gear.sqf" }; }; }; }; 1 Share this post Link to post Share on other sites
ovibag 10 Posted August 29, 2015 Is believe this is incorrect class CfgFunctions { class TRGU_Modules { class TRGU_Modules_Cat { class TRGU_fnc_gear {file = "TRGU_Modules\functions\fnc_gear.sqf"}; }; }; }; and would create a function called TRGU_Modules_fnc_TRGU_fnc_gear. Open up the debugConsole and in one of the watch lines type TRGU_fnc_gear. If nothing appears in the line below type TRGU_Modules_fnc_TRGU_fnc_gear and see if there is code returned. I should be something like.. //TAG_fnc_FUNCTION class CfgFunctions { class TRGU //TAG { class TRGU_Modules //CATEGORY { class gear //FUNCTION { file = "TRGU_Modules\functions\fnc_gear.sqf" }; }; }; }; This worked great and there isn't an error when loading in anymore!! But the unit still doesnt have his loadout changed at all Share this post Link to post Share on other sites
jshock 512 Posted August 29, 2015 I would add the postInit attribute to the function, to ensure all objects have been created before running the module function. Share this post Link to post Share on other sites
Larrow 2817 Posted August 29, 2015 I would add the postInit attribute to the function, to ensure all objects have been created before running the module function. This would just make the function run postInit, making the whole point of having it as a drop in module void. Although a valid way to accomplish the same effect. _activate vs if ( _activated As your module has no changeable attribute and does not care what it is synced to as its just doing all units with predefined gear, there is no need to care about the parameters passed, just start with your foreach loop. Its basically just a gameLogic with some code (just wrapped up in module clothing :D ). You may need to put a local check in there along with the unit type else you have a module that isGlobal and is doing allUnits (every client at mission start doing a mixture of commands some local some global to all units) Share this post Link to post Share on other sites
ovibag 10 Posted August 29, 2015 Thanks for the help! Its basically working exactly how I need it too! Currently just working through adding all the roles that need changing >.> Is there a way to make it so it only changes their gear if the module is placed? Because its currently just working with or without the module being placed. Also is there a way to have random predefined helmets/backpacks across different unit classnames? And finally have the gear be reapplied on respawn? Share this post Link to post Share on other sites
ovibag 10 Posted August 31, 2015 Still needing help with this, pulling my hair out Share this post Link to post Share on other sites
Larrow 2817 Posted September 1, 2015 Is there a way to make it so it only changes their gear if the module is placed? Because its currently just working with or without the module being placed. Have you changed the CfgFunction definition to include a pre or post init? Can you show us what you now have. Also is there a way to have random predefined helmets/backpacks across different unit classnames? Bit of an oxymoron that but i presume you mean a different array of helmets/backpacks for certain classes to choose a random one from? And finally have the gear be reapplied on respawn? Should just be a case of adding a repawn eventHandler to the end of your code that re-runs the script. Something like.. //On initial module call 'this select 3' will be undefined so allUnits will be choosen //When called by Respawn EH respawning unit will be passed _respawn = false; //If a unit was passed if ( [ _this select 3 ] params[ [ "_units", allUnits, [ [] ] ] ] ) then { _respawn = true; }; { if ( local _x ) then { if (typeOf _x == "B_Soldier_F") then { removeAllWeapons _x; removeAllItems _x; //rest of loadout code }; //Only add EH if not respawning if !( _respawn ) then { _x addEventHandler [ "Respawn", { [ nil, nil, nil, [ _this select 0 ] ] call trgu_fnc_Gear; }]; }; }; } forEach _units; true testpbo 1 Share this post Link to post Share on other sites
ovibag 10 Posted September 1, 2015 Have you changed the CfgFunction definition to include a pre or post init? Can you show us what you now have. I changed lots of stuff just trying to fix the damn thing by myself, reverted back to the one you included in the example pbo (Thank you). Bit of an oxymoron that but i presume you mean a different array of helmets/backpacks for certain classes to choose a random one from? Yeah exactly what I meant! Sorry for explaining it terribly. Should just be a case of adding a repawn eventHandler to the end of your code that re-runs the script. Something like.. This worked perfectly! I tried using an eventHandler before, but I just couldn't get it to work how I wanted it to. Thanks for clearing the issue up! Share this post Link to post Share on other sites
Larrow 2817 Posted September 1, 2015 Well you could put your backpack/helmet arrays within each IF statement but if you wanted several classes that maybe share the same backpack/helmet arrays you could add some type of class array to the top of your script. Something like... //On initial module call 'this select 3' will be undefined so allUnits will be choosen //When called by Respawn EH respawning unit will be passed _respawn = false; //If a unit was passed if ( [ _this select 3 ] params[ [ "_units", allUnits, [ [] ] ] ] ) then { _respawn = true; }; _classDef = [ [ [ "B_Soldier_F", "B_Soldier_AR_F" ], //Classes [ "B_Bergen_blk", "B_Bergen_rgr", "B_AssaultPack_blk", "B_Carryall_khk" ], //Backpacks [ "H_HelmetB_camo", "H_HelmetB_grass", "H_HelmetB_light", "H_HelmetB_light_sand" ] //Helmets ], [ [ "B_Officer_F" ], //Classes [ "B_AssaultPack_khk", "B_AssaultPack_rgr" ], //Backpacks [ "H_HelmetB_camo", "H_HelmetB_grass" ] //Helmets ], [ [ "B_Pilot_F" ], //Classes [ "B_O_Parachute_02_F" ], //Backpacks [ "H_PilotHelmetFighter_B", "H_PilotHelmetHeli_B" ] //Helmets ] ]; _fnc_getClassArrays = { _class = typeOf _this; { if ( _class in ( _x select 0 ) ) exitWith { _this addBackpackGlobal ( ( _x select 1 ) call BIS_fnc_selectRandom ); _this addHeadgear ( ( _x select 2 ) call BIS_fnc_selectRandom ); }; }forEach _classDef; }; { if ( local _x ) then { switch ( typeOf _x ) do { case ("B_Soldier_F") : { _x call _fnc_getClassArrays; //rest of loadout code }; case ("B_Soldier_AR_F") : { _x call _fnc_getClassArrays; //rest of loadout code }; case ("B_Officer_F") : { _x call _fnc_getClassArrays; //rest of loadout code }; case ("B_Pilot_F") : { _x call _fnc_getClassArrays; //rest of loadout code }; }; //Only add EH if not respawning if !( _respawn ) then { _x addEventHandler [ "Respawn", { [ nil, nil, nil, [ _this select 0 ] ] call trgu_fnc_Gear; }]; }; }; } forEach _units; trueI suppose it kind of keeps it tidy with all the arrays in one place and easy to edit and share across different classes. Is this the sort of thing you meant? Share this post Link to post Share on other sites
ovibag 10 Posted September 1, 2015 I suppose it kind of keeps it tidy with all the arrays in one place and easy to edit and share across different classes. Is this the sort of thing you meant? This is spot on what I meant! Absolutely perfect. Thank you very much for all the help! I think thats about everything now haha Share this post Link to post Share on other sites
ovibag 10 Posted September 2, 2015 Actually having issues getting this to work properly, doesn't seem to be randomizing the gear at all. Here is the relative code. _classDef = [ [ [ "TRGU_Zero", "B_Soldier_AR_F" ], //Classes [ "UK3CB_BAF_B_Bergen_MTP_Radio_H_A", "UK3CB_BAF_B_Bergen_MTP_Radio_H_B" ], //Backpacks [ "UK3CB_BAF_H_Mk7_Camo_A", "UK3CB_BAF_H_Mk7_Camo_B", "UK3CB_BAF_H_Mk7_Camo_C", "UK3CB_BAF_H_Mk7_Camo_D", "UK3CB_BAF_H_Mk7_Camo_E", "UK3CB_BAF_H_Mk7_Camo_F", "UK3CB_BAF_H_Mk7_Net_ESS_A", "UK3CB_BAF_H_Mk7_Camo_ESS_B", "UK3CB_BAF_H_Mk7_Camo_ESS_C", "UK3CB_BAF_H_Mk7_Scrim_A" ], //Helmets [ "UK3CB_BAF_U_CombatUniform_MTP_ShortSleeve", "UK3CB_BAF_U_CombatUniform_MTP" ] //Uniform ], [ [ "B_Officer_F" ], //Classes [ "B_AssaultPack_khk", "B_AssaultPack_rgr" ], //Backpacks [ "H_HelmetB_camo", "H_HelmetB_grass" ] //Helmets ], [ [ "B_Pilot_F" ], //Classes [ "B_O_Parachute_02_F" ], //Backpacks [ "H_PilotHelmetFighter_B", "H_PilotHelmetHeli_B" ] //Helmets ] ]; _fnc_getClassArrays = { _class = typeOf _this; { if ( _class in ( _x select 1 ) ) exitWith { removeuniform _this; removeHeadgear _this; removebackpack _this; _this addBackpackGlobal ( ( _x select 2 ) call BIS_fnc_selectRandom ); _this addHeadgear ( ( _x select 3 ) call BIS_fnc_selectRandom ); _this AddUniform ( ( _x select 4 ) call BIS_fnc_selectRandom ); }; }forEach _classDef; }; { if ( local _x ) then { switch ( typeOf _x ) do { case ("TRGU_Zero") : { _x call _fnc_getClassArrays; removeAllWeapons _x; removeAllItems _x; removeAllAssignedItems _x; removeVest _x; removeGoggles _x; for "_i" from 1 to 4 do {_x addItemToUniform "ACE_fieldDressing";}; for "_i" from 1 to 4 do {_x addItemToUniform "ACE_packingBandage";}; for "_i" from 1 to 2 do {_x addItemToUniform "ACE_quikclot";}; for "_i" from 1 to 2 do {_x addItemToUniform "ACE_elasticBandage";}; _x addItemToUniform "ACE_tourniquet"; _x addItemToUniform "ACE_morphine"; _x addItemToUniform "ACE_epinephrine"; _x addVest "UK3CB_BAF_V_Osprey_SL_D"; for "_i" from 1 to 6 do {_x addItemToVest "UK3CB_BAF_30Rnd";}; for "_i" from 1 to 2 do {_x addItemToVest "UK3CB_BAF_30Rnd_T";}; for "_i" from 1 to 2 do {_x addItemToVest "UK3CB_BAF_17Rnd_9mm";}; _x addItemToBackpack "ACE_microDAGR"; _x addItemToBackpack "ACE_IR_Strobe_Item"; _x addItemToBackpack "ACE_MapTools"; for "_i" from 1 to 4 do {_x addItemToBackpack "SmokeShellBlue";}; for "_i" from 1 to 2 do {_x addItemToBackpack "SmokeShellRed";}; _x addItemToBackpack "UK3CB_BAF_100Rnd"; _x addItemToBackpack "optic_Nightstalker"; _x addItemToBackpack "optic_NVS"; _x addItemToBackpack "UK3CB_BAF_G_Tactical_Clear"; _x addItemToBackpack "UK3CB_BAF_HMNVS"; _x addWeapon "UK3CB_BAF_L85A2_RIS"; _x addPrimaryWeaponItem "UK3CB_BAF_SFFH"; _x addPrimaryWeaponItem "UK3CB_BAF_LLM_IR_Black"; _x addPrimaryWeaponItem "RKSL_optic_LDS"; _x addWeapon "UK3CB_BAF_L131A1"; _x addWeapon "ACE_Vector"; _x linkItem "ItemMap"; _x linkItem "ItemCompass"; _x linkItem "tf_microdagr"; _x linkItem "tf_anprc152_2"; _x linkItem "ItemGPS"; }; Share this post Link to post Share on other sites
Larrow 2817 Posted September 2, 2015 Sorry my bad, I didnt test the code i just wrote it as an example. In _fnc_getClassArrays it should be _x select 0 1,2 etc not 1,2,3. Corrected previous post. Share this post Link to post Share on other sites
ovibag 10 Posted September 10, 2015 Working great, mostly! Only issue is the module doesn't work for JIP players! Share this post Link to post Share on other sites
Larrow 2817 Posted September 11, 2015 Should just be a matter of turning isGlobal in the module config to 2. Share this post Link to post Share on other sites
ovibag 10 Posted September 11, 2015 Awesome! I thought it would have to be an additional eventhandler, or changing when the function executes. Thanks again Larrow! Share this post Link to post Share on other sites
ovibag 10 Posted September 11, 2015 Still doesn't seem to be working with JIP players, I've changed the isGlobal to 2 like you said. class TRGU_ModuleGear: Module_F { scope=2; displayName="Section Gear"; category="TRGU_Modules_Cat"; icon = "\TRGU_Modules\TRGU_LOGO.paa"; author="TRGU"; function="trgu_fnc_Gear"; functionPriority=1; isGlobal=2; isTriggerActivated=0; isDisposable=0; class ModuleDescription: ModuleDescription { description="Place down the module and all TRGU units will have their loadouts set to their role."; sync[]={}; }; }; Share this post Link to post Share on other sites