cleanup attach

This commit is contained in:
commy2 2015-02-15 15:31:09 +01:00
parent df23b44df5
commit baf9396459
12 changed files with 100 additions and 92 deletions

View File

@ -1,5 +1,6 @@
class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE( call COMPILE_FILE(XEH_preInit) );
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};
};

View File

@ -1,10 +1,12 @@
class CfgMagazines {
class CA_Magazine;
class B_IR_Grenade: CA_Magazine {
ACE_Attachable = 1;
};
class SmokeShell;
class Chemlight_green: SmokeShell {
ACE_Attachable = 1;
};
};
};

View File

@ -1,7 +1,3 @@
#define MACRO_ADDITEM(ITEM,COUNT) class _xx_##ITEM { \
name = #ITEM; \
count = COUNT; \
};
#define MACRO_ATTACHTOVEHICLE \
class ACE_Actions { \
@ -32,16 +28,20 @@ class CfgVehicles {
class Car: LandVehicle {
MACRO_ATTACHTOVEHICLE
};
class Tank: LandVehicle {
MACRO_ATTACHTOVEHICLE
};
class Air;
class Helicopter: Air {
MACRO_ATTACHTOVEHICLE
};
class Plane: Air {
MACRO_ATTACHTOVEHICLE
};
class Ship;
class Ship_F: Ship {
MACRO_ATTACHTOVEHICLE
@ -96,6 +96,7 @@ class CfgVehicles {
onlyInNvg = 1;
useFlare = 0;
};
side = 7;//-1=NO_SIDE yellow box,3=CIV grey box,4=NEUTRAL yellow box,6=FRIENDLY green box,7=LOGIC no radar signature
accuracy = 1000;
cost = 0;
@ -111,37 +112,36 @@ class CfgVehicles {
};
class NATO_Box_Base;
class EAST_Box_Base;
class IND_Box_Base;
class FIA_Box_Base_F;
class Box_NATO_Support_F: NATO_Box_Base {
class TransportItems {
MACRO_ADDITEM(ACE_IR_Strobe_Item,12)
MACRO_ADDITEM(ACE_IR_Strobe_Item,12);
};
};
class EAST_Box_Base;
class Box_East_Support_F: EAST_Box_Base {
class TransportItems {
MACRO_ADDITEM(ACE_IR_Strobe_Item,12)
MACRO_ADDITEM(ACE_IR_Strobe_Item,12);
};
};
class IND_Box_Base;
class Box_IND_Support_F: IND_Box_Base {
class TransportItems {
MACRO_ADDITEM(ACE_IR_Strobe_Item,12)
MACRO_ADDITEM(ACE_IR_Strobe_Item,12);
};
};
class FIA_Box_Base_F;
class Box_FIA_Support_F: FIA_Box_Base_F {
class TransportItems {
MACRO_ADDITEM(ACE_IR_Strobe_Item,12)
MACRO_ADDITEM(ACE_IR_Strobe_Item,12);
};
};
class ACE_Box_Misc: Box_NATO_Support_F {
class TransportItems {
MACRO_ADDITEM(ACE_IR_Strobe_Item,12)
MACRO_ADDITEM(ACE_IR_Strobe_Item,12);
};
};
};
};

View File

@ -1,16 +1,19 @@
class CfgWeapons {
class ACE_ItemCore;
class InventoryItem_Base_F;
class ACE_IR_Strobe_Item: ACE_ItemCore {
ACE_attachable = 1;
author = "$STR_ACE_Common_ACETeam";
scope = 2;
displayName = "$STR_ACE_IrStrobe_Name";
descriptionShort = "$STR_ACE_IrStrobe_Description";
model = "\A3\weapons_F\ammo\mag_univ.p3d";
picture = PATHTOF(UI\irstrobe_item.paa);
scope = 2;
ACE_attachable = 1;
class ItemInfo: InventoryItem_Base_F {
mass = 1;
};
};
};
};

View File

@ -5,17 +5,14 @@ class CfgPatches {
units[] = {};
weapons[] = {"ACE_IR_Strobe_Item"};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_common", "ace_interaction"};
author[] = {"KoffeinFlummi", "eRazeri", "CAA-Picard"};
requiredAddons[] = {"ace_common","ace_interaction"};
author[] = {"KoffeinFlummi","eRazeri","CAA-Picard"};
authorUrl = "https://github.com/KoffeinFlummi/";
VERSION_CONFIG;
};
};
#include "CfgEventHandlers.hpp"
#include "CfgVehicles.hpp"
#include "CfgWeapons.hpp"
#include "CfgMagazines.hpp"
#include "CfgVehicles.hpp"
#include "CfgWeapons.hpp"

View File

@ -20,31 +20,33 @@
PARAMS_3(_unit,_attachToVehicle,_itemName);
//Sanity Check (_unit has item in inventory, not over attach limit)
if (!([_unit,_attachToVehicle,_itemName] call FUNC(canAttach))) exitWith {ERROR("Tried to attach, but check failed");};
if !([_unit, _attachToVehicle, _itemName] call FUNC(canAttach)) exitWith {ERROR("Tried to attach, but check failed");};
private ["_itemVehClass", "_onAtachText", "_selfAttachPosition"];
_selfAttachPosition = [_unit, [-0.05,0,0.12], "rightshoulder"];
_itemVehClass = "";
_onAtachText = "";
_selfAttachPosition = [_unit, [-0.05, 0, 0.12], "rightshoulder"];
switch true do {
case (_itemName == "ACE_IR_Strobe_Item"): {
switch (true) do {
case (_itemName == "ACE_IR_Strobe_Item"): {
_itemVehClass = "ACE_IR_Strobe_Effect";
_onAtachText = localize "STR_ACE_Attach_IrStrobe_Attached";
_selfAttachPosition = [_unit,[0,-0.11,0.16],"pilot"]; //makes it attach to the head a bit better, shoulder is not good for visibility - eRazeri
//_selfAttachPosition = [_unit, [0, -0.11, 0.16], "pilot"]; //makes it attach to the head a bit better, shoulder is not good for visibility - eRazeri
};
case (_itemName == "B_IR_Grenade"): {
case (_itemName == "B_IR_Grenade"): {
_itemVehClass = "B_IRStrobe";
_onAtachText = localize "STR_ACE_Attach_IrGrenade_Attached";
};
case (_itemName == "O_IR_Grenade"): {
case (_itemName == "O_IR_Grenade"): {
_itemVehClass = "O_IRStrobe";
_onAtachText = localize "STR_ACE_Attach_IrGrenade_Attached";
};
case (_itemName == "I_IR_Grenade"): {
case (_itemName == "I_IR_Grenade"): {
_itemVehClass = "I_IRStrobe";
_onAtachText = localize "STR_ACE_Attach_IrGrenade_Attached";
};
case (_itemName == "Chemlight_blue" or {_itemName == "Chemlight_green"} or {_itemName == "Chemlight_red"} or {_itemName == "Chemlight_yellow"}): {
case (toLower _itemName in ["chemlight_blue", "chemlight_green", "chemlight_red", "chemlight_yellow"]): {
_itemVehClass = _itemName;
_onAtachText = localize "STR_ACE_Attach_Chemlight_Attached";
};
@ -57,8 +59,8 @@ if (_unit == _attachToVehicle) then { //Self Attachment
_attachedItem = _itemVehClass createVehicle [0,0,0];
_attachedItem attachTo _selfAttachPosition;
[_onAtachText] call EFUNC(common,displayTextStructured);
_attachToVehicle setVariable ["ACE_AttachedObjects", [_attachedItem], true];
_attachToVehicle setVariable ["ACE_AttachedItemNames", [_itemName], true];
_attachToVehicle setVariable [QGVAR(Objects), [_attachedItem], true];
_attachToVehicle setVariable [QGVAR(ItemNames), [_itemName], true];
} else {
GVAR(setupObject) = _itemVehClass createVehicleLocal [0,0,-10000];
GVAR(setupObject) enableSimulationGlobal false;
@ -72,17 +74,17 @@ if (_unit == _attachToVehicle) then { //Self Attachment
private "_player";
_player = ACE_player;
//Stop if player switch or player gets to far from vehicle
if ((GVAR(placer) != _player) || {(_player distance GVAR(SetupAttachVehicle)) > 7}) exitWith {
if (GVAR(placer) != _player || {_player distance GVAR(SetupAttachVehicle) > 7}) exitWith {
call FUNC(placeCancel);
};
GVAR(pfeh_running) = true;
_pos = (ASLtoATL eyePos _player) vectorAdd (positionCameraToWorld [0,0,1] vectorDiff positionCameraToWorld [0,0,0]);
GVAR(setupObject) setPosATL _pos;
}] call BIS_fnc_addStackedEventHandler;
}] call BIS_fnc_addStackedEventHandler; // @todo replace with CBA PFH
//had to delay the mouseHint, not sure why
[{[localize "STR_ACE_Attach_PlaceAction", localize "STR_ACE_Attach_CancelAction"] call EFUNC(interaction,showMouseHint)}, [], 0, 0] call EFUNC(common,waitAndExecute);
_unit setVariable [QGVAR(placeActionEH), [_unit, "DefaultAction", {GVAR(pfeh_running) AND !isNull (GVAR(setupObject))}, {call FUNC(placeApprove);}] call EFUNC(common,AddActionEventHandler)];
_unit setVariable [QGVAR(cancelActionEH), [_unit, "MenuBack", {GVAR(pfeh_running) AND !isNull (GVAR(setupObject))}, {call FUNC(placeCancel);}] call EFUNC(common,AddActionEventHandler)];
_unit setVariable [QGVAR(placeActionEH), [_unit, "DefaultAction", {GVAR(pfeh_running) && {!isNull (GVAR(setupObject))}}, {call FUNC(placeApprove);}] call EFUNC(common,AddActionEventHandler)];
_unit setVariable [QGVAR(cancelActionEH), [_unit, "MenuBack", {GVAR(pfeh_running) && {!isNull (GVAR(setupObject))}}, {call FUNC(placeCancel);}] call EFUNC(common,AddActionEventHandler)];
};

View File

@ -19,7 +19,9 @@
PARAMS_3(_unit,_attachToVehicle,_item);
_attachLimit = if (_unit == _attachToVehicle) then {1} else {10};
_attachedObjects = _attachToVehicle getVariable ["ACE_AttachedObjects", []];
private ["_attachLimit", "_attachedObjects"];
canStand _unit && {alive _attachToVehicle} && {(count _attachedObjects) < _attachLimit} && {_item in ((magazines _unit) + (items _unit) + [""])}
_attachLimit = [10, 1] select (_unit == _attachToVehicle);
_attachedObjects = _attachToVehicle getVariable [QGVAR(Objects), []];
canStand _unit && {alive _attachToVehicle} && {count _attachedObjects < _attachLimit} && {_item in (itemsWithMagazines _unit + [""])}

View File

@ -16,24 +16,25 @@
*/
#include "script_component.hpp"
private ["_attachedObjects", "_inRange", "_unitPos", "_objectPos"];
PARAMS_2(_unit,_attachToVehicle);
_attachedObjects = _attachToVehicle getVariable ["ACE_AttachedObjects", []];
private ["_attachedObjects", "_inRange"];
_attachedObjects = _attachToVehicle getVariable [QGVAR(Objects), []];
_inRange = false;
if (_unit == _attachToVehicle) then {
_inRange = (count _attachedObjects) > 0;
_inRange = count _attachedObjects > 0;
} else {
//Scan if unit is within range (using 2d distance)
private ["_unitPos", "_objectPos"];
_unitPos = getPos _unit;
_unitPos set [2,0];
{
_objectPos = getPos _x;
_objectPos set [2, 0];
if ((_objectPos distance _unitPos) < 4) exitWith {_inRange = true};
if (_objectPos distance _unitPos < 4) exitWith {_inRange = true};
} forEach _attachedObjects;
};
(canStand _unit) && _inRange && {alive _attachToVehicle}
canStand _unit && {_inRange} && {alive _attachToVehicle}

View File

@ -16,12 +16,14 @@
*/
#include "script_component.hpp"
private ["_itemName", "_count", "_attachedItem", "_fnc_detachDelay"];
PARAMS_2(_unit,_attachToVehicle);
_attachedObjectsArray = _attachToVehicle getVariable ["ACE_AttachedObjects", []];
_attachedItemsArray = _attachToVehicle getVariable ["ACE_AttachedItemNames", []];
private ["_attachedObjects", "_attachedItems"];
_attachedObjects = _attachToVehicle getVariable [QGVAR(Objects), []];
_attachedItems = _attachToVehicle getVariable [QGVAR(ItemNames), []];
private ["_attachedObject", "_attachedIndex", "_itemName", "_minDistance", "_unitPos", "_objectPos"];
_attachedObject = objNull;
_attachedIndex = -1;
@ -34,53 +36,51 @@ _unitPos set [2,0];
{
_objectPos = getPos _x;
_objectPos set [2, 0];
if ((_objectPos distance _unitPos) < _minDistance) then {
_minDistance = (_objectPos distance _unitPos);
if (_objectPos distance _unitPos < _minDistance) then {
_minDistance = _objectPos distance _unitPos;
_attachedObject = _x;
_itemName = _attachedItemsArray select _forEachIndex;
_itemName = _attachedItems select _forEachIndex;
_attachedIndex = _forEachIndex;
};
} forEach _attachedObjectsArray;
} forEach _attachedObjects;
// Check if unit has an attached item
if ((isNull _attachedObject) || {_itemName == ""}) exitWith {ERROR("Could not find attached object")};
if (isNull _attachedObject || {_itemName == ""}) exitWith {ERROR("Could not find attached object")};
// Add item to inventory
_count = (count items _unit) + (count magazines _unit);
_unit addItem _itemName;
if ((count items _unit) + (count magazines _unit) <= _count) exitWith {
// Exit if can't add the item
if !(_unit canAdd _itemName) exitWith {
[localize "STR_ACE_Attach_Inventory_Full"] call EFUNC(common,displayTextStructured);
};
if (_itemName == "B_IR_Grenade" or _itemName == "O_IR_Grenade" or _itemName == "I_IR_Grenade") then {
// Add item to inventory
_unit addItem _itemName;
if (toLower _itemName in ["b_ir_grenade", "o_ir_grenade", "i_ir_grenade"]) then {
// Hack for dealing with X_IR_Grenade effect not dissapearing on deleteVehicle
detach _attachedObject;
_attachedObject setPos [getPos _unit select 0, getPos _unit select 1, ((getPos _unit select 2) - 1000)];
_attachedObject setPos ((getPos _unit) vectorAdd [0, 0, -1000]);
// Delete attached item after 0.5 seconds
_fnc_detachDelay = {
deleteVehicle (_this select 0);
};
[_fnc_detachDelay, [_attachedObject], 0.5, 0] call EFUNC(common,waitAndExecute);
[{deleteVehicle (_this select 0)}, [_attachedObject], 0.5, 0] call EFUNC(common,waitAndExecute);
} else {
// Delete attached item
deleteVehicle _attachedObject;
};
// Reset unit variables
_attachedObjectsArray deleteAt _attachedIndex;
_attachedItemsArray deleteAt _attachedIndex;
_attachToVehicle setVariable ["ACE_AttachedObjects", _attachedObjectsArray, true];
_attachToVehicle setVariable ["ACE_AttachedItemNames", _attachedItemsArray, true];
_attachedObjects deleteAt _attachedIndex;
_attachedItems deleteAt _attachedIndex;
_attachToVehicle setVariable [QGVAR(Objects), _attachedObjects, true];
_attachToVehicle setVariable [QGVAR(ItemNames), _attachedItems, true];
// Display message
switch true do {
case (_itemName == "ACE_IR_Strobe_Item") : {
switch (true) do {
case (_itemName == "ACE_IR_Strobe_Item") : {
[localize "STR_ACE_Attach_IrStrobe_Detached"] call EFUNC(common,displayTextStructured);
};
case (_itemName == "B_IR_Grenade" or _itemName == "O_IR_Grenade" or _itemName == "I_IR_Grenade") : {
case (toLower _itemName in ["b_ir_grenade", "o_ir_grenade", "i_ir_grenade"]) : {
[localize "STR_ACE_Attach_IrGrenade_Detached"] call EFUNC(common,displayTextStructured);
};
case (_itemName == "Chemlight_blue" or {_itemName == "Chemlight_green"} or {_itemName == "Chemlight_red"} or {_itemName == "Chemlight_yellow"}) : {
case (toLower _itemName in ["chemlight_blue", "chemlight_green", "chemlight_red", "chemlight_yellow"]) : {
[localize "STR_ACE_Attach_Chemlight_Detached"] call EFUNC(common,displayTextStructured);
};
};

View File

@ -55,13 +55,13 @@ _attachables = items _unit;
} forEach _attachables;
[
_actions,
{
[ACE_player, GVAR(attachTarget), _this] call FUNC(attach);
call EFUNC(interaction,hideMenu);
},
{
call EFUNC(interaction,hideMenu);
if !(profileNamespace getVariable [QEGVAR(interaction,AutoCloseMenu), false]) then {"Default" call EFUNC(interaction,openMenuSelf)};
}
_actions,
{
[ACE_player, GVAR(attachTarget), _this] call FUNC(attach);
call EFUNC(interaction,hideMenu);
},
{
call EFUNC(interaction,hideMenu);
if !(profileNamespace getVariable [QEGVAR(interaction,AutoCloseMenu), false]) then {"Default" call EFUNC(interaction,openMenuSelf)};
}
] call EFUNC(interaction,openSelectMenu);

View File

@ -100,11 +100,11 @@ _attachedObject attachTo [_attachToVehicle, _endPosTestOffset];
_placer removeItem _itemClassname;
//Add Object to ACE_AttachedObjects and ACE_AttachedItemNames
_currentObjects = _attachToVehicle getVariable ["ACE_AttachedObjects", []];
_currentObjects = _attachToVehicle getVariable [QGVAR(Objects), []];
_currentObjects pushBack _attachedObject;
_attachToVehicle setVariable ["ACE_AttachedObjects", _currentObjects, true];
_currentItemNames = _attachToVehicle getVariable ["ACE_AttachedItemNames", []];
_attachToVehicle setVariable [QGVAR(Objects), _currentObjects, true];
_currentItemNames = _attachToVehicle getVariable [QGVAR(ItemNames), []];
_currentItemNames pushBack _itemClassname;
_attachToVehicle setVariable ["ACE_AttachedItemNames", _currentItemNames, true];
_attachToVehicle setVariable [QGVAR(ItemNames), _currentItemNames, true];
[_placementText] call EFUNC(common,displayTextStructured);

View File

@ -176,4 +176,4 @@
<Spanish>Error en Acoplar</Spanish>
</Key>
</Package>
</Project>
</Project>