wok 1 Posted November 1, 2013 (edited) I am working on some scripts and I need to detect when you are aiming at an enemy. I did some research and found cursorTarget and sideEnemy. But I am not sure how to use it, I think the login (not actual code) would be something like: if (side cursorTarget == sideEnemy) { hint "test"; }; But how would I run that all the time? I mean, the code needs to be checking contanstly and show the hint if aiming at an enemy, do I need to use a loop, trigger or something like that? Where would I put the code? Sorry for the noob questions, any advice will be appreciated. Edited November 1, 2013 by wok Share this post Link to post Share on other sites
roy86 367 Posted November 1, 2013 use this: _enemySide = east; // <!-- Change this to which ever side you consider the enemy waitUntil { if (side cursorTarget == _enemySide) { hint "test"; }; false }; Word of warning: using hint is going to spam you with an annoying sound. I'd use hintSilent. Share this post Link to post Share on other sites
wok 1 Posted November 1, 2013 Thanks for the code, I also think I found a way to do it with triggers, will test that and your code tomorrow, time to sleep now. Btw I did know about the hint spam, I just tried to keep the code minimal to better explain what I needed. Thanks again. Share this post Link to post Share on other sites
wok 1 Posted November 1, 2013 (edited) My end goal for this is to add an addAction menu entry when aiming at an enemy from close range, so I will be able to give him a command like "freeze" or "hands up" to an enemy AI. I managed to do the aiming part like this: init.sqf _trigger = createTrigger ["EmptyDetector", [0,0,0]]; _trigger setTriggerArea [0, 0, 0, false]; _trigger setTriggerActivation ["NONE", "present", true]; _trigger setTriggerStatements ["side cursorTarget == east", "execVM 'test.sqf'" , ""]; test.sqf player addAction ["Hands up!", {hint "test";}]; This works fine (if you are a NATO aiming at a CSAT), but the problem is that since I am not removing the action I get duplicated entries every time I aim at the enemy. I know I can use removeAction to remove it, but how do I run removeAction on this action when the player aims away from the enemy? UPDATE: I feel dumb, I can just use the addAction condition parameter instead of the trigger, I will still use the trigger method to add some complexity like detecting if the player is aiming his gun at the enemy after telling him to put the hunds up, but im not yet there. Edited November 1, 2013 by wok Share this post Link to post Share on other sites
froggyluv 2135 Posted October 3, 2016 Hey trying to get the variable that is the enemy unit that cursorTarget is aimed at to call a function 'Frog_ Move': _target = cursortarget;_trigger = createTrigger ["EmptyDetector", [0,0,0]];_trigger setTriggerArea [0, 0, 0, false];_trigger setTriggerActivation ["NONE", "present", true];_trigger setTriggerStatements ["_target isKindOf 'man' ", "[_target] call Frog_Move" , ""]; - doesnt fire Also used the above example: _trigger = createTrigger ["EmptyDetector", [0,0,0]]; _trigger setTriggerArea [0, 0, 0, false];_trigger setTriggerActivation ["NONE", "present", true];_trigger setTriggerStatements ["side cursorTarget == east", "[_this call Frog_Move" , ""]; - the function was called but the '_this' wasnt accounted and the function passed him over. Share this post Link to post Share on other sites
Tajin 349 Posted October 4, 2016 1. Why did you hijack this old thread instead of making a new one? They're not really related. 2. Give us some background on what you're actually trying to do and why you think you need a trigger for it. Share this post Link to post Share on other sites
froggyluv 2135 Posted October 4, 2016 Ok Im trying to have an animation (or series of) play when player points his gun at an enemy spec op at close range. init.sqf _target = cursortarget; _trigger = createTrigger ["EmptyDetector", [0,0,0]]; _trigger setTriggerArea [0, 0, 0, false]; _trigger setTriggerActivation ["NONE", "present", true]; _trigger setTriggerStatements ["_target isKindOf 'man'", "[_target] call Frog_Move" , ""];Frog_Move ={ _this select 0; hint "gun is on him!"; if ((player distance _this < 20) && (_this in Frog_ReconEast)) then {_this switchmove "AmovPercMevaSrasWrflDfr_AmovPknlMstpSrasWrflDnon"}; Share this post Link to post Share on other sites
Tajin 349 Posted October 4, 2016 Allright. Don't use a trigger for that :) This should do (init.sqf): if (hasInterface) then { addMissionEventHandler ["EachFrame",{ private ["_trg"]; _trg = cursorObject; // instead of cursorTarget... might be better, give it a try if (_trg isKindOf "man") then { if (_trg in (missionNamespace getVariable ["Frog_ReconEast",[]])) then { // getVariable to avoid errors if the variable is not set if ((player distanceSqr _trg) < 400) then { // 20^2 hintSilent "gun is on him"; [_trg,"AmovPercMevaSrasWrflDfr_AmovPknlMstpSrasWrflDnon"] remoteExec ["switchMove", 0]; // for Multiplayer, to make sure everyone sees the animation }; }; }; }]; }; Share this post Link to post Share on other sites
froggyluv 2135 Posted October 4, 2016 Hmm not working for me outta the box. Definitely not familar with MP so Hasinterface, addMissionEventHandler "eachFrame".... are a little foreign to me. Does this EH need to be applied to player/playable units? Even removing the variable Frog_ReconEast and just looking for a hint I wasnt able to get anything to fire. Share this post Link to post Share on other sites
Tajin 349 Posted October 4, 2016 Just tried it, it works fine for me. You might just have to add some sort of delay to allow the animation to play completely. (it currently restarts as long as you aim on the guy) Share this post Link to post Share on other sites
froggyluv 2135 Posted October 5, 2016 Yes your right Tajin, seems another script i wrote was conflicting with this somehow. Thanks Edit: Actually needed a 'typeOf' as Frog_ReconEast is an array of units - prolly wasnt clear here if (typeOf _trg in (missionNamespace getVariable ["Frog_ReconEast",[]])) Share this post Link to post Share on other sites