forked from LexTheGreat/TLX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
INVfunctions.sqf
718 lines (580 loc) · 18.1 KB
/
INVfunctions.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
// "Function-Call" Script.
// invActions.sqf
INV_Heal = {
if(_this == player) exitWith {
liafu = true;
format ["%1 switchmove ""AinvPknlMstpSlayWrflDnon_medic"";", player] call broadcast;
player groupChat format[localize "STRS_inv_items_medikit_benutzung"];
sleep 5;
player setdamage 0;
player groupChat format[localize "STRS_inv_items_medikit_fertig"];
true
};
format ["%1 switchmove ""AinvPknlMstpSlayWrflDnon_medic"";", _this] call broadcast;
player groupChat "Healing civ...";
sleep 5;
_this setdamage 0;
true
};
INV_AddInventoryItem = {
private ["_object", "_item", "_amount", "_info"];
_object = _this select 0;
_item = _this select 1;
_amount = _this select 2;
_info = _item call INV_GetItemArray;
private["_total_weight", "_own_weight", "_item_weight"];
_own_weight = (call INV_GetOwnWeight);
_item_weight = (_info call INV_GetItemTypeKg);
_total_weight = (_own_weight + (_amount * _item_weight));
if (_amount == 0) exitWith {false};
if (_total_weight > INV_CarryingCapacity) exitWith {false};
([_object, _item, _amount, ([_object] call object_storage_name)] call INV_AddItemStorage)
};
INV_CheckArray = {
private["_object", "_array_name"];
_object = _this select 0;
_array_name = _this select 1;
if (isNil "_object") exitWith {};
if (typeName _object != "OBJECT") exitWith {};
if (isNil "_array_name") exitWith {};
if (typeName _array_name != "STRING") exitWith {};
private["_array_variable"];
_array_variable = _object getVariable _array_name;
if (isNil "_array_variable") exitWith {
_object setVariable [_array_name, [], true];
};
if (typeName _array_variable != "ARRAY") exitWith {
_object setVariable [_array_name, [], true];
};
};
// Add Items to Storage
INV_AddItemStorage = {
private ["_object", "_item", "_quantity", "_arrname"];
_object = _this select 0;
_item = _this select 1;
_quantity = _this select 2;
_arrname = _this select 3;
[_object, _arrname] call INV_CheckArray;
private["_arr", "_arraynum", "_number"];
_arr = _object getVariable _arrname;
_arraynum = -1;
_number = 0;
//find the array that contains this item, and cleanup empty ones
private["_i"];
_i = 0;
while { _i < (count _arr) } do {
private["_info", "_citem", "_count"];
_info = _arr select _i;
_citem = _info select 0;
_count = [(_info select 1)] call decode_number;
if ( _citem == _item) then {
_arraynum = _i;
_number = _count;
};
_i = _i + 1;
};
_quantity = _quantity + _number;
if (_quantity < 0) exitWith {false};
_arraynum = if (_arraynum < 0) then { count _arr} else { _arraynum };
_arr set [_arraynum, [_item, ([_quantity] call encode_number)]];
_object setVariable [_arrname, _arr, true];
true
};
// Calculate How Many Items are Stored.
INV_GetStorageAmount = {
private ["_object", "_arrname", "_Itemname"];
_object = _this select 0;
_Itemname = _this select 1;
_arrname = _this select 2;
[_object, _arrname] call INV_CheckArray;
private["_Array"];
_Array = _object getVariable _arrname;
private["_Result", "_i"];
_Result = 0;
if(!isNil "_Array") then {
_i = 0;
while { _i < (count _Array) } do {
private["_citem"];
_citem = ((_Array select _i) select 0);
if ( _citem == _Itemname) exitWith {
_Result = ((_Array select _i) select 1);
_Result = [_Result] call decode_number;
};
_i = _i + 1;
};};
_Result
};
// Find Quantity of Items
INV_GetItemAmount = {
private["_object", "_item"];
_object = _this select 0;
_item = _this select 1;
([_object, _item, ([_object] call object_storage_name)] call INV_GetStorageAmount)
};
// Change Amount of Items
INV_SetStorageAmount = {
private ["_object", "_Itemname", "_number", "_Arrayname"];
_object = _this select 0;
_Itemname = _this select 1;
_number = _this select 2;
_Arrayname = _this select 3;
[_object, _Arrayname] call INV_CheckArray;
private["_Result", "_Array", "_i"];
_Result = false;
_Array = _object getVariable _Arrayname;
_i = 0;
while { _i < (count _Array) } do {
private["_citem"];
_citem = ((_Array select _i) select 0);
if (_citem == _Itemname) exitWith {
(_Array select _i) set [1, ([_number] call encode_number)];
_Result = true;
};
_i = _i + 1;
};
_object setVariable [_Arrayname, _Array, true];
if ( (!(_Result)) and (_number != 0) ) then {
_Result = [_object, _Itemname, _number, _Arrayname] call INV_AddItemStorage;
};
_Result
};
// Change Amount of Items
INV_SetItemAmount = {
private["_object", "_item", "_number"];
_object = _this select 0;
_item = _this select 1;
_number = _this select 2;
private["_array_name"];
_array_name = ([_object] call object_storage_name);
([_object, _item, _number, _array_name] call INV_SetStorageAmount)
};
// Check for a Type of Item in Storage
INV_StorageHasKindOf = {
private ["_object", "_Arrayname", "_Itemart"];
_object = _this select 0;
_Arrayname = _this select 1;
_Itemart = _this select 2;
[_object, _Arrayname] call INV_CheckArray;
private["_Array", "_i", "_re"];
_re = false;
_Array = _object getVariable _Arrayname;
_i = 0;
while { _i < (count _Array) } do {
private["_citem", "_count"];
_citem = ((_Array select _i) select 0);
_count = ([((_Array select _i) select 1)] call decode_number);
if (((_citem call INV_GetItemKindOf) == _Itemart) and (_count > 0)) exitWith {
_re = true;
};
_i = _i + 1;
};
_re
};
// Remove One Type of Item From Storage
INV_StorageRemoveKindOf = {
private ["_object", "_Arrayname", "_Itemart"];
_object = _this select 0;
_Arrayname = _this select 1;
_Itemart = _this select 2;
[_object, _Arrayname] call INV_CheckArray;
private["_Array", "_i"];
_Array = _object getVariable _Arrayname;
_i = 0;
while { _i < (count _Array) } do {
private["_citem"];
_citem = ((_Array select _i) select 0);
if ( (_citem call INV_GetItemKindOf) == _Itemart) then {
(_Array select _i) set [1, 0];
};
_i = _i + 1;
};
_object setVariable [_Arrayname, _Array, true];
true
};
// Check Stored Item Weight
INV_GetStorageWeight = {
private ["_object", "_Arrayname"];
_object = _this select 0;
_Arrayname = _this select 1;
[_object, _Arrayname] call INV_CheckArray;
private["_weight"];
_weight = 0;
{
private["_entry", "_item", "_count", "_infos", "_item_weight"];
_entry = _x;
_item = _entry select 0;
_count = [(_entry select 1)] call decode_number;
_infos = _item call INV_GetItemArray;
_item_weight = (_infos call INV_GetItemTypeKg);
_weight = _weight + (_count) * (_item_weight);
//_i = _i + 1;
} forEach (_object getVariable _Arrayname);
_weight
};
// Get Current Weight
INV_GetOwnWeight = {
private["_player", "_inventory_name"];
_player = player;
_inventory_name = [_player] call object_storage_name;
([_player, _inventory_name] call INV_GetStorageWeight)
};
// Remove Items that Cannot Exist
INV_RemoveIllegalStorage = {
private ["_object", "_Arrayname"];
_object = _this select 0;
_Arrayname = _this select 1;
if (not([_object, _arrayname, "drug"] call INV_StorageHasKindOf)) exitWith {
player groupchat "No illegal things found.";
false
};
private["_drugs_value", "_Array", "_i"];
_drugs_value = 0;
_Array = _object getVariable (format["%1", _arrayname]);
_i = 0;
while { _i < (count _Array) } do {
private["_item", "_infos"];
_item = ((_Array select _i) select 0);
_infos = _item call INV_GetItemArray;
if(_item call INV_GetItemKindOf == "drug") then {
private["_price", "_amount"];
_amount = ([_object, _item, _arrayname] call INV_GetStorageAmount);
_price = (_infos call INV_GetItemBuyCost);
_drugs_value = _drugs_value + (_price * _amount);
};
_i = _i + 1;
};
[_object, _arrayname, "drug"] call INV_StorageRemoveKindOf;
(format ["if (player == %2) then {player groupChat ""%1 had drugs in its trunk, you removed them. You should jail the owner of %1 for %4 minutes or give him a ticket of $%5.""}; titletext [format[localize ""STRS_civmenucheck_haddrugs"", %1, %3], ""plain""];", _vcl, player, _drugs_value, ceil(_drugs_value/20000), ceil(_drugs_value/2)]) call broadcast;
true
};
// Remove Illegal Items
INV_RemoveIllegal = {
private["_object"];
_object = _this select 0;
private["_illegalinfos", "_illwArray", "_illmags", "_has_nv", "_has_bin"];
_has_nv = if (_object hasWeapon "NVGoggles") then { true } else { false};
_has_bin = if (_object hasWeapon "Binocular") then { true } else { false};
[_object] call player_reset_gear;
if (_has_nv) then {
_object addWeapon "NVGoggles";
};
if (_has_bin) then {
_object addWeapon "Binocular";
};
[_object] call player_reset_side_inventory;
};
// Check if Player Can Carry More
INV_CanCarryItems = {
private ["_item", "_count"];
_item = _this select 0;
_count = _this select 1;
private["_items_weight", "_own_weight", "_remain_weight"];
_items_weight = ((_item call INV_GetItemTypeKg)*_count);
_own_weight = (call INV_GetOwnWeight);
_remain_weight = (INV_CarryingCapacity - _own_weight);
(_remain_weight < _items_weight)
};
// Function Object Taxes
INV_GetObjectTax = {
private["_item"];
_item = _this;
private["_result", "_i"];
_result = 0;
_i = 0;
while { _i < (count INV_ItemTypeArray) } do {
private["_citem"];
_citem = ((INV_ItemTypeArray select _i) select 0);
if (_citem == _item) exitWith {
_result = ((INV_ItemTypeArray select _i) select 2);
};
_i = _i + 1;
};
_result
};
// Fuction Add Percent (Taxes)
INV_AddPercent = {
private ["_worth", "_percent", "_result"];
_worth = _this select 0;
_percent = _this select 1;
_round = true;
if (count _this > 2) then {
_round = _this select 2
};
if (_round) then {
_result = round ( _worth + ((_worth / 100) * _percent) );
}
else {
_result = ( _worth + ((_worth / 100) * _percent) );
};
_result
};
// Find Player Weapon Type, is either 1,2 or 3. See in INV_AllWeaponObjects, select 4 then select 0. Handgun is "1", rifle "2", explosives "3".
INV_Handgun_type = 1;
INV_Rifle_type = 2;
INV_Explosive_type = 3;
INV_GetWeaponType = {
private ["_Fresult"];
_Fresult = -1;
{
if (((_x select 2) select 0) == _this) then {
_Fresult = ((_x select 4) select 0);
};
}
forEach AllLifeMissionObjects;
_Fresult
};
// Get Kind of Vehicle
INV_GetVehicleType = {
private ["_Fresult"];
_Fresult = -1;
{
if (((_x select 2) select 0) == _this) then {
_Fresult = ((_x select 4) select 0);
};
}
forEach AllLifeMissionObjects;
_Fresult
};
// Check if Player is Armed
INV_IsArmed = {if (count (weapons player - nonlethalweapons) > 0) then {true}else{false}};
// Check if unit is Armed
INV_UnitArmed = {if (count (weapons _this - nonlethalweapons) > 0) then {true}else{false}};
//Function Item Taxes
INV_GetItemTax = {
private ["_type", "_item", "_result"];
_type = _this call INV_GetItemType;
_cost = _this call INV_GetItemBuyCost;
[_cost, (_type call INV_GetObjectTax)] call INV_AddPercent;
};
//Function Price Taxes
INV_GetItemTaxPrice= {
private ["_type", "_preis", "_result"];
_type = (_this select 0) call INV_GetItemType;
_preis = (_this select 1);
[_preis, (_type call INV_GetObjectTax)] call INV_AddPercent;
};
// Check if Player Owns Licence
INV_HasLicense = {
if(count INV_LicenseOwner > 0) then {
if ( (_this == "") or (_this in INV_LicenseOwner) ) then {
true
}
else {
false
};
}
else {
if (_this == "") then {
true
}
else {
false
};
};
};
// Get Name of Licence
INV_GetLicenseName = {
private ["_c"];
for "_c" from 0 to (count INV_Licenses - 1) do {
if (((INV_Licenses select _c) select 0) == _this) exitWith {
((INV_Licenses select _c) select 2)
};
};
};
// Unknown
INV_GetScriptFromClass_Mag = {
private ["_c", "_result"];
_result = "";
for "_c" from 0 to (count AllLifeMissionObjects - 1) do {
if ((((INV_AllMagazineObjects select _c) select 2) select 0) == _this) exitWith {
_result = ((INV_AllMagazineObjects select _c) select 0);
};
};
_result
};
// Unknown
INV_GetScriptFromClass_Weap = {
private ["_c", "_result"];
_result = "";
for "_c" from 0 to (count AllLifeMissionObjects - 1) do {
if ((((INV_AllWeaponObjects select _c) select 2) select 0) == _this) exitWith {
_result = ((INV_AllWeaponObjects select _c) select 0);
};
};
_result
};
// Get item Array
INV_GetItemArray = {
private ["_Fobjarray"];
_Fobjarray = [];
//player groupChat format ["item array this %1", _this];
if ((typeName _this) == "STRING") then {
_Nname = format["A_MS_%1", _this];
_Fobjarray = missionNamespace getVariable _Nname;
//player groupChat format ["string identified %1", _Fobjarray];
};
if ((typeName _this) == "ARRAY") then {
_Fobjarray = _this;
//player groupChat format ["array identified %1", _Fobjarray];
};
_Fobjarray
};
// Get shop array
INV_GetShopArray = {
private ["_c", "_Fshoparray"];
_Fshoparray = [];
if ((typeName _this) == "OBJECT") then {
for "_c" from 0 to (count INV_ItemShops - 1) do {
if (((INV_ItemShops select _c) select 0) == _this) then {
_Fshoparray = INV_ItemShops select _c;
};
};
};
if ((typeName _this) == "ARRAY") then {
_Fshoparray = _this;
};
_Fshoparray
};
// Get shop number
INV_GetShopNum = {
private ["_item", "_shopnum"];
_item = _this;
_shopnum = [];
if ((typeName _item) == "OBJECT") then {
private["_i"];
_i = 0;
while { _i < (count INV_ItemShops) } do {
private["_citem"];
_citem = ((INV_ItemShops select _i) select 0);
if(!isNil "_citem") then {
if (_citem == _item) then {
_shopnum = _i;
};
};
_i = _i + 1;
};
};
_shopnum
};
// Get shopitem number
INV_GetShopItemNum = {
private["_item", "_shopinv"];
_item = _this select 0;
_shopinv = _this select 1;
private ["_shopitemnum"];
_shopitemnum = [];
if ((typeName _item) == "STRING") then {
private["_i"];
_i = 0;
while { _i < (count _shopinv) } do {
if ((_shopinv select _i) == _item) then {
_shopitemnum = _i;
};
_i = _i + 1;
};
};
_shopitemnum
};
INV_GetStock = {
private["_item", "_shopnum"];
_item = _this select 0;
_shopnum = (_this select 1);
private["_shoparr", "_shopinv", "_itemnum"];
_shoparr = INV_ItemShops select _shopnum;
_shopinv = _shoparr select 4;
_itemnum = [_item, _shopinv] call INV_GetShopItemnum;
if (not( typeName _shopnum == "SCALAR" && typeName _itemnum == "SCALAR")) exitWith {-1};
if(typeName (INV_ItemMaxStocks select _shopnum) != "ARRAY")exitwith{-1};
(INV_ItemStocks select _shopnum) select _itemnum
};
INV_GetMaxStock = {
private["_item", "_shopnum"];
_item = _this select 0;
_shopnum = (_this select 1);
private["_shoparr", "_shopinv", "_itemnum"];
_shoparr = INV_ItemShops select _shopnum;
_shopinv = _shoparr select 4;
_itemnum = [_item, _shopinv] call INV_GetShopItemNum;
if (not(typeName _shopnum == "SCALAR" && typename _itemnum == "SCALAR")) exitWith {-1};
if(typename (INV_ItemMaxStocks select _shopnum) != "ARRAY") exitWith {-1};
((INV_ItemMaxStocks select _shopnum) select _itemnum)
};
INV_ItemStocksupdate = {
private["_item", "_stock", "_shopnum"];
_item = _this select 0;
_stock = _this select 1;
_shopnum = _this select 2;
private["_shoparr", "_shopinv", "_itemnum"];
_shoparr = INV_ItemShops select _shopnum;
_shopinv = (_shoparr select 4);
_itemnum = [_item, _shopinv] call INV_GetShopItemNum;
if (isNil "_shopnum") exitWith {};
if (typeName _shopnum != "SCALAR") exitWith {};
if (isNil "_itemnum") exitWith {};
if (typeName _itemnum != "SCALAR") exitWith {};
(INV_ItemStocks select _shopnum) SET [_itemnum, _stock];
};
INV_HasItem = {
private["_item", "_return", "_object"];
_object = _this select 0;
_item = _this select 1;
_return = false;
//Object item
if ((typeName _item) == "STRING") then {
if(([_object, _item] call INV_GetItemAmount) > 0) exitWith{_return = true;};
};
if ((typeName _item) == "ARRAY") then {
{
if(([_object, _x] call INV_GetItemAmount) > 0) exitWith{_return = true;};
} foreach _item;
};
_return
};
INV_MyGang = {
_mygang = "";
private["_i"];
_i = 0;
while { _i < (count gangsarray) } do {
private["_gangarray", "_gang", "_members"];
_gangarray = gangsarray select _i;
_gang = _gangarray select 0;
_members = _gangarray select 1;
if((name player) in _members) then {
_mygang = _gang
};
_i = _i + 1;
};
_mygang
};
// Get Object Details
INV_GetItemScriptName = { ((_this call INV_GetItemArray) select 0)};
INV_GetItemType = {((_this call INV_GetItemArray) select 1) select 0};
INV_GetItemKindOf = { ((_this call INV_GetItemArray) select 1) select 1 };
INV_GetItemClassName = { ((_this call INV_GetItemArray) select 2) select 0 };
INV_GetItemName = {((_this call INV_GetItemArray) select 2) select 1};
INV_GetItemBuyCost = {((_this call INV_GetItemArray) select 3) select 0 };
INV_GetItemSellCost = { ((_this call INV_GetItemArray) select 3) select 1 };
INV_GetItemTypeKg = { ((_this call INV_GetItemArray) select 4) select 0 };
INV_GetVehMaxKg = { ((_this call INV_GetItemArray) select 4) select 5 };
INV_GetItemLicense = { private["_license_1"]; _license_1 = (((_this call INV_GetItemArray) select 4) select 1); if (isNil "_license_1") exitWith {""}; _license_1};
INV_GetItemLicense2 = { private["_license_2"]; _license_2 = (((_this call INV_GetItemArray) select 4) select 2); if (isNil "_license_2") exitWith {""}; _license_2};
INV_GetItemLicense3 = { private["_license_3"]; _license_3 = (((_this call INV_GetItemArray) select 4) select 3); if (isNil "_license_3") exitWith {""}; _license_3};
//if(!isNil "_this call INV_GetItemArray") then {
INV_GetItemLicense4 = {
private["_license_4"];
if(count((_this call INV_GetItemArray) select 4) >= 5) then {
_license_4 = (((_this call INV_GetItemArray) select 4) select 4);
};
if (isNil "_license_4") exitWith {""};
_license_4;
};
INV_GetItemOtherStuff = { ((_this call INV_GetItemArray) select 5) };
INV_GetItemDescription1 = { ((_this call INV_GetItemArray) select 6) };
INV_GetItemDescription2 = { ((_this call INV_GetItemArray) select 7) };
INV_GetItemMaterials = { ((_this call INV_GetItemArray) select 8) };
INV_GetItemGiveable = { ((_this call INV_GetItemArray) select 5) select 0 };
INV_GetItemDropable = { ((_this call INV_GetItemArray) select 5) select 1 };
INV_GetItemLooseable = { ((_this call INV_GetItemArray) select 5) select 2 };
INV_GetItemIsIllegal = { ((_this call INV_GetItemArray) select 5) select 3 };
INV_GetItemFilename = { ((_this call INV_GetItemArray) select 5) select 4 };
//player groupChat "Done definining INV_Functions!";