Jump to content
Sign in to follow this  
CapMorganCD

Addeventhandler @ respawned units

Recommended Posts

Hi all, here's a small problem:

I can't add handlers to a respawned unit. Not by script or trigger.

Here's what i have. Works fine first time, but when unit respwns no handler is added. Any hook?

init.sqs

ArrayGlobal = units grpEste + units grpOeste

eventos = true

trigger:

condition: Eventos

on activation:"""_X removeAllEventHandlers {killed}"" foreach ArrayGlobal; ""_x addeventhandler [{killed}, {_this exec {Camper.sqs}}]"" forEach ArrayGlobal; eventos = false;publicVariable ""eventos"""

;script Camper.sqs

_muerto = _this select 0

_matador = _this select 1

? _muerto in units grpOeste && _matador in units grpOeste: goto "fin"

? _muerto in units grpEste && _matador in units grpEste: goto "fin"

_linea = "Dont kill in respawn"

? _muerto in units grpOeste && _muerto in list listaRespOeste: _matador setdammage 1; hint _linea; goto "fin"

? _muerto in units grpEste && _muerto in list listaRespEste: _matador setdammage 1; hint _linea; goto "fin"

#fin

Eventos = true

Publicvariable "eventos"

exit

Share this post


Link to post
Share on other sites

Well, if you want to keep the EHs on the local unit, here's how:

;loadeh.sqs

@alive player

@side player != "CIV"

;I didn't control for correct syntax of the side command. sorry

#LoadEh

player addeventhandler ["type", {action}]

player addeventhandler ["killed", {[] exec "loadeh.sqs"}]

exit

Share this post


Link to post
Share on other sites

well, i tried dinger's solution, but i can't use "player" because of the bots.

I just don't undertand why the trigger add the events to all the units the first time its activated but not the second.

Any other sugestion?

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (DV Chris Death @ Dec. 30 2002,13:16)</td></tr><tr><td id="QUOTE">I think what uiox means is, don't use: not alive xxx,

rather use: alive xxx

~S~ CD<span id='postcolor'>

That's the first thing i tried, and it worked, but i cant add a trigger for each unit i have on the map. There must be a better way.

Share this post


Link to post
Share on other sites

Could it be that the newly "respawned" Players are not in ArrayGlobal?

Whenever they are spawned you would have to perform ArrayGLobal= ArrayGlobal + [spawned unit];

Share this post


Link to post
Share on other sites

Or do a try with the event "init", if this event is call when a unit respawn you can add kill event.

If it's the case you can give guns & ammos easily in MP, may be someone has test "init"...

Share this post


Link to post
Share on other sites

You would need the object in the first place to attach an "init" to it though.  Hey, yeah that's wierd.  If the object exists in the first place, how would attaching an "init" to it be any good, since it should have already initialized??

Share this post


Link to post
Share on other sites

You were absolutely wright.

A very BIG THANK YOU bn880.

Here's what finally worked, just in case someone needs it (not tested in MP yet, but i think there should be no problem)

Thanx a gain to all the replys.

-------------

init.sqs

eventos = true

-------------

trigger:

rad: 5000

activation:anybody/present

condition: Eventos

delay: 2 more seconds than the respawn delay in the description.ext

on activation:"""_X removeAllEventHandlers {killed}"" foreach thislist; ""_x addeventhandler [{killed}, {_this exec {Camper.sqs}}]"" forEach thislist; eventos = false;publicVariable ""eventos"""

-------------

;script Camper.sqs

_muerto = _this select 0

_matador = _this select 1

? _muerto in units grpOeste && _matador in units grpOeste: goto "fin"

? _muerto in units grpEste && _matador in units grpEste: goto "fin"

_linea = "Dont kill in respawn"

? _muerto in units grpOeste && _muerto in list listaRespOeste: _matador setdammage 1; hint _linea; goto "fin"

? _muerto in units grpEste && _muerto in list listaRespEste: _matador setdammage 1; hint _linea; goto "fin"

#fin

Eventos = true

Publicvariable "eventos"

exit

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×