Epoch/Sources/epoch_code/compile/EPOCH_consumeItem.sqf

316 lines
11 KiB
Plaintext
Raw Normal View History

2015-12-07 16:24:52 +00:00
/*
Author: Aaron Clark - EpochMod.com
Contributors:
Description:
Epoch consume item function
Licence:
Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike
Github:
2016-06-13 16:54:19 +00:00
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/EPOCH_consumeItem.sqf
2015-12-07 16:24:52 +00:00
*/
2016-09-01 00:40:18 +00:00
//[[[cog import generate_private_arrays ]]]
private ["_buildClass","_buildingCountLimit","_buildingJammerRange","_canCapacity","_cfgBaseBuilding","_cfgItemInteractions","_color","_currentDMG","_currentFuel","_currentHIT","_fuelCapacity","_highestDMG","_interactAttributes","_interactOption","_interactReturnOnUse","_isOk","_isStorage","_magazineSize","_magazineSizeMax","_magazinesAmmoFull","_newDMG","_newFuel","_object","_otherObjects","_output","_paintCanColor","_paintCanIndex","_partCheck","_pos","_removeItem","_transportFuel","_unifiedInteract","_vehicle","_vehicles"];
//[[[end]]]
EPOCH_InteractedItem params ["_text","_item","_pic"];
2015-09-14 20:55:36 +00:00
_cfgBaseBuilding = 'CfgBaseBuilding' call EPOCH_returnConfig;
_cfgItemInteractions = ["CfgItemInteractions", _item] call EPOCH_returnConfigV2;
// _cfgItemInteractions = (('CfgItemInteractions' call EPOCH_returnConfig) >> _item);
2016-05-06 20:30:10 +00:00
_interactOption = getNumber(_cfgItemInteractions >> "interactAction");
_interactAttributes = getArray(_cfgItemInteractions >> "interactAttributes");
_interactReturnOnUse = getText(_cfgItemInteractions >> "interactReturnOnUse");
_inputCount = count _this;
if (_inputCount >= 1) then {
_interactOption = param [0,0];
};
if (_inputCount >= 2) then {
_interactAttributes = param [1,[]];
};
if (_inputCount >= 3) then {
_interactReturnOnUse = param [2,""];
};
// diag_log format["DEBUG: %1",[_interactOption,_interactAttributes,_interactReturnOnUse]];
2015-09-14 20:55:36 +00:00
_removeItem = {([player,_this] call BIS_fnc_invRemove) == 1};
_unifiedInteract = {
if (_item call _removeItem) then {
Release 0.3.8 (#502) * first build for 0.3.8 * 0.3.8.0190 * 0.3.8.0202 * 0.3.8.0213 * 0.3.7.0214 * 0.3.8.0222 * 0.3.8.0246 * 0.3.8.0247 fixed typo * 0.3.8.0249 more fixes for server compiler * 0.3.8.0256 * add build number and simple batch file for packing * match build number with internal * add build numbers to server pbo's and mission files also reworked build script for more options * 0.3.8.0261 * 0.3.8.0261 * 0.3.8.0283 * 0.3.8.0284 * changelog * 0.3.8.0307 * 0.3.8.0311 * remove old BEC plugin * update redis-server.exe to latest build and full config * 0.3.8.0314 * 0.3.8.0315 * inverse logic This should correctly prevent spawning these units nearby jammer or protection zones * use pushbackUnique here * optimized loot function by using selectRandom instead of slower sqf logic * 0.3.8.0316 * make use of new getDir functionality instead of BIS fnc * add lower disconnect value to server.cfg * use new getpos functionality * 0.3.8.0317 * 0.3.8.0319 * 0.3.8.0327 * 0.3.8.0338 changelog update tba * changelog * 0.3.8.0341 * BE update * 0.3.8.0353 * changelog * removed duplicates * 0.3.8.0355 fixed error in getIDC * 0.3.8.0356 revert to BIS_fnc_param as params threw errors * 0.3.8.0357 fixes for #496 #497 * 0.3.8.0359 fixed #497 fixed #496 * 0.3.8.0365 * 0.3.8.0371 * 0.3.8.0373 * 0.3.8.0379 * 0.3.8.0381 * 0.3.8.0386 * 0.3.8.0393 * 0.3.8.0395 * 0.3.8.0396 * 0.3.8.0397 * 0.3.8.0406 * 0.3.8.0409 * 0.3.8.0410 loot balance suppress error in spawnloot make near object check based on building size * 0.3.8.0412 * 0.3.8.0414 removed classes with scope 0 test remove loot trash on gear for #498 fixed #501 * 0.3.8.0415 * same
2016-04-08 20:21:46 +00:00
if (_interactReturnOnUse != "") then {
_interactReturnOnUse call EPOCH_fnc_addItemOverflow;
};
2015-09-14 20:55:36 +00:00
{
_output = _x call EPOCH_giveAttributes;
Release 0.3.8 (#502) * first build for 0.3.8 * 0.3.8.0190 * 0.3.8.0202 * 0.3.8.0213 * 0.3.7.0214 * 0.3.8.0222 * 0.3.8.0246 * 0.3.8.0247 fixed typo * 0.3.8.0249 more fixes for server compiler * 0.3.8.0256 * add build number and simple batch file for packing * match build number with internal * add build numbers to server pbo's and mission files also reworked build script for more options * 0.3.8.0261 * 0.3.8.0261 * 0.3.8.0283 * 0.3.8.0284 * changelog * 0.3.8.0307 * 0.3.8.0311 * remove old BEC plugin * update redis-server.exe to latest build and full config * 0.3.8.0314 * 0.3.8.0315 * inverse logic This should correctly prevent spawning these units nearby jammer or protection zones * use pushbackUnique here * optimized loot function by using selectRandom instead of slower sqf logic * 0.3.8.0316 * make use of new getDir functionality instead of BIS fnc * add lower disconnect value to server.cfg * use new getpos functionality * 0.3.8.0317 * 0.3.8.0319 * 0.3.8.0327 * 0.3.8.0338 changelog update tba * changelog * 0.3.8.0341 * BE update * 0.3.8.0353 * changelog * removed duplicates * 0.3.8.0355 fixed error in getIDC * 0.3.8.0356 revert to BIS_fnc_param as params threw errors * 0.3.8.0357 fixes for #496 #497 * 0.3.8.0359 fixed #497 fixed #496 * 0.3.8.0365 * 0.3.8.0371 * 0.3.8.0373 * 0.3.8.0379 * 0.3.8.0381 * 0.3.8.0386 * 0.3.8.0393 * 0.3.8.0395 * 0.3.8.0396 * 0.3.8.0397 * 0.3.8.0406 * 0.3.8.0409 * 0.3.8.0410 loot balance suppress error in spawnloot make near object check based on building size * 0.3.8.0412 * 0.3.8.0414 removed classes with scope 0 test remove loot trash on gear for #498 fixed #501 * 0.3.8.0415 * same
2016-04-08 20:21:46 +00:00
if (_output != "") then {
2016-06-18 01:22:29 +00:00
[_output, 5] call Epoch_message;
Release 0.3.8 (#502) * first build for 0.3.8 * 0.3.8.0190 * 0.3.8.0202 * 0.3.8.0213 * 0.3.7.0214 * 0.3.8.0222 * 0.3.8.0246 * 0.3.8.0247 fixed typo * 0.3.8.0249 more fixes for server compiler * 0.3.8.0256 * add build number and simple batch file for packing * match build number with internal * add build numbers to server pbo's and mission files also reworked build script for more options * 0.3.8.0261 * 0.3.8.0261 * 0.3.8.0283 * 0.3.8.0284 * changelog * 0.3.8.0307 * 0.3.8.0311 * remove old BEC plugin * update redis-server.exe to latest build and full config * 0.3.8.0314 * 0.3.8.0315 * inverse logic This should correctly prevent spawning these units nearby jammer or protection zones * use pushbackUnique here * optimized loot function by using selectRandom instead of slower sqf logic * 0.3.8.0316 * make use of new getDir functionality instead of BIS fnc * add lower disconnect value to server.cfg * use new getpos functionality * 0.3.8.0317 * 0.3.8.0319 * 0.3.8.0327 * 0.3.8.0338 changelog update tba * changelog * 0.3.8.0341 * BE update * 0.3.8.0353 * changelog * removed duplicates * 0.3.8.0355 fixed error in getIDC * 0.3.8.0356 revert to BIS_fnc_param as params threw errors * 0.3.8.0357 fixes for #496 #497 * 0.3.8.0359 fixed #497 fixed #496 * 0.3.8.0365 * 0.3.8.0371 * 0.3.8.0373 * 0.3.8.0379 * 0.3.8.0381 * 0.3.8.0386 * 0.3.8.0393 * 0.3.8.0395 * 0.3.8.0396 * 0.3.8.0397 * 0.3.8.0406 * 0.3.8.0409 * 0.3.8.0410 loot balance suppress error in spawnloot make near object check based on building size * 0.3.8.0412 * 0.3.8.0414 removed classes with scope 0 test remove loot trash on gear for #498 fixed #501 * 0.3.8.0415 * same
2016-04-08 20:21:46 +00:00
};
2015-09-14 20:55:36 +00:00
} foreach _interactAttributes;
};
};
switch _interactOption do {
2015-12-29 18:22:24 +00:00
case 0: {
2016-05-06 20:30:10 +00:00
_magazineSizeMax = getNumber (configfile >> "CfgMagazines" >> _item >> "count");
2015-12-29 18:22:24 +00:00
// allow repack for all magazines with greater than 1 bullet
2016-01-08 04:32:52 +00:00
if (_magazineSizeMax > 1) then {
2015-12-29 18:22:24 +00:00
2016-01-08 04:32:52 +00:00
_magazineSize = 0;
2015-12-29 18:22:24 +00:00
_magazinesAmmoFull = magazinesAmmoFull player;
{
if (_item isEqualTo (_x select 0)) then {
2016-01-08 04:32:52 +00:00
if (!(_x select 2)) then {
_magazineSize = _magazineSize + (_x select 1);
};
2015-12-29 18:22:24 +00:00
};
} forEach _magazinesAmmoFull;
// remove all
player removeMagazines _item;
// Add full magazines back to player
for "_i" from 1 to floor (_magazineSize / _magazineSizeMax) do
{
player addMagazine [_item, _magazineSizeMax];
};
// Add last non full magazine
if ((_magazineSize % _magazineSizeMax) > 0) then {
player addMagazine [_item, floor (_magazineSize % _magazineSizeMax)];
};
2016-06-18 01:22:29 +00:00
["Ammo Repacked", 5] call Epoch_message;
2015-12-29 18:22:24 +00:00
};
};
2015-09-14 20:55:36 +00:00
case 1: _unifiedInteract; // Eat 1
case 2: _unifiedInteract; //Drink 2
case 3: { // Build 3
closeDialog 0;
_buildingJammerRange = ["CfgEpochClient", "buildingJammerRange", 75] call EPOCH_fnc_returnConfigEntryV2;
_buildingCountLimit = ["CfgEpochClient", "buildingCountLimit", 200] call EPOCH_fnc_returnConfigEntryV2;
_partCheck = _item in (magazines player);
2016-05-06 20:30:10 +00:00
_buildClass = getText(_cfgItemInteractions >> "buildClass");
if (_buildClass != "" && _partCheck) then {
_isStorage = getNumber(_cfgItemInteractions >> "isStorage");
2015-09-14 20:55:36 +00:00
2015-10-28 15:16:00 +00:00
_isOk = if (_isStorage == 1 || _buildClass isKindOf "Secure_Storage_Temp") then { EPOCH_StorageSlotsCount > 0 } else { EPOCH_BuildingSlotCount > 0 };
2015-09-14 20:55:36 +00:00
if (isNil "EPOCH_simulSwap_Lock") then {
if !(isNil "_isOk") then {
if (_isOk) then {
if (_buildClass call EPOCH_isBuildAllowed) then {
if (EPOCH_playerEnergy > 0) then {
EPOCH_buildMode = 1;
EPOCH_buildDirection = 0;
// base building
_pos = player modelToWorldVisual[0, 5, 0];
_pos set[2, getPosATL player select 2];
if (_buildClass isKindOf "ThingX") then {
// prevent spawning if another simulated object exists still
_otherObjects = nearestObjects[player, [_buildClass], _buildingJammerRange];
if (_otherObjects isEqualTo []) then {
_object=createVehicle[_buildClass,_pos,[],0,"CAN_COLLIDE"];
_object setDir ((getDir player) - 180);
[format["Press '%1' to drop object.", "1"], 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
if (([player, _item] call BIS_fnc_invRemove) == 1) then {
[_object] spawn EPOCH_simulSwap;
};
}
else {
2016-06-18 01:22:29 +00:00
["Building Disallowed: Frequency Unstable", 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
};
}
else {
_object=createVehicle[_buildClass,_pos,[],0,"CAN_COLLIDE"];
_object setDir ((getDir player) - 180);
[format["Press '%1' to drop object.", "1"], 5] call Epoch_message;
[_object,_item] spawn EPOCH_staticMove;
2015-09-14 20:55:36 +00:00
};
}
else {
2016-06-18 01:22:29 +00:00
["Need Energy", 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
};
};
} else {
2016-06-18 01:22:29 +00:00
["World limit reached", 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
};
};
};
};
};
case 4: { // Refuel 4
2016-04-17 20:28:21 +00:00
_vehicles = player nearEntities [["LandVehicle","Ship","Air","Tank"], 30];
2015-09-14 20:55:36 +00:00
if (cursorTarget in _vehicles) then {
_vehicle = cursorTarget;
_currentFuel = fuel _vehicle;
2016-01-08 22:27:07 +00:00
_canCapacity = _interactAttributes param [0,10];
2015-09-14 20:55:36 +00:00
_fuelCapacity = getNumber (configfile >> "CfgVehicles" >> (typeOf _vehicle) >> "fuelCapacity");
_currentFuel = _currentFuel * _fuelCapacity;
_newFuel = _currentFuel + _canCapacity;
_newFuel = _newFuel / _fuelCapacity;
if (_item call _removeItem) then {
2016-01-15 19:22:40 +00:00
_interactReturnOnUse call EPOCH_fnc_addItemOverflow;
2015-12-23 17:38:11 +00:00
// send
[_vehicle,_newFuel,player,Epoch_personalToken] remoteExec ["EPOCH_server_fillVehicle",2];
2016-06-18 01:22:29 +00:00
["Fuel Added", 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
};
};
};
case 5: {
2016-04-17 20:28:21 +00:00
_vehicles = player nearEntities [["LandVehicle","Ship","Air","Tank"], 30];
2016-01-08 22:27:07 +00:00
_canCapacity = _interactAttributes param [0,10];
2015-09-14 20:55:36 +00:00
if (cursorTarget in _vehicles) then {
_vehicle = cursorTarget;
_fuelCapacity = getNumber (configfile >> "CfgVehicles" >> (typeOf _vehicle) >> "fuelCapacity");
_newFuel = (((fuel _vehicle) * _fuelCapacity) - _canCapacity) / _fuelCapacity;
if (_newFuel > 0) then {
if (_item call _removeItem) then {
2016-01-15 19:22:40 +00:00
_interactReturnOnUse call EPOCH_fnc_addItemOverflow;
2015-12-23 17:38:11 +00:00
[_vehicle,_newFuel,player,Epoch_personalToken] remoteExec ["EPOCH_server_fillVehicle",2];
2016-06-18 01:22:29 +00:00
["Fuel Siphoned", 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
};
} else {
2016-06-18 01:22:29 +00:00
["Not Enough Fuel", 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
};
2016-01-08 22:27:07 +00:00
} else {
// find any other nearby fuel sources
_transportFuel = 0;
{
_transportFuel = _transportFuel + getNumber (configFile >> "CfgVehicles" >> (typeOf _x) >> "transportFuel");
} forEach (player nearObjects["ALL", 6]);
if (_transportFuel > _canCapacity) then {
if (_item call _removeItem) then {
2016-01-17 14:44:52 +00:00
_interactReturnOnUse call EPOCH_fnc_addItemOverflow;
2016-06-18 01:22:29 +00:00
["Fuel Siphoned", 5] call Epoch_message;
2016-01-08 22:27:07 +00:00
};
} else {
2016-06-18 01:22:29 +00:00
["Not Enough Fuel", 5] call Epoch_message;
2016-01-08 22:27:07 +00:00
};
2015-09-14 20:55:36 +00:00
};
};
case 6: _unifiedInteract; //Clean -25
case 7: _unifiedInteract; //Warm + 1
case 8: _unifiedInteract; //Cold -1
case 9: _unifiedInteract; //Energy 100
case 10: { // Repair 10 - Lite
2016-04-17 20:28:21 +00:00
_vehicles = player nearEntities [["LandVehicle","Ship","Air","Tank"], 30];
2015-09-14 20:55:36 +00:00
_vehicle = cursorTarget;
if (_vehicle in _vehicles) then {
if (_item call _removeItem) then {
_highestDMG = 0;
_currentHIT = -1;
_currentDMG = 0;
{
_currentDMG = _x;
if (_currentDMG > _highestDMG) then {
_highestDMG = _currentDMG;
_currentHIT = _forEachIndex;
};
}forEach ((getAllHitPointsDamage _vehicle) param [2,[]]);
if (_highestDMG > 0) then {
_newDMG = ((_highestDMG - 0.5) max 0);
if (local _vehicle) then {
[_vehicle, [_currentHIT, _newDMG]] call EPOCH_client_repairVehicle;
} else {
2015-12-23 17:38:11 +00:00
[_vehicle,[_currentHIT,_newDMG],player,Epoch_personalToken] remoteExec ["EPOCH_server_repairVehicle",2];
2015-09-14 20:55:36 +00:00
};
} else {
if ((damage _vehicle) > 0) then {
2015-12-23 17:38:11 +00:00
[_vehicle,["ALL",0],player,Epoch_personalToken] remoteExec ["EPOCH_server_repairVehicle",2];
2015-09-14 20:55:36 +00:00
};
};
2016-06-18 01:22:29 +00:00
["Vehicle Partially Repaired", 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
};
};
};
case 11: { // Repair 11 - Heavy
2016-04-17 20:28:21 +00:00
_vehicles = player nearEntities [["LandVehicle","Ship","Air","Tank"], 30];
2015-09-14 20:55:36 +00:00
_vehicle = cursorTarget;
if (_vehicle in _vehicles) then {
if (_item call _removeItem) then {
2015-12-23 17:38:11 +00:00
[_vehicle,["ALL",0],player,Epoch_personalToken] remoteExec ["EPOCH_server_repairVehicle",2];
2016-06-18 01:22:29 +00:00
["Vehicle Fully Repaired", 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
};
};
};
// case 12 consume paincan and set texture on base object (only if has slot and is static)
case 12: {
closeDialog 0;
_vehicles = player nearObjects["Const_WoodWalls_static_F", 5];
_vehicle = cursorTarget;
if (_vehicle in _vehicles) then {
if ("" call EPOCH_isBuildAllowed) then {
_color = getArray(_cfgBaseBuilding >> (typeOf _vehicle) >> "availableTextures");
2015-09-14 20:55:36 +00:00
if !(_color isEqualTo[]) then {
if (_item call _removeItem) then {
// find _paintCanIndex from config
_paintCanIndex = getNumber(_cfgItemInteractions >> "textureIndex");
_paintCanColor = getText(_cfgItemInteractions >> "colorName");
2015-09-14 20:55:36 +00:00
2015-12-23 17:38:11 +00:00
[_vehicle,_paintCanIndex,player,Epoch_personalToken] remoteExec ["EPOCH_server_paintBUILD",2];
2015-09-14 20:55:36 +00:00
2016-06-18 01:22:29 +00:00
[format["Wall Painted %1", _paintCanColor], 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
};
};
}
else {
2016-06-18 01:22:29 +00:00
["Disallowed", 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
};
};
};
case 13: { //Heal Player
_vehicles = player nearEntities[["Epoch_Male_F", "Epoch_Female_F"], 6];
_vehicle = cursorTarget;
if (_vehicle in _vehicles) then {
if (damage _vehicle != 0 || {_x > 0} count ((getallhitpointsdamage _vehicle) select 2) > 0) then {
2015-09-14 20:55:36 +00:00
if (_item call _removeItem) then {
2015-12-23 17:38:11 +00:00
[_vehicle,["ALL",0],player,Epoch_personalToken] remoteExec ["EPOCH_server_repairVehicle",2];
2016-06-18 01:22:29 +00:00
["Healed other player", 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
};
};
} else {
if (damage player != 0 || {_x > 0} count ((getallhitpointsdamage player) select 2) > 0) then {
2015-09-14 20:55:36 +00:00
if (_item call _removeItem) then {
2015-12-23 17:38:11 +00:00
[player,["ALL",0],player,Epoch_personalToken] remoteExec ["EPOCH_server_repairVehicle",2];
2016-06-18 01:22:29 +00:00
["Healed yourself", 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
};
};
};
};
2016-01-08 22:27:07 +00:00
case 14: { // Unpack Backpack
if (_item call _removeItem) then {
[_interactReturnOnUse,player,Epoch_personalToken] remoteExec ["EPOCH_server_unpackBackpack",2];
2016-06-18 01:22:29 +00:00
["Unpacked backpack", 5] call Epoch_message;
2016-01-08 22:27:07 +00:00
};
};
2015-09-14 20:55:36 +00:00
default {
2016-06-18 01:22:29 +00:00
["Found nothing", 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
};
};