Jump to content
Tajin

[RELEASE] [Function] aimedAt

Recommended Posts

So I just stumbled upon an old function that I wrote for a civilian script and decided to optimize it a bit and share it with everyone here.

Originally, this was used to make civilians freeze, surrender and get out of cars when they see you pointing a weapon at them.

-

Due to optimization, the code in this one isn't as clearly readable as the original, result is the same though:

scriptName "fn_aimedAt";
/*
Author: Tajin

Description:
Determines if _actor is pointing his weapon close to the _target (within _tolerance in meters).
Main use of this command was not to determine if _actor would hit _target but rather to determine if _target feels like _actor is aiming at him.

Parameter(s):
#0 OBJECT - _actor (the guy with the weapon)
#1 OBJECT - _target (the person supposedly aimed at)
#2 NUMBER - _tolerance in meters
(distance is calculated to the actual line of fire, not the point _actor aims at. That means it will still trigger, even if you closely aim past the _target.)

Returns:
BOOL - TRUE when within _tolerance
*/

private ["_actor","_target","_pos0","_pos1"];

_actor = _this select 0;
_target = _this select 1;
if ( isNull _actor ) exitWith {false};
if ( isNull _target ) exitWith {false};
if ( weaponLowered _actor ) exitWith {false};
if ( _target knowsAbout _actor < 3 ) exitWith {false};

_pos0 = getPosASL _actor;
_pos1 = getPosASL _target;
( ( ( _pos0 vectorAdd ( (_actor weaponDirection (currentWeapon _actor)) vectorMultiply (_pos0 distance _pos1) ) ) distanceSqr _pos1 ) < ((_this select 2)^2) )

This script is mainly good for checking if _target feels threatened by _actor.

Preferably use small numbers for "_tolerance".

If you set _tolance to 10 for example, the _target will "feel threatened" when you get too close to him, even if you don't aim in his direction.

Keep in mind, that this doesn't check for obstacles. (depending on the situation you use it in, that isn't even necessary and I wanted it to be as fast as possible)

Here's an example how it can be used:

{ [_x select 4,_unit,0.9] call ArA_fnc_aimedAt } count _targets > 0

This is a simple check that will return true if _unit notices any of his known _targets aiming at him.

Share this post


Link to post
Share on other sites

Shouldn't make much difference in this case but I would suggest to run it where the _target is local.

Share this post


Link to post
Share on other sites

Yeah! I was writing something like this myself, only a bit different and seemingly more complicated as I couldn't get it working correctly.

Thanks for sharing. :)

Share this post


Link to post
Share on other sites

I was thinking of a system somewhat like this for my code snippet (in my signature), but decided a snippet is a snippet, but I will definetly look into implementing this into it at some point. Thanks for the function Tajin! :D

Share this post


Link to post
Share on other sites

How can i make it so the script works on every civilian unit? Even if used spawned by Zeus?

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×