OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: sharkattack 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
-
That whole syntax (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=a#addEventHandler) is all wrong...
If you simply want to have a script executed, you only need to use:
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
this addEventHandler ["fired",{if (_this select 2 == "ak74") then {_this exec "script.sqs"}}]
-
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 ..Â
-
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
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..
-
awsome
i now have screaming monkeys when shots are fired in forest/jungle ..
thanx a million h
-
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:
-
lol..
no doubt mate ..
as long as there are guys like youreself willing to teach ..
long live ofpec ............. :good:
-
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)..
-
sorry for spouting in....
wouldn't a removeEventHandler being easier instead of using variables? or is there something i don't know?
-
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..
-
works great with variable
monkey s scream an alert one time at the sound of gunfire then bugger off ..
-
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...
-
could you post a demo mission of your screaming monkies?
-
It's (probably) in his jungle mission, CO4 Especas Commando
-
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...
-
Should be..
Make an array of the silenced ammo or weapon names, you can find them here (http://www.ofpec.com/COMREF/armaweapons.php), and check whether the used ammo/weapon is in the array
Ammo (if ammo used is not SD ammo)
this addEventHandler ["fired",{if (!(_this select 4 in ["B_556x45_SD","B_556x45_SD"]) && !myvar_akFired) then {myvar_akFired=true; _this exec "script.sqs"}]Weapon (if weapon used not silenced)
this addEventHandler ["fired",{if (!(_this select 2 in ["M4A1SD","MP5SD"]) && !myvar_akFired) then {myvar_akFired=true; _this exec "script.sqs"}]
The ammo thing is not very usefull because in ArmA you can use SD and non-SD ammo in silenced weapons and they are still silenced so you can't tell whether the weapon used was silenced with just the ammo..
I just thought I'd post it as an example, it might very well fit some other situation.. :scratch:
Oh, and that myvar_akfired is just an example of a variable name :D
-
cheers h ... yeah i figured about variable name ..
and youre right
Back you will be for more questions sense I..
thanx again mate :good:
-
i am using the following to detect gunfire from un suppressed weapons
this addEventHandler ["fired",{if (!(_this select 2 in["M4A1SD","MP5SD","M9SD","AKS74UN","Makarov
SD"]) && !myvar_akFired) then {myvar_akFired=true; _this exec "detected.sqs"}}]
it works fine ... if the player fires anything but a silcenced weapon the enemy will react ..
however if i manage to avoid detection and go to place a charge at the target .. as soon as i put the satchel down the event handler fires
have tried adding "Put" (weapon class name)
and both PipeBomb and TimeBomb (magazine classname)
to weapons array but still everytime i set a charge the handler is fired
can anyone help with this issue
many thanx and best wishes for the new year to all ...
-
The satchel charge is called "PipeBomb" (AMMO) and is fired by "Put" (WEAPON) using the "PipeBombMuzzle" (MUZZLE). (_this select 1) is the WEAPON, (_this select 2) is the MUZZLE, and (_this select 4) is the AMMO (see the weapons COMREF (http://www.ofpec.com/COMREF/armaweapons.php) for all the possible muzzles for each weapon).
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...
In this event handler, (_this select 2) is the name of the muzzle used, not the weapon. In all weapons that only have one muzzle, the name of the muzzle is the same as the weapon though. For the M4A1GL, the muzzles are the "M4Muzzle" and the "M203Muzzle". If you just want to know which weapon has been fired, then you might as well use the weapon, rather than the muzzle (i.e. use _this select 1)).
-
thanks very much spooner
PipeBombMuzzle done the trick for the satchels :)
all the best