OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: bedges on 01 Jun 2005, 21:43:38

Title: adding/removing multiple event handlers...
Post by: bedges 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...  :-\
Title: Re:adding/removing multiple event handlers...
Post by: h- 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...
Title: Re:adding/removing multiple event handlers...
Post by: bedges 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 :)
Title: Re:adding/removing multiple event handlers...
Post by: Mr.Peanut 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?