Jump to content
Sign in to follow this  
shuko

Something for the pro scripters in here

Recommended Posts

How to add an eventhandler globally for a unit that is spawned (createunit or createvehicle, whichever you prefer)?

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

_init = format ["this addeventhandler [""killed"",{[_this,%1] call addKill}]; this addeventhandler [""hit"",{[_this,%1] call addHit}]; t%1 = this; removeallweapons this; this allowfleeing 0; this setunitpos ""%2""; this setcaptive true;",_i,_pos];

"SoldierEB" createUnit [getpos spawnpoint, grpSpawn, _init];

Works nicely in preview, but not in dedi, so Im guessing its only adding the handlers for the server.

Any ideas for a workaround? Down side is, it needs to be added quite fast at/after creation. sad_o.gif

Share this post


Link to post
Share on other sites
How to add an eventhandler globally for a unit that is spawned (createunit or createvehicle, whichever you prefer)?

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

_init = format ["this addeventhandler [""killed"",{[_this,%1] call addKill}]; this addeventhandler [""hit"",{[_this,%1] call addHit}]; t%1 = this; removeallweapons this; this allowfleeing 0; this setunitpos ""%2""; this setcaptive true;",_i,_pos];

"SoldierEB" createUnit [getpos spawnpoint, grpSpawn, _init];

Works nicely in preview, but not in dedi, so Im guessing its only adding the handlers for the server.

Any ideas for a workaround? Down side is, it needs to be added quite fast at/after creation. sad_o.gif

Init eventhandlers are globally executed, Hit and Killed eventhandlers are only executed on the machine where the unit is local and not on all other machines.

Adding the KilledEH and HitEH in the init at createvehicle, might (not sure) execute the addeventhandler on all machines, but will still only fire the KilledEH and HitEH on the machine where the unit is local to. AFAIK if you want things happening globally, on a KilledEH or HitEH you will have to make use of a PublicVariable system, Network Services System or for instance use createvehicle to create a logic and make the init line execute something (which will be done globally). Then delete the logic again

Share this post


Link to post
Share on other sites

I know they are fired locally, that suits me just fine.

Quote[/b] ]Adding the KilledEH and HitEH in the init at createvehicle, might (not sure) execute the addeventhandler on all machines, but will still only fire the KilledEH and HitEH on the machine where the unit is local to.

Thats the problem, it doesnt seem to be adding the eventhandler on the unit on clients, just on the server. Why would you have a global command that creates a unit on all clients, but wont add stuff in init to them. sad_o.gif

Share this post


Link to post
Share on other sites

Then I misunderstood the question smile_o.gif

You should be able to resolve it by using setvehicleinit and use processInitCommands (on the server, after you have done all ur setvehicleinits). For reference check biki smile_o.gif

Share this post


Link to post
Share on other sites

I tried it with those as well, so, please show me how you get it to work. wink_o.gif

Share this post


Link to post
Share on other sites
I tried it with those as well, so, please show me how you get it to work. wink_o.gif

Could you send me your Mission or whatever you use to test? sb_at_6thsense.eu

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  

×