Home   Help Search Login Register  

Author Topic: [solved] Distance to Object trigger  (Read 1904 times)

0 Members and 1 Guest are viewing this topic.

Offline Carroll

  • Members
  • *
  • Mission Designer (MP-"well tryin to capiche"
[solved] Distance to Object trigger
« 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?
« Last Edit: 09 Oct 2008, 08:54:52 by Carroll »

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Distance to Object trigger
« Reply #1 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.
"When 900 years YOU reach, look as good you will not!"

Offline Carroll

  • Members
  • *
  • Mission Designer (MP-"well tryin to capiche"
Re: Distance to Object trigger
« Reply #2 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:
« Last Edit: 07 Oct 2008, 11:46:19 by Carroll »

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Distance to Object trigger
« Reply #3 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.
"When 900 years YOU reach, look as good you will not!"

Offline Carroll

  • Members
  • *
  • Mission Designer (MP-"well tryin to capiche"
Re: Distance to Object trigger
« Reply #4 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:
« Last Edit: 08 Oct 2008, 13:30:44 by Carroll »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Distance to Object trigger
« Reply #5 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.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)