cybercoco 16 Posted January 16, 2016 I have the following code in init.sqf : _won = nearestObjects [player, ["C_Offroad_01_F"], 50]; _won = str _won select [1,5]; _won = call compile _won; // script for trigger _trg = createTrigger ["EmptyDetector", getPos _won, false]; _trg setTriggerArea [3, 3, 0, false]; _trg setTriggerActivation ["WEST","PRESENT",true]; _trg setVariable ["won", _won]; _trg setTriggerStatements [ "this && !(player in (thisTrigger getVariable 'won'))", "(thisTrigger getVariable 'won') addaction [ '<t>Title</t>', 'jack\jack.sqf',"",11]", "removeallactions (thisTrigger getVariable 'won') && hint ''" ]; This will look for the nearest vehicle (id : C_Offroad_01_F) name and store it in _won. The result is that only one trigger has been created for only one vehicle (the nearest). What I would like is to have a "constant" search for the nearest vehicle for each player and then create a for this vehicle trigger. If you didn't understand the text above, then read this : Final objective would be to have an addaction on any vehicle that's in a 3 meters range of a player. Share this post Link to post Share on other sites
Guest Posted January 16, 2016 Depending on the vehicle quantity, vehicles + distance check may be more efficient. You can also add the action on the player with the nearEntities check Share this post Link to post Share on other sites
shuko 59 Posted January 16, 2016 I must be blind or just slow, but why not just do addAction on the vehicle(s)? Share this post Link to post Share on other sites
jshock 512 Posted January 17, 2016 I must be blind or just slow, but why not just do addAction on the vehicle(s)? My thoughts as well, with the condition of the action being: "_this distance _target < 3" Share this post Link to post Share on other sites
cybercoco 16 Posted January 17, 2016 My thoughts as well, with the condition of the action being: "_this distance _target < 3" My code doesn't work : { _this addaction [format ["<t>-Title Here-</t>"],"jack\jack.sqf", "", 11, "", "", "", "_this distance _target < 3"] } forEach vehicles; Share this post Link to post Share on other sites
shuko 59 Posted January 17, 2016 Change _this addaction to _x addaction Share this post Link to post Share on other sites
cybercoco 16 Posted January 17, 2016 Change _this addaction to _x addaction Changed it, _x works, thanks Shuko ! { _x addaction [format ["<t>Title Here</t>"],"jack\jack.sqf","",11, true, true, "", "_this distance _target < 3"] } foreach vehicles; Just curious, do I do forEach ["C_Offroad_01_F"] if I want it for a particular type of vehicle ? Share this post Link to post Share on other sites
Grumpy Old Man 3544 Posted January 17, 2016 If you only run this once then it should be no problem, if you want it on every vehicle in the mission. For applying the action to specific types only you can change it into something like this: _type = "C_Offroad_01_F"; { if (typeOf _x isEqualTo _type) then { _x addaction [format ["<t>Title Here</t>"],"jack\jack.sqf","",11, true, true, "", "_this distance _target < 3"]; }; } foreach vehicles; Cheers Share this post Link to post Share on other sites
cybercoco 16 Posted January 17, 2016 If you only run this once then it should be no problem, if you want it on every vehicle in the mission. For applying the action to specific types only you can change it into something like this: _type = "C_Offroad_01_F"; { if (typeOf _x isEqualTo _type) then { _x addaction [format ["<t>Title Here</t>"],"jack\jack.sqf","",11, true, true, "", "_this distance _target < 3"]; }; } foreach vehicles; Cheers Thanks mate ! Share this post Link to post Share on other sites
cybercoco 16 Posted January 23, 2016 Is there a way to delete the addAction if someone gets in the vehicle (only remove the addAction from this one vehicle) ? But then add it back when the player gets out... Tried it, but doesn't work : _type = "C_Offroad_01_F"; { if (typeOf _x isEqualTo _type) then { while { alive _x} do { if (!player in _x) then { _x addaction ["Hello","jack.sqf","",11, true, true, "", "_this distance _target < 3"]; } else { removeallactions _x; }; sleep 2; }; }; } foreach vehicles; Share this post Link to post Share on other sites
f2k sel 164 Posted January 23, 2016 you can just use the condition, by someone do you mean player, AI or both. Just Player _type = "C_Offroad_01_F"; { if (typeOf _x isEqualTo _type) then { _x addaction [format ["<t>Title Here</t>"],"jack\jack.sqf","",11, true, true, "", "_this distance _target < 3 and { !(player in _target))]; }; } foreach vehicles; any unit in vehicle inc player _type = "C_Offroad_01_F"; { if (typeOf _x isEqualTo _type) then { _x addaction [format ["<t>Title Here</t>"],"jack\jack.sqf","",11, true, true, "", "_this distance _target < 3 and (count crew _target == 0)"]; }; } foreach vehicles; Share this post Link to post Share on other sites
whiztler 137 Posted January 23, 2016 Alternatively, you can add the getIn eventHandler. More efficient than adding actions/triggers to all vehicles IMHO. For players leaving the vehicle, use the getOut eventhandler. Share this post Link to post Share on other sites
cybercoco 16 Posted January 23, 2016 Just can just use the condition, by someone do you mean player, AI or both. Just Player _type = "C_Offroad_01_F"; { if (typeOf _x isEqualTo _type) then { _x addaction [format ["<t>Title Here</t>"],"jack\jack.sqf","",11, true, true, "", "_this distance _target < 3 and { !(player in _target))]; }; } foreach vehicles; any unit in vehicle inc player _type = "C_Offroad_01_F"; { if (typeOf _x isEqualTo _type) then { _x addaction [format ["<t>Title Here</t>"],"jack\jack.sqf","",11, true, true, "", "_this distance _target < 3 and (count crew _target == 0)"]; }; } foreach vehicles; Thank you, I just realised that I was actually using this double condition on my version but I didn't notice that the thing was working. Share this post Link to post Share on other sites