mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Merge pull request #2305 from acemod/attachEventHandlers
Attach event handlers
This commit is contained in:
commit
22f8b2e8c2
@ -8,3 +8,24 @@ class Extended_PostInit_EventHandlers {
|
||||
clientInit = QUOTE( call COMPILE_FILE(XEH_clientInit) );
|
||||
};
|
||||
};
|
||||
class Extended_GetIn_EventHandlers {
|
||||
class All {
|
||||
class ADDON {
|
||||
getIn = QUOTE(_this call FUNC(handleGetIn));
|
||||
};
|
||||
};
|
||||
};
|
||||
class Extended_GetOut_EventHandlers {
|
||||
class All {
|
||||
class ADDON {
|
||||
getOut = QUOTE(_this call FUNC(handleGetOut));
|
||||
};
|
||||
};
|
||||
};
|
||||
class Extended_Killed_EventHandlers {
|
||||
class All {
|
||||
class ADDON {
|
||||
killed = QUOTE(_this call FUNC(handleKilled));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -7,6 +7,9 @@ PREP(canAttach);
|
||||
PREP(canDetach);
|
||||
PREP(detach);
|
||||
PREP(getChildrenAttachActions);
|
||||
PREP(handleGetIn);
|
||||
PREP(handleGetOut);
|
||||
PREP(handleKilled);
|
||||
PREP(placeApprove);
|
||||
|
||||
ADDON = true;
|
||||
|
@ -17,15 +17,14 @@
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_itemVehClass", "_onAtachText", "_selfAttachPosition", "_attachedItem", "_tempObject", "_actionID", "_model"];
|
||||
params ["_attachToVehicle","_unit","_args"];
|
||||
params ["_attachToVehicle","_unit","_args", ["_silentScripted", false]];
|
||||
_args params [["_itemClassname","", [""]]];
|
||||
TRACE_3("params",_attachToVehicle,_unit,_itemClassname);
|
||||
TRACE_4("params",_attachToVehicle,_unit,_itemClassname,_silentScripted);
|
||||
|
||||
private ["_itemVehClass", "_onAtachText", "_selfAttachPosition", "_attachedItem", "_tempObject", "_actionID", "_model"];
|
||||
|
||||
//Sanity Check (_unit has item in inventory, not over attach limit)
|
||||
if ((_itemClassname == "") || {!(_this call FUNC(canAttach))}) exitWith {ERROR("Tried to attach, but check failed");};
|
||||
|
||||
_selfAttachPosition = [_unit, [-0.05, 0, 0.12], "rightshoulder"];
|
||||
if ((_itemClassname == "") || {(!_silentScripted) && {!(_this call FUNC(canAttach))}}) exitWith {ERROR("Tried to attach, but check failed");};
|
||||
|
||||
_itemVehClass = getText (configFile >> "CfgWeapons" >> _itemClassname >> "ACE_Attachable");
|
||||
_onAtachText = getText (configFile >> "CfgWeapons" >> _itemClassname >> "displayName");
|
||||
@ -40,12 +39,13 @@ if (_itemVehClass == "") exitWith {ERROR("no ACE_Attachable for Item");};
|
||||
_onAtachText = format [localize LSTRING(Item_Attached), _onAtachText];
|
||||
|
||||
if (_unit == _attachToVehicle) then { //Self Attachment
|
||||
_unit removeItem _itemClassname; // Remove item
|
||||
_attachedItem = _itemVehClass createVehicle [0,0,0];
|
||||
_attachedItem attachTo _selfAttachPosition;
|
||||
[_onAtachText] call EFUNC(common,displayTextStructured);
|
||||
_attachToVehicle setVariable [QGVAR(Objects), [_attachedItem], true];
|
||||
_attachToVehicle setVariable [QGVAR(ItemNames), [_itemClassname], true];
|
||||
_attachedItem attachTo [_unit, [-0.05, 0, 0.12], "rightshoulder"];
|
||||
if (!_silentScripted) then {
|
||||
_unit removeItem _itemClassname; // Remove item
|
||||
[_onAtachText] call EFUNC(common,displayTextStructured);
|
||||
};
|
||||
_unit setVariable [QGVAR(attached), [[_attachedItem, _itemClassname]], true];
|
||||
} else {
|
||||
GVAR(placeAction) = PLACE_WAITING;
|
||||
|
||||
|
@ -17,14 +17,17 @@
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_attachLimit", "_attachedObjects","_playerPos"];
|
||||
params ["_attachToVehicle","_player","_args"];
|
||||
_args params [["_itemClassname","", [""]]];
|
||||
TRACE_3("params",_attachToVehicle,_unit,_itemClassname);
|
||||
TRACE_3("params",_attachToVehicle,_player,_itemClassname);
|
||||
|
||||
private ["_attachLimit", "_attachedObjects"];
|
||||
|
||||
_attachLimit = [6, 1] select (_player == _attachToVehicle);
|
||||
_attachedObjects = _attachToVehicle getVariable [QGVAR(Objects), []];
|
||||
_attachedObjects = _attachToVehicle getVariable [QGVAR(attached), []];
|
||||
|
||||
_playerPos = (ACE_player modelToWorldVisual (ACE_player selectionPosition "pilot"));
|
||||
|
||||
(canStand _player) && {(_attachToVehicle distance _player) < 7} && {alive _attachToVehicle} && {(count _attachedObjects) < _attachLimit} && {_itemClassname in ((itemsWithMagazines _player) + [""])};
|
||||
((_player == _attachToVehicle) || {canStand _player}) &&
|
||||
{(_attachToVehicle distance _player) < 7} &&
|
||||
{alive _attachToVehicle} &&
|
||||
{(count _attachedObjects) < _attachLimit} &&
|
||||
{_itemClassname in ((itemsWithMagazines _player) + [""])};
|
||||
|
@ -16,25 +16,25 @@
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_attachedObjects", "_inRange"];
|
||||
params ["_attachToVehicle", "_unit"];
|
||||
TRACE_2("params",_attachToVehicle,_unit);
|
||||
|
||||
_attachedObjects = _attachToVehicle getVariable [QGVAR(Objects), []];
|
||||
_attachedList = _attachToVehicle getVariable [QGVAR(attached), []];
|
||||
if ((count _attachedList) == 0) exitWith {false};
|
||||
|
||||
private ["_inRange"];
|
||||
|
||||
_inRange = false;
|
||||
if (_unit == _attachToVehicle) then {
|
||||
_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};
|
||||
} forEach _attachedObjects;
|
||||
};
|
||||
{
|
||||
_x params ["_xObject"];
|
||||
if (isNull _xObject) exitWith {
|
||||
TRACE_1("Null attached",_x);
|
||||
_attachedList deleteAt _forEachIndex;
|
||||
_attachToVehicle setVariable [QGVAR(attached), _attachedList, true];
|
||||
};
|
||||
if (((getPos _unit) distance2d (getPos _xObject)) < 4) exitWith {_inRange = true};
|
||||
} forEach _attachedList;
|
||||
|
||||
canStand _unit && {_inRange} && {alive _attachToVehicle}
|
||||
_inRange &&
|
||||
{(_unit == _attachToVehicle) || {canStand _unit}} &&
|
||||
{alive _attachToVehicle}
|
||||
|
@ -16,15 +16,12 @@
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_attachedObjects", "_attachedItems", "_itemDisplayName",
|
||||
"_attachedObject", "_attachedIndex", "_itemName", "_minDistance",
|
||||
"_unitPos", "_objectPos"
|
||||
];
|
||||
params ["_attachToVehicle","_unit"],
|
||||
TRACE_2("params",_attachToVehicle,_unit);
|
||||
|
||||
_attachedObjects = _attachToVehicle getVariable [QGVAR(Objects), []];
|
||||
_attachedItems = _attachToVehicle getVariable [QGVAR(ItemNames), []];
|
||||
private ["_attachedList", "_itemDisplayName", "_attachedObject", "_attachedIndex", "_itemName", "_minDistance"];
|
||||
|
||||
_attachedList = _attachToVehicle getVariable [QGVAR(attached), []];
|
||||
|
||||
_attachedObject = objNull;
|
||||
_attachedIndex = -1;
|
||||
@ -32,18 +29,17 @@ _itemName = "";
|
||||
|
||||
//Find closest attached object
|
||||
_minDistance = 1000;
|
||||
_unitPos = getPos _unit;
|
||||
_unitPos set [2,0];
|
||||
|
||||
{
|
||||
_objectPos = getPos _x;
|
||||
_objectPos set [2, 0];
|
||||
if (_objectPos distance _unitPos < _minDistance) then {
|
||||
_minDistance = _objectPos distance _unitPos;
|
||||
_attachedObject = _x;
|
||||
_itemName = _attachedItems select _forEachIndex;
|
||||
_x params ["_xObject", "_xItemName"];
|
||||
|
||||
if (((getPos _unit) distance2d (getPos _xObject)) < _minDistance) then {
|
||||
_minDistance = ((getPos _unit) distance2d (getPos _xObject));
|
||||
_attachedObject = _xObject;
|
||||
_itemName = _xItemName;
|
||||
_attachedIndex = _forEachIndex;
|
||||
};
|
||||
} forEach _attachedObjects;
|
||||
} forEach _attachedList;
|
||||
|
||||
// Check if unit has an attached item
|
||||
if (isNull _attachedObject || {_itemName == ""}) exitWith {ERROR("Could not find attached object")};
|
||||
@ -68,10 +64,8 @@ if (toLower _itemName in ["b_ir_grenade", "o_ir_grenade", "i_ir_grenade"]) then
|
||||
};
|
||||
|
||||
// Reset unit variables
|
||||
_attachedObjects deleteAt _attachedIndex;
|
||||
_attachedItems deleteAt _attachedIndex;
|
||||
_attachToVehicle setVariable [QGVAR(Objects), _attachedObjects, true];
|
||||
_attachToVehicle setVariable [QGVAR(ItemNames), _attachedItems, true];
|
||||
_attachedList deleteAt _attachedIndex;
|
||||
_attachToVehicle setVariable [QGVAR(attached), _attachedList, true];
|
||||
|
||||
// Display message
|
||||
_itemDisplayName = getText (configFile >> "CfgWeapons" >> _itemName >> "displayName");
|
||||
|
38
addons/attach/functions/fnc_handleGetIn.sqf
Normal file
38
addons/attach/functions/fnc_handleGetIn.sqf
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Author: PabstMirror
|
||||
* Handles when a unit gets in to a vehicle.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: vehicle <OBJECT>
|
||||
* 1: dunno <OBJECT>
|
||||
* 2: unit <OBJECT>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [car2, x, player] call ACE_attach_fnc_handleGetIn
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
if (!isServer) exitWith {};
|
||||
|
||||
params ["", "", "_unit"];
|
||||
TRACE_1("params",_unit);
|
||||
|
||||
private ["_attachedList"];
|
||||
|
||||
_attachedList = _unit getVariable [QGVAR(attached), []];
|
||||
if ((count _attachedList) == 0) exitWith {};
|
||||
|
||||
(_attachedList select 0) params ["_xObject"];
|
||||
if (!isNull _xObject) then {
|
||||
detach _xObject;
|
||||
_xObject setPos ((getPos _unit) vectorAdd [0, 0, -1000]);
|
||||
[{deleteVehicle (_this select 0)}, [_xObject], 2] call EFUNC(common,waitAndExecute);
|
||||
(_attachedList select 0) set [0, objNull];
|
||||
};
|
||||
|
||||
_unit setVariable [QGVAR(attached), _attachedList, true];
|
35
addons/attach/functions/fnc_handleGetOut.sqf
Normal file
35
addons/attach/functions/fnc_handleGetOut.sqf
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Author: PabstMirror
|
||||
* Handles when a unit gets in to a vehicle.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: vehicle <OBJECT>
|
||||
* 1: dunno <OBJECT>
|
||||
* 2: unit <OBJECT>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [car2, x, player] call ACE_attach_fnc_handleGetOut
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
if (!isServer) exitWith {};
|
||||
|
||||
params ["", "", "_unit"];
|
||||
TRACE_1("params",_unit);
|
||||
|
||||
private ["_attachedList"];
|
||||
|
||||
_attachedList = _unit getVariable [QGVAR(attached), []];
|
||||
if ((count _attachedList) == 0) exitWith {};
|
||||
|
||||
(_attachedList select 0) params ["_xObject", "_xItemName"];
|
||||
if (isNull _xObject) then {
|
||||
TRACE_1("null attached when exiting vehicle, scripted reattach",_xItemName);
|
||||
_unit setVariable [QGVAR(attached), [], true];
|
||||
[_unit, _unit, _xItemName, true] call FUNC(attach);
|
||||
};
|
39
addons/attach/functions/fnc_handleKilled.sqf
Normal file
39
addons/attach/functions/fnc_handleKilled.sqf
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Author: PabstMirror
|
||||
* Handles when vehicle or man is killed.
|
||||
* Note: Runs where unit is local.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: DeadVehicle <OBJECT>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [bob1] call ACE_attach_fnc_handleKilled
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
params ["_deadUnit"];
|
||||
TRACE_1("params",_deadUnit);
|
||||
|
||||
private ["_attachedList"];
|
||||
|
||||
_attachedList = _deadUnit getVariable [QGVAR(attached), []];
|
||||
|
||||
if ((count _attachedList) == 0) exitWith {};
|
||||
|
||||
{
|
||||
_x params ["_xObject"];
|
||||
TRACE_2("detaching",_xObject,_deadUnit);
|
||||
detach _xObject;
|
||||
//If it's a vehicle, also delete the attached
|
||||
if (!(_deadUnit isKindOf "CAManBase")) then {
|
||||
_xObject setPos ((getPos _deadUnit) vectorAdd [0, 0, -1000]);
|
||||
[{deleteVehicle (_this select 0)}, [_xObject], 2] call EFUNC(common,waitAndExecute);
|
||||
};
|
||||
} forEach _attachedList;
|
||||
|
||||
_deadUnit setVariable [QGVAR(attached), nil, true];
|
@ -25,7 +25,7 @@
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_startingOffset", "_startDistanceFromCenter", "_closeInUnitVector", "_closeInMax", "_closeInMin", "_closeInDistance", "_endPosTestOffset", "_endPosTest", "_doesIntersect", "_startingPosShifted", "_startASL", "_endPosShifted", "_endASL", "_attachedObject", "_currentObjects", "_currentItemNames"];
|
||||
private ["_startingOffset", "_startDistanceFromCenter", "_closeInUnitVector", "_closeInMax", "_closeInMin", "_closeInDistance", "_endPosTestOffset", "_endPosTest", "_doesIntersect", "_startingPosShifted", "_startASL", "_endPosShifted", "_endASL", "_attachedObject", "_attachList"];
|
||||
|
||||
params ["_unit", "_attachToVehicle", "_itemClassname", "_itemVehClass", "_onAtachText", "_startingPosition"];
|
||||
TRACE_6("params",_unit,_attachToVehicle,_itemClassname,_itemVehClass,_onAtachText,_startingPosition);
|
||||
@ -87,12 +87,9 @@ _attachedObject attachTo [_attachToVehicle, _endPosTestOffset];
|
||||
//Remove Item from inventory
|
||||
_unit removeItem _itemClassname;
|
||||
|
||||
//Add Object to ACE_AttachedObjects and ACE_AttachedItemNames
|
||||
_currentObjects = _attachToVehicle getVariable [QGVAR(Objects), []];
|
||||
_currentObjects pushBack _attachedObject;
|
||||
_attachToVehicle setVariable [QGVAR(Objects), _currentObjects, true];
|
||||
_currentItemNames = _attachToVehicle getVariable [QGVAR(ItemNames), []];
|
||||
_currentItemNames pushBack _itemClassname;
|
||||
_attachToVehicle setVariable [QGVAR(ItemNames), _currentItemNames, true];
|
||||
//Add Object to attached array
|
||||
_attachList = _attachToVehicle getVariable [QGVAR(attached), []];
|
||||
_attachList pushBack [_attachedObject, _itemClassname];
|
||||
_attachToVehicle setVariable [QGVAR(attached), _attachList, true];
|
||||
|
||||
[_onAtachText] call EFUNC(common,displayTextStructured);
|
||||
|
Loading…
Reference in New Issue
Block a user