jordanbache97 47 Posted July 20, 2015 Hi Guys I am using the virtual Arsenal to make units loadouts for the community im in and for not playing arma in a while my mind has gone blank for switching the commands to global so they would work in multiplayer withoutout duplicating. Would I need to switch every command of "this" and put P1,p2 ect...?? or is there just a line I could put at the top of each init? Thanks Jordan ( it was so much easier in ArmA 2 ) Share this post Link to post Share on other sites
R3vo 2654 Posted July 20, 2015 Where are you executing them now ? I always used seperated scripts for each loadout. In the init of the unit I put the following: _nil = [this] execVM "scripts\scriptsName.sqf"; In the script itself you put: _unit = _this select 0; When a player joins in progress, only the loadout of that player will be changed. If you don't want multiple script files for loadouts, you could also create functions and precompile those on mission initialisation. Share this post Link to post Share on other sites
Kingsley1997 39 Posted July 20, 2015 For multiplayer scripting it's best practice to use the init.sqf as appose to placing code inside each units init box. Something like this in your init would create a virtual arsenal on a unit named "arsenalBox"; if (isServer || isDedicated) then { ["AmmoboxInit", [arsenalBox, true]] call BIS_fnc_arsenal; }; Now that my brain has caught up I understand your problem and yes, R3vo suggestion is probably best Share this post Link to post Share on other sites
R3vo 2654 Posted July 20, 2015 I would also like to see other solutions, since I actually dislike to put code into the units initialisation too. However, the way I posted above has always worked for me, so I sticked with it. Share this post Link to post Share on other sites
Kingsley1997 39 Posted July 20, 2015 So are you trying to get different units to have different loadout's that you've exported from the virtual arsenal? ---------- Post added at 19:41 ---------- Previous post was at 19:30 ---------- I would also like to see other solutions, since I actually dislike to put code into the units initialisation too. However, the way I posted above has always worked for me, so I sticked with it. This script should simplify things, but again I'm not sure what you're after. private ["_unit", "_type", "_defaultType"]; _defaultType = "rifleman"; _unit = [_this, 0, player] call BIS_fnc_param; // If no unit is given in the parameters, use player instead _type = [_this, 1, _defaultType] call BIS_fnc_param; // If no type is given in the parameters, use the default instead /* Call this script by placing the following line in the units init: null = [this, "yourType"] execVM "theScriptName.sqf"; If you want to use it in the init.sqf use the following code: if (local player) then { _null = [player, "yourType"] execVM "theScriptName.sqf"; }; */ removeAllWeapons _unit; removeAllItems _unit; removeAllAssignedItems _unit; removeUniform _unit; removeVest _unit; removeBackpack _unit; removeHeadgear _unit; removeGoggles _unit; switch (_type) do { case "sniper": { // Add your exported arsenal code here, but replace this with _unit! }; case "medic": { // Do the same here, but for the medic loadout etc. }; case "rifleman": { // Do the same here, but for the medic loadout etc. }; default { // Type used wasn't defined in the switch statement, do the default }; }; Share this post Link to post Share on other sites
jordanbache97 47 Posted July 20, 2015 Thanks I used to do the .sqf way then for some reason I couldnt get it to work, So just put _unit = _this select 0; at the top of the .sqf before removeAllWeapons this; and then I should be all fine and dandy. Share this post Link to post Share on other sites
Kingsley1997 39 Posted July 20, 2015 Thanks I used to do the .sqf way then for some reason I couldnt get it to work, So just put _unit = _this select 0; at the top of the .sqf before removeAllWeapons this; and then I should be all fine and dandy. Yes but make sure you change all the "this" in the script to _unit. "this" refers to the object it's in, so when it's used in the init box of a unit, it refers directly to that unit, but when executing a script, you have to pass it that object, and reference it in whatever you choose, could be _unit or could be _aCrazyLongPointlessVarNameWhichIsAnnoying. Share this post Link to post Share on other sites
jordanbache97 47 Posted July 20, 2015 Would I have to change each playable character to _unit1 _unit2 and so on or would I just be fine with _unit. Share this post Link to post Share on other sites
Kingsley1997 39 Posted July 20, 2015 Would I have to change each playable character to _unit1 _unit2 and so on or would I just be fine with _unit. No the _unit is a local variable that references _this select 0 which references the units object. You don't need to set each units name in the editor. Read up on some SQF to fully understand how these variables work and what _this means. Share this post Link to post Share on other sites
R3vo 2654 Posted July 21, 2015 No the _unit is a local variable that references _this select 0 which references the units object. You don't need to set each units name in the editor. Read up on some SQF to fully understand how these variables work and what _this means. You script would work just fine, but I guess it's time to abandon BIS_fnc_param and replace it with params or param command. Share this post Link to post Share on other sites
Kingsley1997 39 Posted July 21, 2015 You script would work just fine, but I guess it's time to abandon BIS_fnc_param and replace it with params or param command. Oh I didn't know they had a new one, will have to check that out thanks Share this post Link to post Share on other sites