Home   Help Search Login Register  

Author Topic: adding/removing multiple event handlers...  (Read 582 times)

0 Members and 1 Guest are viewing this topic.

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
adding/removing multiple event handlers...
« on: 01 Jun 2005, 21:43:38 »
m'kay - scenario: i'm adding various event handlers to all the loons in the player's group, and i'm wondering how to reference them properly.

there may also be different numbers of troops in the player's group, so i'd rather use an array or somesuch thing, but i've no idea if that can be used in combination with EHs.

to give an example, i have a 'hit' EH which triggers a kevlar script. the action for this can be toggled, like putting on/taking off the vest -

Code: [Select]
;bodyarmour action

?k_arm:goto "check"
k_arm = true

hint "Bodyarmour:\nEngaged!"

kevlar = player addeventhandler ["hit",{_this exec "boing.sqs"}]
exit


#check

k_arm = false

hint "Bodyarmour:\nDisengaged!"

player removeEventHandler ["hit",kevlar]
exit

so the event handler for the player is easy enough to reference, by the variable 'kevlar'. but what if i have a squadful of them? do i use a format command along with an incremented array? can i use the 'kevlar' reference for all of the loons? is there an easier way?

thanks in advance ;)

EDIT - i'll tack this question on at the end, as it's directly related, but how does one instruct an AI loon to perform a user-added action?

Code: [Select]
loon_name action ["action_name"]

doesn't work...  :-\
« Last Edit: 01 Jun 2005, 22:17:45 by bedges »

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:adding/removing multiple event handlers...
« Reply #1 on: 01 Jun 2005, 22:35:47 »
???
execute the script with unitname exec "bodyarmor.sqs"...
Quote
;bodyarmour action

?k_arm:goto "check"
k_arm = true

hint "Bodyarmour:\nEngaged!"

_kevlar = _this addeventhandler ["hit",{_this exec "boing.sqs"}]
exit


#check

k_arm = false

hint "Bodyarmour:\nDisengaged!"

_this removeEventHandler ["hit",_kevlar]
exit
Now it should be local to each unit...
If I'm missing something, blame it on sleep deprivation.. ::)

Quote
i'll tack this question on at the end, as it's directly related, but how does one instruct an AI loon to perform a user-added action?
By adding the player an action or something which when activated will make the AI to perform the action, or something like that...
The function action can't be used in this situ...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:adding/removing multiple event handlers...
« Reply #2 on: 02 Jun 2005, 09:49:01 »
yep - i used the kevlar variable for all of them, and it works fine. but not being able to call their actions from a script... fuducker.

ah well. win some lose some - thanks for the input :)

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re:adding/removing multiple event handlers...
« Reply #3 on: 02 Jun 2005, 17:56:30 »
I think the only reason why the _kevlar works for all loons is that event handlers are numbered sequentially for each loon i.e. for each loon the first eventhandler added has a handle numbered 0.  Since _kevlar is private to the script I don't see how it can be used when re-entering the script.  Aren't local variables destroyed upon exiting a script?

Does loon Action idAction work?

« Last Edit: 07 Jun 2005, 14:00:57 by Mr.Peanut »
urp!