/
ac_functions.sqf
175 lines (164 loc) · 5.14 KB
/
ac_functions.sqf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// DayZ Epoch Helper Functions by Axe Cop
private ["_version","_skip"];
_version = 1.02;
// redefine functions only if this file is a newer version
_skip = false;
if (!isNil "AC_functions") then {
if (AC_functions >= _version) then {
diag_log format ["evaluation of ac_functions.sqf skipped, active version %1 is newer or equal than this file (version %2)", AC_functions, _version];
_skip = true;
};
};
if (_skip) exitWith {};
AC_functions = _version;
diag_log format ["AC_functions version %1", AC_functions];
// params: x:any
// return: bool
AC_fnc_isArray = {
typeName _this == "ARRAY"
};
// params: [num:number, len:number]
// return: str:string
AC_fnc_num2str = {
private ["_num","_len","_str","_numArr","_i"];
_num = _this select 0;
_len = _this select 1;
_str = str _num;
_numArr = toArray _str;
for "_i" from (count _numArr) to (_len-1) do {
_str = "0" + _str;
};
_str
};
// params: [object, [id], [classname]]
// return: object
AC_fnc_swapObject = {
private ["_obj","_objectCharacterID","_objectID","_objectUID","_classname","_location","_dir","_object"];
_obj = _this select 0;
_objectCharacterID = if (count _this >= 2) then [{_this select 1}, {_obj getVariable ["CharacterID","0"]}];
_objectID = _obj getVariable ["ObjectID","0"];
_objectUID = _obj getVariable ["ObjectUID","0"];
if (_objectID == "0" && _objectUID == "0") exitWith { nil };
_classname = if (count _this >= 3) then [{_this select 2}, {typeOf _obj}];
_location = _obj getVariable ["OEMPos",(getPosATL _obj)];
_dir = getDir _obj;
_object = createVehicle [_classname, [0,0,0], [], 0, "CAN_COLLIDE"];
_object setDir _dir;
_object setPosATL _location;
PVDZE_obj_Swap = [_objectCharacterID,_object,[_dir,_location],_classname,_obj,player];
publicVariableServer "PVDZE_obj_Swap";
player reveal _object;
_object
};
// params: tools:array
// return: bool
AC_fnc_hasTools = {
private ["_tools","_items","_hasTools","_missing"];
_tools = _this;
_items = items player; // weapons player
_hasTools = true;
{
if (!(_x in _items)) exitWith {
_hasTools = false;
_missing = getText (configFile >> "cfgWeapons" >> _x >> "displayName");
cutText [format["Missing tool %1", _missing] , "PLAIN DOWN"];
};
} forEach _tools;
_hasTools
};
// params: requirements:array
// return: bool
AC_fnc_checkRequirements = {
private ["_requirements","_inventory","_hasRequirements","_itemIn","_countIn","_qty","_missing","_missingQty","_textMissing"];
_requirements = _this;
_inventory = magazines player;
_hasRequirements = true;
{
_itemIn = "";
_countIn = 1;
if (_x call AC_fnc_isArray) then {
if (count _x >= 2) then {
_itemIn = _x select 0;
_countIn = _x select 1;
};
} else {
_itemIn = _x;
// _countIn = 1;
};
if (_itemIn != "") then {
_qty = { (_x == _itemIn) || (configName(inheritsFrom(configFile >> "cfgMagazines" >> _x)) == _itemIn) } count _inventory;
} else {
_qty = _countIn;
};
if (_qty < _countIn) exitWith {
_missing = _itemIn;
_missingQty = (_countIn - _qty);
_hasRequirements = false;
_textMissing = getText(configFile >> "CfgMagazines" >> _missing >> "displayName");
cutText [format["Missing %1 more of %2", _missingQty, _textMissing], "PLAIN DOWN"];
};
} forEach _requirements;
_hasRequirements
};
// params: requirements:array
// return: bool
AC_fnc_removeRequirements = {
private ["_requirements","_inventory","_temp_removed_array","_removed_total","_tobe_removed_total","_removed","_itemIn","_countIn","_num_removed"];
_requirements = _this;
_inventory = magazines player;
_temp_removed_array = [];
_removed_total = 0;
_tobe_removed_total = 0;
{
_removed = 0;
_itemIn = "";
_countIn = 1;
if (_x call AC_fnc_isArray) then {
if (count _x >= 2) then {
_itemIn = _x select 0;
_countIn = _x select 1;
};
} else {
_itemIn = _x;
// _countIn = 1;
};
if (_itemIn != "") then {
_tobe_removed_total = _tobe_removed_total + _countIn;
{
if ((_removed < _countIn) && ((_x == _itemIn) || configName(inheritsFrom(configFile >> "cfgMagazines" >> _x)) == _itemIn)) then {
_num_removed = ([player,_x] call BIS_fnc_invRemove);
_removed = _removed + _num_removed;
_removed_total = _removed_total + _num_removed;
if (_num_removed >= 1) then {
_temp_removed_array set [count _temp_removed_array, _x];
};
};
} forEach _inventory;
};
} forEach _requirements;
// all parts removed
if (_tobe_removed_total == _removed_total) exitWith { true };
// missing parts
{ player addMagazine _x; } forEach _temp_removed_array;
cutText [format["Missing Parts after first check Item: %1 / %2", _removed_total, _tobe_removed_total], "PLAIN DOWN"];
false
};
// params: requirements:array
// return: bool
AC_fnc_checkAndRemoveRequirements = {
private ["_requirements","_b"];
_requirements = _this;
_b = _requirements call AC_fnc_checkRequirements;
if (_b) then {
_b = _requirements call AC_fnc_removeRequirements;
};
_b
};
// params: [animation:string, range:number]
AC_fnc_doAnimationAndAlertZombies = {
private ["_animation","_range"];
_animation = _this select 0;
_range = _this select 1;
player playActionNow _animation;
[player,_range,true,(getPosATL player)] spawn player_alertZombies;
};