Advertisement
Morbo513

Untitled

Jul 5th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. /*
  2. * Author: PabstMirror
  3. * Applies a loadout to a unit (cached)
  4. *
  5. * Arguments:
  6. * 0: Unit <OBJECT>
  7. *
  8. * Return Value:
  9. * Nothing
  10. *
  11. * Example:
  12. * [player] call potato_assignGear_fnc_assignGearMan;
  13. *
  14. * Public: Yes
  15. */
  16.  
  17. #include "script_component.hpp"
  18.  
  19. TRACE_1("params",_this);
  20.  
  21. params ["_unit"];
  22. TRACE_2("",_unit, local _unit);
  23.  
  24. BEGIN_COUNTER(assignGearMan);
  25.  
  26. private _faction = toLower faction _unit;
  27. private _unitClassname = [typeOf _unit] call FUNC(cleanPrefix);
  28. private _loadout = _unit getVariable ["F_Gear", _unitClassname]; //Check variable f_gear, otherwise default to typeof
  29. private _path = missionConfigFile >> "CfgLoadouts" >> _faction >> _loadout;
  30. private _face = "";
  31. private _speaker = "";
  32.  
  33. if ((!isClass(_path)) && GVAR(useFallback)) then {
  34. _path = missionConfigFile >> "CfgLoadouts" >> _faction >> "fallback";
  35. };
  36.  
  37. if (!isClass(_path)) exitWith {
  38. TRACE_2("No Class Found",_unit,typeOf _unit);
  39. _unit setVariable [QGVAR(gearSetup), true, true];
  40. };
  41.  
  42. private _randomIndex = floor (random GVAR(maxRandomization));
  43. private _loadoutKey = format ["%1:%2", _path, _randomIndex];
  44.  
  45. private _loadoutArray = GVAR(loadoutCache) getVariable _loadoutKey;
  46.  
  47. if (isNil "_loadoutArray") then {
  48. TRACE_1("compiling new",_loadoutKey);
  49. BEGIN_COUNTER(getLoadoutFromConfig);
  50. _loadoutArray = [_path] call FUNC(getLoadoutFromConfig);
  51. _speaker = _loadoutArray deleteAt 11;
  52. _face = _loadoutArray deleteAt 10;
  53. END_COUNTER(getLoadoutFromConfig);
  54. TRACE_1("loadout array: ", _loadoutArray);
  55. GVAR(loadoutCache) setVariable [_loadoutKey, _loadoutArray];
  56. };
  57.  
  58. // Allow player profile face to override
  59. _loadoutArray set [LA_FACE_INDEX, face _unit];
  60. _unit setUnitLoadout _loadoutArray;
  61. [_unit, _face] remoteExec ["setFace", 0, true];
  62. [_unit, _speaker] remoteExec ["setSpeaker", 0, true];
  63.  
  64. if (isText (_path >> "init")) then {
  65. TRACE_1("calling init code", getText (_path >> "init"));
  66. _unit call compile ("this = _this;"+ getText (_path >> "init"));
  67. };
  68.  
  69. _unit setVariable [QGVAR(gearSetup), true, true];
  70.  
  71. END_COUNTER(assignGearMan);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement