shuko 59 Posted March 27, 2007 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. Share this post Link to post Share on other sites
sickboy 13 Posted March 27, 2007 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. 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
shuko 59 Posted March 27, 2007 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. Share this post Link to post Share on other sites
sickboy 13 Posted March 27, 2007 Then I misunderstood the question 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 Share this post Link to post Share on other sites
shuko 59 Posted March 27, 2007 I tried it with those as well, so, please show me how you get it to work. Share this post Link to post Share on other sites
sickboy 13 Posted March 27, 2007 I tried it with those as well, so, please show me how you get it to work. 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