Home   Help Search Login Register  

Author Topic: eventhandler fired  (Read 3967 times)

0 Members and 2 Guests are viewing this topic.

Offline sharkattack

  • Former Staff
  • ****
eventhandler fired
« on: 16 Mar 2007, 10:42:48 »
hi guys .. 
im trying to set up an event handler  so that if a certain units fires his weapon (ak74) a script is called ..

failing desperatley ..
anyone any idea  what to put instead of the xxxxxxx in syntax


this addEventHandler ["fired", xxxxxxxx , xxxxxxxx  (xxxxxxxxxxx)]  exec "myScript.sqs"}]

any help  would be great            many thanx  shark-attack




"HOLY SARDINE" - see Shark-Attack meet his match

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: eventhandler fired
« Reply #1 on: 16 Mar 2007, 11:28:57 »
That whole syntax is all wrong...

If you simply want to have a script executed, you only need to use:
Code: [Select]
this addEventHandler ["fired",{_this exec "script.sqs"}]
However, if you want the script only to be executed when only the ak is fired, use something like this
Code: [Select]
this addEventHandler ["fired",{if (_this select 2 == "ak74") then {_this exec "script.sqs"}}]
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline sharkattack

  • Former Staff
  • ****
Re: eventhandler fired
« Reply #2 on: 16 Mar 2007, 11:54:18 »
thanx�  h ..
ill give it a try ... thanx again  :)
*EDIT
=====
2nd edit 
mmm ..
how can i make it so that the eventhandler is only activated once  at the min everytime loon fires script is called .. so if he gives it a long burst  my script is called several times .. 
« Last Edit: 16 Mar 2007, 12:28:41 by shark attack »
"HOLY SARDINE" - see Shark-Attack meet his match

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: eventhandler fired
« Reply #3 on: 16 Mar 2007, 13:01:54 »
Ach, yes..
I never remember that when it comes to these things  :P

I guess the easiest way (might be the only way actually) is using a global variable.
First, in your mission init.sqs (or .sqf) set the variable myvar_akFired = false

then the EH
Code: [Select]
this addEventHandler ["fired",{if (_this select 2 == "ak74" && !myvar_akFired) then {myvar_akFired=true; _this exec "script.sqs"}}]Now the eventhandler checks whether the weapon is AK74 and if it has not been fired earlier, and if so the eventhandler sets the myvarib_akFired to true and executes the script..
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline sharkattack

  • Former Staff
  • ****
Re: eventhandler fired
« Reply #4 on: 16 Mar 2007, 13:13:30 »
awsome
 i now have screaming monkeys when shots are fired in forest/jungle ..
thanx a million h
« Last Edit: 16 Mar 2007, 22:22:26 by shark attack »
"HOLY SARDINE" - see Shark-Attack meet his match

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: eventhandler fired
« Reply #5 on: 16 Mar 2007, 14:41:37 »
Quote
i now screaming monkeys when shots are fired in forest/jungle
Back you will be for more questions sense I.. 

We'll wait and see.....  :scratch:
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline sharkattack

  • Former Staff
  • ****
Re: eventhandler fired
« Reply #6 on: 16 Mar 2007, 22:24:29 »
lol..
no doubt mate ..
as long as there are guys like youreself  willing to teach ..

long live ofpec ............. :good:
"HOLY SARDINE" - see Shark-Attack meet his match

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: eventhandler fired
« Reply #7 on: 16 Mar 2007, 23:03:17 »
The thing is, that script most likely gets executed only once during the whole mission because of that global variable..

So if the script 'expires' at certain point the monkeys won't be screaming the next time..
At least they shouldn't unless ArmA somehow handles global variables differently (which I really really doubt)..
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re: eventhandler fired
« Reply #8 on: 16 Mar 2007, 23:59:01 »
sorry for spouting in....

wouldn't a removeEventHandler being easier instead of using variables? or is there something i don't know?

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: eventhandler fired
« Reply #9 on: 17 Mar 2007, 00:26:03 »
Yes, should be usable method in case similar to this..

But in this case I used variable in the example because I don't know how many units will be doing the firing..
Now the first to fire prevents any other from executing the script..
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline sharkattack

  • Former Staff
  • ****
Re: eventhandler fired
« Reply #10 on: 17 Mar 2007, 09:07:07 »
works great with variable
monkey s  scream an alert one time at the sound of gunfire  then bugger off ..
"HOLY SARDINE" - see Shark-Attack meet his match

Offline sharkattack

  • Former Staff
  • ****
Re: eventhandler fired
« Reply #11 on: 15 Apr 2007, 22:18:12 »
hi ...
have been using this code to get enemy to react to gunfire

this addEventHandler ["fired",{if (_this select 2 == "ak74" && !myvar_akFired) then {myvar_akFired=true; _this exec "script.sqs"}}]

works a treat with every weapon ... apart from M4A1GL ... i can get it to react to the flare or grenade
just not the main gun ..

this addEventHandler ["fired",{if (_this select 2 == "M4A1GL" && !myvar_akFired) then {myvar_akFired=true; _this exec "script.sqs"}}]   
dosnt fire the script !  any one know the answer  have tried all obvious solutions but to no avail ??
many thanx...
"HOLY SARDINE" - see Shark-Attack meet his match

Offline D_P_

  • Members
  • *
  • YAY! I'm a lama again! ...oh wait.
    • ArmaAddons
Re: eventhandler fired
« Reply #12 on: 16 Apr 2007, 00:20:59 »
could you post a demo mission of your screaming monkies?
just setpos & forgetpos!

Offline Cheetah

  • Former Staff
  • ****
Re: eventhandler fired
« Reply #13 on: 16 Apr 2007, 17:03:56 »
It's (probably) in his jungle mission, CO4 Especas Commando
Like missions? Help with Beta Testing! or take a look at the OFPEC Missions Depot for reviewed missions!

Offline sharkattack

  • Former Staff
  • ****
Re: eventhandler fired
« Reply #14 on: 16 Apr 2007, 18:23:18 »
co4@especas commando ... (MP/SP)
when any gun other than supressed is fired
the jungle reacts birds fly  monkeys scream ... 

back to the issue
is it all possible to set up an event handler for every weapon other than supressed weapons
then that would cover all...
« Last Edit: 16 Apr 2007, 23:16:56 by shark attack »
"HOLY SARDINE" - see Shark-Attack meet his match