Home   Help Search Login Register  

Author Topic: Fired eventhandler again.  (Read 1176 times)

0 Members and 1 Guest are viewing this topic.

Offline The-Architect

  • Former Staff
  • ****
  • Bite my shiny metal...
    • Bob's Un-official Flashpoint Page
Fired eventhandler again.
« on: 22 Mar 2005, 22:55:26 »
Ok, here's the problem. I have a hunter script which will send enemy ai units after the player if you fire a non silenced weapon. I can get the script send the guys once a loud weapon has been fired but the problem arises when the player fires a silenced weapon and then a loud one after it. It seems like the script is finished after its decided the first shot is safe.
 I'll post the script shortly.
James Andrew Wilkinson 1977 - 2005 R.I.P.
"If it ain't the friggin' incoming it's the friggin' outgoing. Only difference is who gets the friggin' grease, and that ain't no friggin' difference at all."

Offline The-Architect

  • Former Staff
  • ****
  • Bite my shiny metal...
    • Bob's Un-official Flashpoint Page
Re:Fired eventhandler again.
« Reply #1 on: 23 Mar 2005, 00:12:07 »
Ok, I have a trigger which covers everything, when fired it calls "hunter.sqs".
Here's hunter.sqs,

me1 addeventhandler ["fired", {me1 exec "hunterkiller.sqs"}]

Here's the hunterkiller.sqs,

;Based on Baron Hurlothrumbo IIX's Hunterkiller Script.
;Edited by The-Architect.

#Begin
? _weapon = "NOR_BTR60_KPVT" : goto "Busted"
? _weapon = "NOR_BTR60_PKT" : goto "Busted"
? _weapon = "AK47" : goto "Busted"
? _weapon = "HK" : goto "Busted"
? _weapon = "SJB_TOS_M4" : goto "Busted"
? _weapon = "SJB_TOS_M4_M203" : goto "Busted"
? _weapon = "SJB_TOS_M249" : goto "Busted"
? _weapon = "SJB_TOS_M60E3" : goto "Busted"
? _weapon = "SJB_TOS_MK43" : goto "Busted"
? _weapon = "SJB_TOS_MK43_E4flash_hider" : goto "Busted"
? _weapon = "SJB_TOS_M21" : goto "Busted"
? _weapon = "SJB_TOS_M24" : goto "Busted"
? _weapon = "ak47cz" : goto "Busted"
? _weapon = "pk" : goto "Busted"
? _weapon = "kozlice" : goto "Busted"
? _weapon = "rpglauncher" : goto "Busted"



#Busted
me1 RemoveAllEventhandlers "fired"
~5
hintcadet "You have been detected."
ainf SetCombatmode "RED"
ainf SetBehaviour "COMBAT"
ainf SetSpeedMode "FULL"


#loop
"_x domove (getpos me1)" foreach units ainf
"_x doTarget me1" foreach units ainf
~60

;waits 60 seconds before updating- change time if you want but bear
;in mind if it updates too fast AI will be swamped with move commands

?alive me1: goto "loop"
;checks if the target is alive, if so goes looking for him, if not exits script.


#Exit
hint "not the right one"
exit

I don't know if you can make it out from that but what I want is the script to ignore silenced shots and to send ainf if a non silenced weapon is fired. That's why I listed all the loud weapons that appear in my mission.

As you can see I'm not too good at this and any help would be greatly appreciated.
« Last Edit: 23 Mar 2005, 00:13:28 by The-Architect »
James Andrew Wilkinson 1977 - 2005 R.I.P.
"If it ain't the friggin' incoming it's the friggin' outgoing. Only difference is who gets the friggin' grease, and that ain't no friggin' difference at all."

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Fired eventhandler again.
« Reply #2 on: 23 Mar 2005, 00:23:48 »
I see you have an HK in that list.........isn't it a silenced weapon?

Where about have you defined the variable _weapon?



Planck
« Last Edit: 23 Mar 2005, 00:33:58 by Planck »
I know a little about a lot, and a lot about a little.

barry_the_baldy

  • Guest
Re:Fired eventhandler again.
« Reply #3 on: 23 Mar 2005, 00:37:23 »
Is the TRIGGER set to Repeat?

Offline The-Architect

  • Former Staff
  • ****
  • Bite my shiny metal...
    • Bob's Un-official Flashpoint Page
Re:Fired eventhandler again.
« Reply #4 on: 23 Mar 2005, 04:45:30 »
Yep, I just noticed the HK. Will fix that.

I don't understand the bit about he variable _weapon.  :-[

Yep, I tried setting the trigger to repeat.

Gawd 'elp me. :-\
« Last Edit: 23 Mar 2005, 04:45:59 by The-Architect »
James Andrew Wilkinson 1977 - 2005 R.I.P.
"If it ain't the friggin' incoming it's the friggin' outgoing. Only difference is who gets the friggin' grease, and that ain't no friggin' difference at all."

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Fired eventhandler again.
« Reply #5 on: 23 Mar 2005, 08:12:55 »
Try putting _weapon = _this select 1 before those ? _weapon == blah blah checks...

The reason why the script is run completely everytime is that you don't have the variable _weapon defined anywhere so the script gets executed to the end...

Why it will not 'register' the second shot is because of this:
Code: [Select]
me1 RemoveAllEventhandlers "fired"This removes the eventhandler from the unit...
So the script will not be executed after the first shot as there is no eventHandler to do that...

Then, if you want the script to ignore silenced weapons you just put
? _weapon = "theSilencedWeaponsName": exit
among the other ? _weapon checks...

Of course do that to all the silenced weapons that might be used in the mission...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline The-Architect

  • Former Staff
  • ****
  • Bite my shiny metal...
    • Bob's Un-official Flashpoint Page
Re:Fired eventhandler again.
« Reply #6 on: 23 Mar 2005, 15:01:53 »
The problem is, when I use the eventhandler, every time I fire it calls the script. If I'm firing on fully automatic it'll call the script loads of times.

I still don't get the whole _weapon = _this stuff. Bear with me, I'm a dumbass when it comes to this stuff.
James Andrew Wilkinson 1977 - 2005 R.I.P.
"If it ain't the friggin' incoming it's the friggin' outgoing. Only difference is who gets the friggin' grease, and that ain't no friggin' difference at all."

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Fired eventhandler again.
« Reply #7 on: 23 Mar 2005, 15:47:50 »
If you want to check for an equality you need == not =.  The latter is used to assign values not check on values.

Why not use something like:

_noisyWeaponsInMission = ["NOR_BTR60_KPVT","NOR_BTR60_PKT" ,"AK47" ...]


if (_weapon in _noisyWeaponsInMission)  then {goto"Busted"}
exit

#Busted
....

Having previously initialised _weapon as described above by HateR_Kint

EDIT:

Do you really have to use:

"_x domove (getpos me1)" foreach units ainf

It feels like cheating to me.

EDIT:

Also note the
exit
immediately before
#Busted
That is something else your script is missing
« Last Edit: 25 Mar 2005, 08:01:14 by THobson »

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:Fired eventhandler again.
« Reply #8 on: 23 Mar 2005, 21:55:18 »
just to help you out here on the understanding bit



to execute a script, we use lines like

[] exec "scriptname.sqs"
this exec "scriptname.sqs"
[alpha, 3, 5] exec "scriptname.sqs"

basically an array is used to execute a script

[] = empty array
[alpha,3,5] = 3 elements in an array
this = (normally a unit) = a single element array

this first element in an array is seen as being in position 0

a fired event handler that executes a script is actually made up of a 5 element array

element 0 (referred to as _this select 0)
element 1 (referred to as _this select 1)
element 2 (referred to as _this select 2)
element 3 (referred to as _this select 3)
element 4 (referred to as _this select 4)

_this refers to the fired eventhandler array

FOR REFERENCE
The comref entry for fired eventhandlers is incorrect
here's what it actually returns

;;__________ fired eventhandler returns________
_Unit = _this select 0
_weapon = _this select 1
_muzzle = _this select 2
_mode = _this select 3
_ammo = _this select 4

[Unit, Weapon, Muzzle, Mode, Ammo] exec "myfiredeventhandlerscript.sqs"

Muzzle examples are:
M16muzzle
M16grenadelauncher

Mode examples are:
Auto
Single
Burst
-------------------------------------------------------------------------------------

hope that clarifies it a bit for ya


one thing to note, the variable name returned for _ammo, is the actual round fired, this is not always the same as the magazine name
« Last Edit: 27 Mar 2005, 23:00:28 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline Blanco

  • Former Staff
  • ****
Re:Fired eventhandler again.
« Reply #9 on: 25 Mar 2005, 05:13:20 »
Quote
Do you really have to use:

"_x domove (getpos me1)" foreach units ainf

It feels like cheating to me

True, when you hide in the bushes for a while, the ainf guys will stand on top of your head :)

Use something like this

Code: [Select]

#loop
_rad = 100
_newposx = getpos me1 select 0
_newposy = getpos me1 select 0
#newpos
   _newposx = (_mx + Random (2 * _rad) - _rad)
   _newposy = (_my + Random (2 * _rad) - _rad)

"_x domove [_newposx,_newposy]" foreach units ainf
~60
?alive me1 : goto "loop"

and Here you can find the best Eventhandler tutorial around. :)
« Last Edit: 25 Mar 2005, 05:19:32 by Blanco »
Search or search or search before you ask.

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Fired eventhandler again.
« Reply #10 on: 26 Mar 2005, 02:58:37 »
I suggest you completely get rid of the detction routine in the script, and use the eventhandler instead ;)

eg.

unit addEventHandler ["FIRED",{if ("_this select 1 == _x" count ["GlockS","Bizon","HK","Uzi"] == 0) then {[] exec "Detected.sqs"}}]

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:Fired eventhandler again.
« Reply #11 on: 28 Mar 2005, 15:36:58 »
Sui, i am not very good with if - then statements.


Quote
unit addEventHandler ["FIRED",{if ("_this select 1 == _x" count ["GlockS","Bizon","HK","Uzi"] == 0) then {[] exec "Detected.sqs"}}]

If the fired event handler was to trigger only when the unit fired his primary weapon, how would your line look then ??
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123