Jump to content
mudnut

[RELEASE] Custom EVH: Position Changed

Recommended Posts

Position Changed "Custom EVH"

Hi all, this script executes code with given parameters and one passed parameter (new position of unit) upon the unit changing positions.

Here is the script, the header should explain how to use it thoroughly enough:

Thanks to Commy2 for the help and feedback!

Spoiler

fn_posChanged


/*
  Author: mudnut

  Description: Executes given code with parameters upon movement change

  Paramter(s):
  0 - OBJECT: Unit to evaluate
  1 - CODE: Code to execute when position of unit has changed (New position of unit is passed) (Passed params by user are contained as an array inside an array)
  2 - ARRAY: Array of parameters to pass to code
  3 - NUMBER: (Optional) The distance needed to change before calling code (Default 1 Meter)
  4 - BOOLEAN: (Optiona) True for 3D scan of movement, or False for 2D scan of movement (Default true)
  5 - NUMBER: (Optional) Suspension time between checks (Default 0)

  Returns: Nothing

  EXAMPLE: [player,{hint "Players Pos Has Changed!"},[name player],1,false,3] spawn mud_fnc_posChanged
*/
params[
  ["_unit",objNull,[objNull]],
  ["_code",{},[{}]],
  ["_params",[],[[]]],
  ["_distance",1,[0]],
  ["_type",true,[true]],
  ["_suspend",0,[0]]
];
if(!canSuspend) exitWith{diag_log "Fnc posChanged is not in scheduled and cannot suspend"};
private _pos = getPosWorld _unit;
waitUntil{
  if(_type) then {
    if(_pos vectorDistance getPosWorld _unit > _distance) then
    {
      _pos = getPosWorld _unit;
      [_pos,_params] call _code;
    };
  } else {
    if(_pos distance2D getPosWorld _unit > _distance) then {
      _pos = getPosWorld _unit;
      [_pos,_params] call _code;
    };
  };
  sleep _suspend;
  !alive _unit || _unit getVariable "POS_EXIT"
};

If there is any bugs or you want to give some feedback let me know!

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

×