Home   Help Search Login Register  

Author Topic: Using eventhandlers to detect which weapon has been fired....  (Read 927 times)

0 Members and 1 Guest are viewing this topic.

Offline Gogs

  • Contributing Member
  • **
  • WWIIEC - Gracefully retired boss
Word up crew. Working on a few missions involving aircraft. I wan't to use the eventhandler "fired" to trigger a radio call of "Fox One" or "Fox Two", depending on the weapon. Currently using a script that detects the shell/missile in flight, but it isn't 100% reliable, and relys on using the nearestobject command, every 0.01 seconds, which isn't going to be good on low end machines. I know how to add the event handler, but I'm not sure of the syntax for using one of the returned values to determine which script to run. I thought of something like this.......

aircraft addEventHandler ["fired",{if (this select 4) == "shell/missilename" then (exec "myscript.sqs}]

But OFP doesn't like it or anything I can think of. Anyone know how to write it? Thanks in advance.

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Using eventhandlers to detect which weapon has been fired....
« Reply #1 on: 22 May 2005, 01:23:52 »
You have the right idea, but your syntax is wrong:

aircraft addEventHandler ["fired",{if ((this select 4) == "shell/missilename") then {exec "myscript.sqs"}}]

Always triple-check and make sure you have a closing parenthesis for each opening one.
« Last Edit: 22 May 2005, 01:24:28 by General Barron »
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline Gogs

  • Contributing Member
  • **
  • WWIIEC - Gracefully retired boss
Re:Using eventhandlers to detect which weapon has been fired....
« Reply #2 on: 22 May 2005, 02:20:21 »
Oh yeah, that wasn't coppied and pasted from the mission editor, thats just what I wrote here. Now, I coppied and pasted yours, and I think I'm getting warmer, but now I get

if ((this select 3) == "shell/missilename") then {exec "myscript.sqs"} error select : type object, expected array

So I'm not sure that what I'm doing isn't fundamentally wrong somewhere. Here is the arguments for the "Fired" event handler....

"Fired" string:weapon,string:muzzle,string:mode,string:ammo

Here is my full line of code....

this addEventHandler ["fired",{if ((this select 4) == "FLKAW_AIM9L") then {exec "fox2.sqs"}}]

Where "FLKAW_AIM9L" is the name of my ammo. Any clues anybody? I still think its a syntax thingy...

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Using eventhandlers to detect which weapon has been fired....
« Reply #3 on: 22 May 2005, 02:28:11 »
hmmmmmm......should it be _this select 4 instead of this select 4 ?


Planck
I know a little about a lot, and a lot about a little.

Offline Gogs

  • Contributing Member
  • **
  • WWIIEC - Gracefully retired boss
Re:Using eventhandlers to detect which weapon has been fired....
« Reply #4 on: 22 May 2005, 02:33:54 »
Hehe, buy that man a beer! :D

Thankyou, problem solved. Watch out for the mission in the Falklands MOD, its coming along nicely!