Skip to content

Instantly share code, notes, and snippets.

@Fusselwurm
Last active August 29, 2015 14:09
Show Gist options
  • Save Fusselwurm/8d651b08abe8a1b92e9a to your computer and use it in GitHub Desktop.
Save Fusselwurm/8d651b08abe8a1b92e9a to your computer and use it in GitHub Desktop.
Loadouts depending on unit class
// AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
// autoloadouts.sqf
// Aufruf:
//
//[
// ["ARC_GER_Flecktarn_soldier_LAT", "ksk_g3ka4_2"],
// ["ARC_GER_Flecktarn_soldier_FOO", "bar"]
// // ....
//] execVM "autoloadouts.sqf";
//
// ruft loadouts/ksk_g3ka4_2.sqf für alle Einheiten der Klasse ARC_GER_Flecktarn_soldier_LAT auf.
// "loadouts/ksk_g3ka4_2.sqf" kann aus VAS kopiert sein, allerdings muß am Anfang this = _this select 0; gesetzt werden
private ["_loadouts"];
_loadouts = _this;
if ((!isServer) and (!isDedicated)) exitWith {};
getNewlyJoinedPlayers = {
private ["_isSet", "_result"];
_result = [];
{
_isSet = _x getVariable ["autoloadout_is_set", 0];
if (_isSet != 1) then {
_x setVariable ["autoloadout_is_set", 1];
_result = _result + [_x];
diag_log format ["adding to new players: %2 (%1)", typeOf _x, name _x];
} else {
diag_log format ["unit %2 (%1) is already known", typeOf _x, name _x];
};
} forEach allUnits;
_result;
};
tryLoadout = {
private ["_loadoutDefinition", "_unit", "_type",
"_loadOutClass", "_loadoutFileName",
"_xxx",
"_loadoutScriptPath"
];
_loadoutDefinition = _this select 0;
_unit = _this select 1;
_type = typeOf _unit;
_loadOutClass = _loadoutDefinition select 0;
_loadoutFileName = _loadoutDefinition select 1;
_loadoutScriptPath = "loadouts\" + _loadoutFileName + ".sqf";
if (_type == _loadOutClass) then {
diag_log format ["applying loadout %1 for %2 (%3) ...", _loadoutScriptPath, name _unit, _loadOutClass];
[
[
[_unit],
_loadoutScriptPath
],
"BIS_fnc_execVM",
_unit,
false,
true
] call BIS_fnc_MP;
};
};
setLoadout = {
private ["_type"];
_type = typeOf _this;
diag_log format ["searching for loadout for %2 (%1)...", _type, name _this];
{
[_x, _this] call tryLoadout;
} forEach _loadouts;
};
onPlayersConnected = {
{
_x call setLoadout;
} forEach ([] call getNewlyJoinedPlayers);
};
[
"autoloadout_handler",
"onPlayerConnected",
onPlayersConnected
] call BIS_fnc_addStackedEventHandler;
[] call onPlayersConnected;
@nomisum
Copy link

nomisum commented Nov 18, 2014

fixed here:

https://gist.github.com/nomisum/9f5a837bab7330b46dcd

... [[_unit,_loadoutPath],"BIS_fnc_execVM" ..

must be

... [[[_unit],_loadoutPath],"BIS_fnc_execVM" ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment