snkman 351 Posted August 3, 2007 Hey guy's, i'm trying to make an Event handler "Killed" Global, so everyone on a Dedicated server will see whats happend, if a object was killed and the Event handler was triggered. So far i made a hundreds of tests using the ECP way: Create a file "Load.sqs" which is executed in the init.sqs of the mission Load.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> ? (isServer) : exit _explosions = [1,2,3,5] _fire = [1,2,3,5] #Start ; Create Global variable GL2Plus_Spawn_Script = -1 ; Wait till GL2Plus_Spawn_Script is not -1 @GL2Plus_Spawn_Script != -1 ; ########### DEBUG =\SNKMAN/= ########### ;hint format["DEBUG: Spawn # : %1\nDEBUG: Spawn Object: %2",GL2Plus_Spawn_Script,GL2Plus_Spawn_Script_Object] ; ######################################## ; Check if GL2Plus_SmokeEffect are enabled, if yes run script with GL2Plus_Spawn_Script_Object ? (GL2Plus_SmokeEffect && GL2Plus_Spawn_Script in _explosions) : [GL2Plus_Spawn_Script_Object] exec "GL2Plus\GL2Plus_Effects\Explosion\Init.sqs" ; Check if GL2Plus_SmokeEffect are enabled, if yes run script with GL2Plus_Spawn_Script_Object ? (GL2Plus_FireEffect && GL2Plus_Spawn_Script in _fire) : [GL2Plus_Spawn_Script_Object] exec "GL2Plus\GL2Plus_Effects\Fire\Fire.sqs" ; Check if GL2Plus_SmokeEffect are enabled, if yes run script with GL2Plus_Spawn_Script_Object ? (GL2Plus_FireEffect && GL2Plus_Spawn_Script in _fire) : [GL2Plus_Spawn_Script_Object] exec "GL2Plus\GL2Plus_Effects\Fire\Fire_Damage.sqs" ; Do it all over goto "Start" Then in a script i add the Event handler "Killed" to each vehicle: EventHandler.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> // Check if FX should be used, if yes add EventHandler "Killed" if (GL2Plus_SpecialFX) then {{_x AddEventHandler ["Killed", { if (GL2Plus_SmokeEffect && (_this select 0) isKindOf "LandVehicle") then {_this exec "GL2Plus\GL2Plus_Effects\Explosion\Init.sqs"; GL2Plus_Spawn_Script_Object = (_this select 0); publicvariable "GL2Plus_Spawn_Script_Object"; GL2Plus_Spawn_Script = 1; publicvariable "GL2Plus_Spawn_Script"}; if (GL2Plus_FireEffect && (_this select 0) isKindOf "LandVehicle") then {_this exec "GL2Plus\GL2Plus_Effects\Fire\Fire.sqs"; GL2Plus_Spawn_Script_Object = (_this select 0); publicvariable "GL2Plus_Spawn_Script_Object"; GL2Plus_Spawn_Script + 2; publicvariable "GL2Plus_Spawn_Script"}; if (GL2Plus_FireEffect && (_this select 0) isKindOf "Man") then {_this exec "GL2Plus\GL2Plus_Effects\Fire\Fire_Damage.sqs"; GL2Plus_Spawn_Script_Object = (_this select 0); publicvariable "GL2Plus_Spawn_Script_Object"; GL2Plus_Spawn_Script + 3; publicvariable "GL2Plus_Spawn_Script"}}]} } forEach vehicles; Now after an Event handler was triggered ( A vehicle was destroyed ) the Event handler will public the object (_this select 0), which was destroyed and the lock (GL2Plus_Spawn_Script) to run the "Load.sqs" Then in "Load.sqs" the brodcasted object will run the script. Well basically this should work, it do on a local hosted server, where i'm the server but i doesn't work on a Dedicated server. May someone of you know why or has a other way how to do this. Share this post Link to post Share on other sites
SouthSaturnDelta 1 Posted August 3, 2007 Making Napalm eh Sninkman? Not 100 % sure of a solution along these lines,but there are other ways that work. How are your P.S. effects coming along? SSD Share this post Link to post Share on other sites
snkman 351 Posted August 3, 2007 Sorry i don#t really understand, what are you talking about? Quote[/b] ]Making Napalm eh Sninkman? Napalm Event handler? And what does P.S. means? Well if you know some other ways plz let me know SouthSaturnDelta Share this post Link to post Share on other sites
norrin 9 Posted August 4, 2007 Its the locality again m8. Â I think this is what's happening. Â If the vehicles are empty or filled with non-playable AI when the event handler is added then the vehicles are local to the dedicated server and the eventhandler is only added there (ie. to the dedi) and therefore is not added or recognised by the clients machines. If the vehicles are driven by a player then the vehicle is local to the driver's client and this time the event handler is only added to that clients instance of ArmA. Â Some guys (UNN and the other posters in the first thread) have got around the locality of eventhandlers though by creating an init variable that contains the vehicles name, eventhandler etc then they use the SetVehicleInit and processInitCommands commands to send this information to all the clients and the dedi. You can read more about this problem and solution in the following 2 threads on the BIS forums: http://www.flashpoint1985.com/cgi-bin....=synide http://www.flashpoint1985.com/cgi-bin....=norrin Share this post Link to post Share on other sites
snkman 351 Posted August 4, 2007 Damn it norrin!!!! Again you are right.... Once again i tested it with the way i descripted above but this time i placed the player of the 2. ArmA instance in the vehicle and it just worked perfect!!!! So now how can i make this work with the way above? There must be something to make it work. Well just tested the stuff UNN made: code: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> // Check if FX should be used, if yes add EventHandler "Killed" _InitString = "this AddEventHandler [""Killed"", { if (GL2Plus_SmokeEffect && (_this select 0) isKindOf ""LandVehicle"") then {_this exec ""GL2Plus\GL2Plus_Effects\Explosion\Init.sqs""}; if (GL2Plus_FireEffect && (_this select 0) isKindOf ""LandVehicle"") then {_this exec ""GL2Plus\GL2Plus_Effects\Fire\Fire.sqs""}; if (GL2Plus_FireEffect && (_this select 0) isKindOf ""LandVehicle"") then {_this exec ""GL2Plus\GL2Plus_Effects\Fire\Fire_Damage.sqs""}; }]"; {_x SetVehicleInit _InitString} foreach vehicles; processInitCommands; Well i get no errors but it seems like the effect scripts are not triggered correctly... And once again in the Edtior it works like a dream but on the dedi it failed completly... I slowly really start hating this!! Share this post Link to post Share on other sites
UNN 0 Posted August 4, 2007 Quote[/b] ]Well i get no errors but it seems like the effect scripts are not triggered correctly SNKMAN, It's better to approach these sort of problems a bit at a time. Try getting this up and running for a single vehicle in a new mission: Create init.sqf with: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">GL2Plus_SmokeEffect=True; If IsServer Then     {     _InitString = "this AddEventHandler [""Killed"",{_This ExecVM ""AddKilledEvent.sqs""}]; Hint ""Killed Event added""];";         (vehicles Select 0) SetVehicleInit _InitString;     processInitCommands;     }; Then start off with AddKilledEvent.sqs as: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Vehicle=_This Select 0; If IsServer Then     {     SERVERSIDE=Format ["Server: Effect %1 Kindof %2",GL2Plus_SmokeEffect,_Vehicle IsKindOf "LandVehicle"];     PublicVariable "SERVERSIDE";     }     Else     {     LOCALCLIENT=Format ["Local: Effect %1 IsKindof %2",GL2Plus_SmokeEffect,_Vehicle IsKindOf "LandVehicle"];     }; Run the mission in MP and display the content of SERVERSIDE and LOCALCLIENT, using hint and a radio trigger after you destroy the vehicle. If both variables return true values, then your ready to add the rest of the code. If you don't see the "Killed Event added" message when your mission starts. Then there is, a problem with your init commands. Still more to take into account with JIP, but you can worry about that later on. Share this post Link to post Share on other sites
snkman 351 Posted August 4, 2007 Hey UNN, thank you very much for the greate tutorital. Well yesterday after my 1000 try i finally could get it to work with my way. Looks like the problem was, that the script was executet, on all clients. Bevore: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> if (isServer) then {{[_x] execVM "GL2Plus\GL2Plus_Event\Server.sqf"}} forEach _groups ; Check if this is the server (host), if not then exit ? !(isServer) : exit Now i simply changed it to: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> ; Check if this is the server (host), if not then exit ? !(isServer) : exit if (isServer) then {{[_x] execVM "GL2Plus\GL2Plus_Event\Server.sqf"}} forEach _groups and everything works fine even on a Dedi I really have no clue why becouse bevore i only allowed the server to run the script. Well anyway it works. I will test your way too, to see whats working best for me. So thank you guy's for all your help. Share this post Link to post Share on other sites
UNN 0 Posted August 4, 2007 In theory those two bits of code you posted do the same thing. Although I'm suprised either of then will work. Perhaps this is why you hit problems: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (isServer) then {{[_x] execVM "GL2Plus\GL2Plus_Event\Server.sqf"}} forEach _groups Should be: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (isServer) then {{[_x] execVM "GL2Plus\GL2Plus_Event\Server.sqf"} forEach _groups} But anyway, glad to here it's working the way you wanted. Share this post Link to post Share on other sites
snkman 351 Posted August 4, 2007 Well UNN i always use this way for "_x forEach" codes. So far i never placed a bracket at the very end of the line. So far i saw a lot of codes and one put the brackets like me and on another part like you. I tested everything and it always works good without the bracket at the end of the line. But hey good to know. May this will slove some other problems, i have with some other scripts. Thanks UNN. Share this post Link to post Share on other sites
UNN 0 Posted August 5, 2007 Yeah, it kind of works. But I think that could be classed as a bug, not a feature? If you want to do anything else within that if condition, once the ForEach loop has finished. You would have to revert to the usual method, otherwise something like this throws up errors: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Total=0; If Player {{If (_x>0) Then {_Total=_Total+_x}; Hint Format ["Total %1",_Total]} ForEach [1,2,3,-1,5]; This way, your ok: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Total=0; If Player {{If (_x>0) Then {_Total=_Total+_x} ForEach [1,2,3,-1,5]; Hint Format ["Total %1",_Total]}; It's not like it's going to cause a major problem, but easy to avoid in the future. Share this post Link to post Share on other sites
snkman 351 Posted August 5, 2007 Well most of my knowledge is based on OFP Group Link II and OFP Mod ECP becouse i used thouse Scripts/Mod's to understand how to script. In OFP GLII i saw KeyCat was doing something like: grouplink2.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> if (GL2Plus_AIhearingaid) then {{[_x] exec "GL2Plus\GL2Plus_Reacted\Advance.sqs"} forEach _groups} and another forEach code in the same grouplink2.sqs script <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> {if ((count units _x) == 0) then {_groups = _groups - [_x]; goto "start"}} foreach _groups So i thougt it's only for the way the code's look better I thought it was something like then and : bouth are working on the same way it's up to you which one you like to use. But okay if you say it should look like this i will rewrite my scripts. Share this post Link to post Share on other sites
UNN 0 Posted August 5, 2007 I see, looks like you found a new feature in the scripts The code you posted: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (isServer) then {{[_x] execVM "GL2Plus\GL2Plus_Event\Server.sqf"}} forEach _groups Is a variation on the two grouplink2 scripts. Both those scripts do two different things. The first executes a foreach loop if GL2Plus_AIhearingaid is equal to true. The second executes a foreach loop that checks each group, to see if it's empty. For your original code, you just need to use the same format as the first method: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (GL2Plus_AIhearingaid) then {{[_x] exec "GL2Plus\GL2Plus_Reacted\Advance.sqs"} forEach _groups} But still, your code does what it's supposed to do. I'm just suprised it worked that way. Share this post Link to post Share on other sites
sickboy 13 Posted August 5, 2007 I must admit I have not read everything too closely, will prolly do tomorrow, but here some of my thoughts.. Below is based on 1.08-only btw, as version before 1.08 had more locality issues due to not properly broadcasting objects in MP. I create a trigger after mission start, catch all vehicles etc in it, and then add eventhandlers, local on every machine. No need to work out with setVehicleInit. The trigger however only catches all objects after mission start. Where do you execute the addEventHandler part? executed from a vehicle's init field or elsewhere? Incase it's executed in the vehicle's init line, then that might simply be the problem. Incase of the init.sqs/sqf, it might help to use a sleep 1; or whatever sleep, as that waits until after the game has launched. Share this post Link to post Share on other sites
UNN 0 Posted August 6, 2007 Quote[/b] ]I create a trigger after mission start, catch all vehicles etc in it, and then add eventhandlers, local on every machine. He's using the Vehicles command, so the list should be available from the start. Share this post Link to post Share on other sites