Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Make Event handlers Global ( Killed )

Hybrid View

  1. #1
    Sergeant Major SNKMAN's Avatar
    Join Date
    Aug 29 2006
    Location
    Germany ( Lake Constance )
    Posts
    1,616
    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">

    ? &#40;isServer&#41; &#58; exit

    _explosions = &#91;1,2,3,5&#93;
    _fire = &#91;1,2,3,5&#93;

    #Start

    ; Create Global variable
    GL2Plus_Spawn_Script = -1

    ; Wait till GL2Plus_Spawn_Script is not -1
    @GL2Plus_Spawn_Script &#33;= -1

    ; ########### DEBUG =&#92;SNKMAN/= ###########
    ;hint format&#91;&#34;DEBUG&#58; Spawn # &#58; %1&#92;nDEBUG&#58; Spawn Object&#58; %2&#34;,GL2Plus_Spawn_Script,GL2Plus_Spawn_Script_ Object&#93;
    ; ########################################

    ; Check if GL2Plus_SmokeEffect are enabled, if yes run script with GL2Plus_Spawn_Script_Object
    ? &#40;GL2Plus_SmokeEffect && GL2Plus_Spawn_Script in _explosions&#41; &#58; &#91;GL2Plus_Spawn_Script_Object&#93; exec &#34;GL2Plus&#92;GL2Plus_Effects&#92;Explosion&#92 ;Init.sqs&#34;

    ; Check if GL2Plus_SmokeEffect are enabled, if yes run script with GL2Plus_Spawn_Script_Object
    ? &#40;GL2Plus_FireEffect && GL2Plus_Spawn_Script in _fire&#41; &#58; &#91;GL2Plus_Spawn_Script_Object&#93; exec &#34;GL2Plus&#92;GL2Plus_Effects&#92;Fire&#92;Fire .sqs&#34;

    ; Check if GL2Plus_SmokeEffect are enabled, if yes run script with GL2Plus_Spawn_Script_Object
    ? &#40;GL2Plus_FireEffect && GL2Plus_Spawn_Script in _fire&#41; &#58; &#91;GL2Plus_Spawn_Script_Object&#93; exec &#34;GL2Plus&#92;GL2Plus_Effects&#92;Fire&#92;Fire _Damage.sqs&#34;

    ; Do it all over
    goto &#34;Start&#34;[/QUOTE]

    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 &#34;Killed&#34;
    if &#40;GL2Plus_SpecialFX&#41; then {{_x AddEventHandler &#91;&#34;Killed&#34;, {

    if &#40;GL2Plus_SmokeEffect && &#40;_this select 0&#41; isKindOf &#34;LandVehicle&#34;&#41; then {_this exec &#34;GL2Plus&#92;GL2Plus_Effects&#92;Explosion&#92 ;Init.sqs&#34;; GL2Plus_Spawn_Script_Object = &#40;_this select 0&#41;; publicvariable &#34;GL2Plus_Spawn_Script_Object&#34;; GL2Plus_Spawn_Script = 1; publicvariable &#34;GL2Plus_Spawn_Script&#34;};

    if &#40;GL2Plus_FireEffect && &#40;_this select 0&#41; isKindOf &#34;LandVehicle&#34;&#41; then {_this exec &#34;GL2Plus&#92;GL2Plus_Effects&#92;Fire&#92;Fire .sqs&#34;; GL2Plus_Spawn_Script_Object = &#40;_this select 0&#41;; publicvariable &#34;GL2Plus_Spawn_Script_Object&#34;; GL2Plus_Spawn_Script + 2; publicvariable &#34;GL2Plus_Spawn_Script&#34;};

    if &#40;GL2Plus_FireEffect && &#40;_this select 0&#41; isKindOf &#34;Man&#34;&#41; then {_this exec &#34;GL2Plus&#92;GL2Plus_Effects&#92;Fire&#92;Fire _Damage.sqs&#34;; GL2Plus_Spawn_Script_Object = &#40;_this select 0&#41;; publicvariable &#34;GL2Plus_Spawn_Script_Object&#34;; GL2Plus_Spawn_Script + 3; publicvariable &#34;GL2Plus_Spawn_Script&#34;}}&#93;}

    } forEach vehicles;
    [/QUOTE]

    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&#39;m the server but i doesn&#39;t work on a Dedicated server.

    May someone of you know why or has a other way how to do this.




  2. #2
    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




  3. #3
    Sergeant Major SNKMAN's Avatar
    Join Date
    Aug 29 2006
    Location
    Germany ( Lake Constance )
    Posts
    1,616
    Author of the Thread
    Sorry i don#t really understand, what are you talking about?

    Quote Originally Posted by [b
    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




  4. #4
    Master Gunnery Sergeant norrin's Avatar
    Join Date
    Aug 30 2006
    Location
    Melbourne, Australia
    Posts
    1,123
    Its the locality again m8. ***I think this is what&#39;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&#39;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




    **[XDF]*****************************[AAW]**

  5. #5
    Sergeant Major SNKMAN's Avatar
    Join Date
    Aug 29 2006
    Location
    Germany ( Lake Constance )
    Posts
    1,616
    Author of the Thread
    Damn it norrin&#33;&#33;&#33;&#33;

    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&#33;&#33;&#33;&#33;

    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 &#34;Killed&#34;
    _InitString = &#34;this AddEventHandler &#91;&#34;&#34;Killed&#34;&#34;, {


    if &#40;GL2Plus_SmokeEffect && &#40;_this select 0&#41; isKindOf &#34;&#34;LandVehicle&#34;&#34;&#41; then {_this exec &#34;&#34;GL2Plus&#92;GL2Plus_Effects&#92;Explosio n&#92;Init.sqs&#34;&#34;};

    if &#40;GL2Plus_FireEffect && &#40;_this select 0&#41; isKindOf &#34;&#34;LandVehicle&#34;&#34;&#41; then {_this exec &#34;&#34;GL2Plus&#92;GL2Plus_Effects&#92;Fire&#92 ;Fire.sqs&#34;&#34;};

    if &#40;GL2Plus_FireEffect && &#40;_this select 0&#41; isKindOf &#34;&#34;LandVehicle&#34;&#34;&#41; then {_this exec &#34;&#34;GL2Plus&#92;GL2Plus_Effects&#92;Fire&#92 ;Fire_Damage.sqs&#34;&#34;};

    }&#93;&#34;;

    {_x SetVehicleInit _InitString} foreach vehicles;

    processInitCommands;[/QUOTE]

    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&#33;&#33;




  6. #6
    Quote Originally Posted by [b
    Quote[/b] ]Well i get no errors but it seems like the effect scripts are not triggered correctly
    SNKMAN, It&#39;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 = &#34;this AddEventHandler &#91;&#34;&#34;Killed&#34;&#34;,{_This ExecVM &#34;&#34;AddKilledEvent.sqs&#34;&#34;}&#93;&#5 9; Hint &#34;&#34;Killed Event added&#34;&#34;&#93;;&#34;;
    *** *** *** ***
    *** *** *** ***&#40;vehicles Select 0&#41; SetVehicleInit _InitString;

    *** *** *** ***processInitCommands;
    *** *** *** ***};[/QUOTE]

    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 &#91;&#34;Server&#58; Effect %1 Kindof %2&#34;,GL2Plus_SmokeEffect,_Vehicle IsKindOf &#34;LandVehicle&#34;&#93;;

    *** *** *** ***PublicVariable &#34;SERVERSIDE&#34;;
    *** *** *** ***}
    *** *** *** ***Else
    *** *** *** ***{
    *** *** *** ***LOCALCLIENT=Format &#91;&#34;Local&#58; Effect %1 IsKindof %2&#34;,GL2Plus_SmokeEffect,_Vehicle IsKindOf &#34;LandVehicle&#34;&#93;;
    *** *** *** ***};
    [/QUOTE]

    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&#39;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.

  7. #7
    Sergeant Major SNKMAN's Avatar
    Join Date
    Aug 29 2006
    Location
    Germany ( Lake Constance )
    Posts
    1,616
    Author of the Thread
    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 &#40;isServer&#41; then {{&#91;_x&#93; execVM &#34;GL2Plus&#92;GL2Plus_Event&#92;Server.sqf&#34; }} forEach _groups

    ; Check if this is the server &#40;host&#41;, if not then exit
    ? &#33;&#40;isServer&#41; &#58; exit[/QUOTE]

    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 &#40;host&#41;, if not then exit
    ? &#33;&#40;isServer&#41; &#58; exit

    if &#40;isServer&#41; then {{&#91;_x&#93; execVM &#34;GL2Plus&#92;GL2Plus_Event&#92;Server.sqf&#34; }} forEach _groups
    [/QUOTE]

    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&#39;s for all your help.




  8. #8
    In theory those two bits of code you posted do the same thing. Although I&#39;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 &#40;isServer&#41; then {{&#91;_x&#93; execVM &#34;GL2Plus&#92;GL2Plus_Event&#92;Server.sqf&#34; }} forEach _groups[/QUOTE]

    Should be:

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if &#40;isServer&#41; then {{&#91;_x&#93; execVM &#34;GL2Plus&#92;GL2Plus_Event&#92;Server.sqf&#34; } forEach _groups}[/QUOTE]

    But anyway, glad to here it&#39;s working the way you wanted.

  9. #9
    Sergeant Major SNKMAN's Avatar
    Join Date
    Aug 29 2006
    Location
    Germany ( Lake Constance )
    Posts
    1,616
    Author of the Thread
    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.




  10. #10
    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 &#40;_x&#62;0&#41; Then {_Total=_Total+_x}&#59; Hint Format &#91;&#34;Total %1&#34;,_Total&#93;} ForEach &#91;1,2,3,-1,5&#93;;
    [/QUOTE]

    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 &#40;_x&#62;0&#41; Then {_Total=_Total+_x} ForEach &#91;1,2,3,-1,5&#93;&#59; Hint Format &#91;&#34;Total %1&#34;,_Total&#93;};
    [/QUOTE]

    It&#39;s not like it&#39;s going to cause a major problem, but easy to avoid in the future.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •