OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Carroll on 07 Oct 2008, 10:47:03

Title: [solved] Distance to Object trigger
Post by: Carroll on 07 Oct 2008, 10:47:03
Hi, is it possible to use an editor placed object as a kind of trigger. For example i have a few IED-type objects (tincan, etc) which spawn at random locations at mission start. I was wondering if there was a bit of code i could use in the objects INIT that can detect when the player is say 2m away from it?

or any other better way of doing this?
Title: Re: Distance to Object trigger
Post by: Wolfrug on 07 Oct 2008, 11:10:44
Hm. Well, you could spawn {} a script that loops a check to see if the player is within 2 meters of the object at all times, and then have it blow up when appropriate, but I don't know how good that is going to be on performance if you have dozens of the things. Then again I don't know if triggers are any better either - I'd guess they are though, even if they update pretty quickly.

Untested:

Code: (In init field, write:) [Select]
nul = this spawn {while {Player distance _this > 2} do {sleep 2}; hint "You're within two meters! Yer dead!"};

Copy-pastable into each object's init field. Will just display a hint once the player is closer than 2 meters to the object. Loops every 2 seconds (make it more or less depending on how "sensitive" you want the IED to be, I guess!). Just replace the hint with whatever effect you want (I'm guessing createvehicle'ing a bomb ;))

Good luck!

Wolfrug out.
Title: Re: Distance to Object trigger
Post by: Carroll on 07 Oct 2008, 11:28:33
Thanks Wolfrug, i got no probs createVehicle-ing the explosin...i'll have a play round with the code you suggested though, as something like this was wot i am after if i can use it in the Objects Init field....

Ed: have a result!
Code: [Select]
nul = this spawn {while {PlayerName distance _this > 2} do {sleep 1}; Bomb6 = "M_Sidewinder_AA" createVehicle (getpos I6)};
Seems to be working okay, i guess i'll have to look at removing the object after it has been destroyed & that should be it!!
Cheers  :good:
Title: Re: Distance to Object trigger
Post by: Wolfrug on 07 Oct 2008, 12:06:00
You don't need to use a global variable in the createvehicle either! That's what the _this is for (and lets you copy-paste the code into as many init fields as you want). So:

Code: [Select]
nul = this spawn {while {PlayerName distance _this > 2} do {sleep 1}; _bomb = "M_Sidewinder_AA" createVehicle (getpos _this); deletevehicle _this};
That will create the bomb at the position of _this (e.g. this, e.g. the unit in whose init field the code is being run), and then delete the object afterwards. Should work!

Wolfrug out.
Title: Re: Distance to Object trigger
Post by: Carroll on 07 Oct 2008, 12:35:49
Thanks again!...anything to clean things up is always good  ;)

Ed: Cheers Spooner, i'm using triggers to detect when the Object has taken damage, so they can be shot at & counter used  :cool2:
Title: Re: Distance to Object trigger
Post by: Spooner on 07 Oct 2008, 13:52:36
Triggers always do a check every 0.5 seconds, so unless you are checking significantly less often than that, you might as well stick with a trigger.