Added tag destruction on object destruction

This commit is contained in:
BaerMitUmlaut 2015-07-21 19:03:25 +02:00
parent 9cba6c6793
commit c532d893c3
5 changed files with 87 additions and 42 deletions

View File

@ -5,5 +5,6 @@ ADDON = false;
PREP(checkTaggable);
PREP(tagWall);
PREP(tagGround);
PREP(handleTagDestruction);
ADDON = true;

View File

@ -18,7 +18,6 @@
#include "script_component.hpp"
private ["_posCheck", "_objectsLeft", "_intersectsLeft", "_objectsRight", "_intersectsRight"];
_posCheck = ACE_player modelToWorldVisual [-0.5, 2, 0];
_posCheck set [2, (eyePos ACE_player) select 2];

View File

@ -0,0 +1,38 @@
/*
* Author: BaerMitUmlaut
* Handles tag destruction when the object they are attached to gets destroyed.
*
* Arguments:
* None
*
* Return Value:
* 0: The tag that should get destroyed <OBJECT>
* 1: The object the tag is attached to <OBJECT>
*
* Example:
* [tag, object] call ace_tagging_fnc_handleTagDestruction
*
* Public: No
*/
#include "script_component.hpp"
private ["_tag", "_attachedTags", "_object"];
PARAMS_2(_tag,_object);
if (count (_object getVariable [QGVAR(attachedTags), []]) == 0) then {
_object setVariable [QGVAR(attachedTags), [_tag]];
_object addEventHandler ["HandleDamage", {
if ((_this select 1) == "" && (_this select 2) >= 1) then {
{
deleteVehicle _x;
} foreach ((_this select 0) getVariable ["ace_tagging_attachedTags", []]);
(_this select 0) setVariable ["ace_tagging_attachedTags", []];
};
}];
} else {
_attachedTags = _object getVariable [QGVAR(attachedTags), []];
_attachedTags pushBack _tag;
_object setVariable [QGVAR(attachedTags), _attachedTags];
};

View File

@ -20,7 +20,7 @@ private ["_color", "_tagPos", "_groundPos", "_vectorDirAndUp"];
PARAMS_1(_color);
if !((toLower _color) in ["black", "red", "green", "blue"]) exitWith {
["%1 is not a valid tag colour.", _color] call BIS_fnc_error;
["%1 is not a valid tag colour.", _color] call BIS_fnc_error;
};
_tagPos = player modelToWorld [0, 1.2, 0];
@ -31,20 +31,20 @@ _groundPos set [2, 0];
//Check if we're in or on top of some object
if (lineIntersects [getPosASL ACE_player, ATLToASL _groundPos, ACE_player, objNull]) then {
_tagPos set [2, (getPosATL ACE_player) select 2];
_vectorDirAndUp = [[0,0,-1], vectorDir ACE_player];
_tagPos set [2, (getPosATL ACE_player) select 2];
_vectorDirAndUp = [[0,0,-1], vectorDir ACE_player];
} else {
_tagPos set [2, 0];
_vectorDirAndUp = [(surfaceNormal _tagPos) vectorMultiply -1, vectorDir ACE_player];
_tagPos set [2, 0];
_vectorDirAndUp = [(surfaceNormal _tagPos) vectorMultiply -1, vectorDir ACE_player];
};
ACE_player playActionNow "PutDown";
[{
private ["_tag"];
playSound3D [QUOTE(PATHTO_R(sounds\spray.ogg)), ACE_player, false, (getPosASL ACE_player), 10, 1, 15];
_tag = "UserTexture1m_F" createVehicle [0,0,0];
_tag setObjectTextureGlobal [0, '\z\ace\addons\tagging\UI\tags\' + (_this select 2) + '\' + str (floor (random 3)) + '.paa'];
_tag setPosATL (_this select 0);
_tag setVectorDirAndUp (_this select 1);
private ["_tag"];
playSound3D [QUOTE(PATHTO_R(sounds\spray.ogg)), ACE_player, false, (getPosASL ACE_player), 10, 1, 15];
_tag = "UserTexture1m_F" createVehicle [0,0,0];
_tag setObjectTextureGlobal [0, '\z\ace\addons\tagging\UI\tags\' + (_this select 2) + '\' + str (floor (random 3)) + '.paa'];
_tag setPosATL (_this select 0);
_tag setVectorDirAndUp (_this select 1);
}, [_tagPos, _vectorDirAndUp, _color], 0.6] call EFUNC(common,waitAndExecute);

View File

@ -20,7 +20,7 @@ private ["_color", "_eyepos", "_touchingPoints", "_pointCloser", "_pointFurther"
PARAMS_1(_color);
if !((toLower _color) in ["black", "red", "green", "blue"]) exitWith {
["%1 is not a valid tag colour.", _color] call BIS_fnc_error;
["%1 is not a valid tag colour.", _color] call BIS_fnc_error;
};
//Cache eyepos in case player moves
@ -28,46 +28,53 @@ _eyepos = eyePos ACE_player;
_touchingPoints = [];
{
//When tagWall is called, we already know there is an object within 2m in front of us.
//We define two points (or rather distances from the player) where the wall is always in between.
//When tagWall is called, we already know there is an object within 2m in front of us.
//We define two points (or rather distances from the player) where the wall is always in between.
_pointCloser = 0;
_pointFurther = 2;
_pointCloser = 0;
_pointFurther = 2;
for "_i" from 0 to 6 do {
for "_i" from 0 to 6 do {
//We need to reduce the distance between those points until we get a very precise position.
//This is done by checking if it is between the closer point and the point in between the two.
//We need to reduce the distance between those points until we get a very precise position.
//This is done by checking if it is between the closer point and the point in between the two.
_posCheckCloser = ACE_player modelToWorldVisual [_x, _pointCloser, 0];
_posCheckCloser set [2, _eyepos select 2];
_posCheckCloser = ACE_player modelToWorldVisual [_x, _pointCloser, 0];
_posCheckCloser set [2, _eyepos select 2];
_posCheckFurther = ACE_player modelToWorldVisual [_x, (_pointCloser + ((_pointFurther - _pointCloser) / 2)), 0];
_posCheckFurther set [2, _eyepos select 2];
_posCheckFurther = ACE_player modelToWorldVisual [_x, (_pointCloser + ((_pointFurther - _pointCloser) / 2)), 0];
_posCheckFurther set [2, _eyepos select 2];
if (lineIntersects [_posCheckCloser, _posCheckFurther, ACE_player, objNull]) then {
//If it is, we move the further point to be closer to the closer point.
_pointFurther = _pointCloser + ((_pointFurther - _pointCloser) / 2);
} else {
//If it isn't, we move the closer point towards the further point.
_pointCloser = _pointCloser + ((_pointFurther - _pointCloser) / 2);
};
};
if (lineIntersects [_posCheckCloser, _posCheckFurther, ACE_player, objNull]) then {
//If it is, we move the further point to be closer to the closer point.
_pointFurther = _pointCloser + ((_pointFurther - _pointCloser) / 2);
} else {
//If it isn't, we move the closer point towards the further point.
_pointCloser = _pointCloser + ((_pointFurther - _pointCloser) / 2);
};
};
//We do this 7 times each a bit to the left and right of the player - that's definitely precise enough.
_touchingPoint = ACE_player modelToWorldVisual [_x, _pointCloser, 0];
_touchingPoint set [2, _eyepos select 2];
_touchingPoints pushBack (_touchingPoint);
//We do this 7 times each a bit to the left and right of the player - that's definitely precise enough.
_touchingPoint = ACE_player modelToWorldVisual [_x, _pointCloser, 0];
_touchingPoint set [2, _eyepos select 2];
_touchingPoints pushBack (_touchingPoint);
} foreach [-0.5, 0.5];
ACE_player playActionNow "PutDown";
[{
private ["_tag"];
playSound3D [QUOTE(PATHTO_R(sounds\spray.ogg)), ACE_player, false, (getPosASL ACE_player), 10, 1, 15];
_tag = "UserTexture1m_F" createVehicle [0,0,0];
_tag setObjectTextureGlobal [0, '\z\ace\addons\tagging\UI\tags\' + (_this select 1) + '\' + str (floor (random 3)) + '.paa'];
_tag setPosASL (((_this select 0 select 0) vectorAdd (_this select 0 select 1)) vectorMultiply 0.5);
_tag setDir (((_this select 0) call BIS_fnc_dirTo) - 90);
private ["_tag", "_object", "_posCheck"];
_posCheck = ACE_player modelToWorldVisual [0, 2, 0];
_posCheck set [2, (eyePos ACE_player) select 2];
_object = (lineIntersectsWith [_posCheck, eyePos player, ACE_player, objNull, true]) select 0;
playSound3D [QUOTE(PATHTO_R(sounds\spray.ogg)), ACE_player, false, (getPosASL ACE_player), 10, 1, 15];
_tag = "UserTexture1m_F" createVehicle [0,0,0];
_tag setObjectTextureGlobal [0, '\z\ace\addons\tagging\UI\tags\' + (_this select 1) + '\' + str (floor (random 3)) + '.paa'];
_tag setPosASL (((_this select 0 select 0) vectorAdd (_this select 0 select 1)) vectorMultiply 0.5);
_tag setDir (((_this select 0) call BIS_fnc_dirTo) - 90);
[[_tag, _object], QUOTE(FUNC(handleTagDestruction)), 1] call EFUNC(common,execRemoteFnc);
}, [_touchingPoints, _color], 0.6] call EFUNC(common,waitAndExecute);