Jump to content
Sign in to follow this  
nullsystems

AI eventhandler problem

Recommended Posts

Hi all,

Havin a problem with a unit respawn script.

Ive placed the event handler in a unit :

this addeventhandler ["killed", {[me1,place1] exec "respawnDead.sqs"}];"

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? not local server : exit;

_unit = _this select 0;

_spawn = _this select 1;

_grp = group _unit;

~2

HideBody _unit;

~2

deleteVehicle _unit;

"ack_dpd_4" createUnit [_spawn, _grp,"_unit = this",0.6, "corporal"];

_unit setVehicleInit "_unit addeventhandler [""killed"", {[_unit,_spawn] exec ""respawnDead.sqs""}];"

processInitcommands

exit;

Now the code respawns the unit, but only once. Never again.

I know the new unit is called the same name, but why isnt the event handler working?

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_unit setVehicleInit "this addeventhandler [""killed"", {[_this select 0,_spawn] exec ""respawnDead.sqs""}];"

First of all, you have to use this instead of _unit in setVehicleInit.

Second thing is, you can't use private variables in an eventhandler.

Cheers

Xeno

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

temp=str _spawn;

publicvariable "temp";

_unit setVehicleInit "this addeventhandler [""killed"", {[this,call (compile temp)] exec ""respawnDead.sqs""}];"

Share this post


Link to post
Share on other sites

Interesting, I can understand why the str was required there.

But im afraid, still only spawns one, then stops.

Share this post


Link to post
Share on other sites

it because you again use private var in initialization "_unit = this" tounge2.gif

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? not local server : exit;

_unit = _this select 0;

_spawn = _this select 1;

_grp = group _unit;

~2

HideBody _unit;

~2

deleteVehicle _unit;

_unit = _grp createUnit ["ack_dpd_4", _spawn, [], 0, "NONE"];

_unit setRank "corporal";

_unit setskill 0.6;

temp=str _spawn;

publicvariable "temp";

_unit setVehicleInit "this addeventhandler [""killed"", {[this,call (compile temp)] exec ""respawnDead.sqs""}];"

processInitcommands;

exit;

Share this post


Link to post
Share on other sites

Hmm, I dont understand why you made the difference.

I tried it but nothing spawned at all.

Share this post


Link to post
Share on other sites

Well, I played around and got this far:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

? not local server : exit;

AIDead = _this select 0;

spawn = _this select 1;

grp = group AIDead;

~2

HideBody AIDead;

~2

deleteVehicle AIDead;

"ack_dpd_4" createUnit [ spawn, grp, "this addeventhandler [""killed"", {[AIDead,spawn] exec

""Police\respawnDead.sqs""}];AIDead = this;", 0.5, "corporal"]

exit;

This respawns people, perfectly. UNTIL you kill more than one before the last person respawns. This then halts and only respawns that one AI each time you kill him, not the others. Annoyin really. lol

Share this post


Link to post
Share on other sites

Ive decided to give up on the ONE script version and use a script for each AI that I need to respawn. Nevermind lol.

Well thanks for your help eveyone, much appreciated !

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  

×