Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20

Thread: "addPublicVariableEventHandler" for Sahraniville

  1. #11
    Sergeant
    Join Date
    Jan 9 2007
    Location
    Bath, United Kingdom
    Posts
    154
    Author of the Thread
    Cheers, guys, thanks for all the help! SickBoy, I love you - I'll test that out and see how it works!

    Edit:

    Okay, so I'm trying this in Single Player at the moment, but it's not 'hinting' that the fine has happened.. I'll try it in MP as well to see if it works there




  2. #12
    The pros and cons of SetVehicleInit over PublicVariableEvents, how and when to use each of them, really deserves a thread of it's own.

    For now, to avoid taking Somerville's thread to far off topic I will try and keep it relevant to his question.

    Quote Originally Posted by [b
    Quote[/b] ]You could use something like this
    What worries me about your example and what I meant, when I said to Somerville about it getting much more complicated was. If two different clients (Cops) both use PublicVariable to broadcast the fines. Won't that nullify the event handler for future fines on those clients? In that, the event won't fire on the machine that uses PublicVariable, or does this condition reset every time the variable is changed?

    Likewise, what happens if two clients (Cops) both issue fines to two different players at the same time?

    I assumed you should really maintain individually named variables for each of the clients and any new JIP client, on all the clients, to ensure you don't hit this problem? Which is what I meant about getting more complicated.

    Quote Originally Posted by [b
    Quote[/b] ]setVehicleInit should IMO be used for persistent actions, e.g. actions that also must be received by all following join in progress players.
    True, SetVehicleInit was designed for JIP. But I did say it was a basic criteria, every scenario has it's own conditions to take into account. But given my above assumption about individual PublicVariables, SetVehicleInit would provide a simple solution for Somerville. All he would need to add, is a simple condition that exits any script for subsequent JIP players, before performing any actions.

    Quote Originally Posted by [b
    Quote[/b] ]As setVehicleInit's are synced also to JIP players. On top of that, massive amounts of setVehicleInits seem to lag the server and players at join, much more than a single or a few PVEHs
    I've only been able to compare the two on a single client that also runs the dedicated server as a separate task. So I can't test to see how the server responds, as I'm always the client JIP'ing.

    Quote Originally Posted by [b
    Quote[/b] ]Not to mention that PVEH can send any data type, where as you will need helper objects and pv's to get certain data across with setVehicleInit.
    In the case of Somerville requirements, all he needs to send is the target player and the amount of the fine. Well within the scope of setVehicleInit.

  3. #13
    Okay a few facts about PVEH's:[*] When you change a variable on this machine and then publicVariable it, a PVEH hooked to this PV will not fire on this machine (but it will on all the other machines). So history doesn't matter, it simply comes down to "The PVEH will not fire on the machine that updates the variable, and pv's it"[*] To my experience, every single publicVariable action, will be received by other machines PVEH's. Even if you do 100 transactions in a second. Even from multiple machines.[*] By using (_this select 1) inside the PVEH, and not a reference directly to the variable itself, you make sure that you use the value of the variable, as it was at the exact moment of the receive

    I agree very much that it's situation dependent, but whenever something is not persistent, I always use PVEH.
    It has IMO less limitations, better performance, and I rather use 1 system instead of multiple, whenever I can

    Also, by using the wrapper function, in my example: fine_updateFunction, you make sure that the event is triggered also on the sending machine



    A.C.E. Advanced Combat Environment

    Dev-Heaven.net Free Project Hosting | A2 Community Issue Tracker Help BIS, Help yourself!

  4. #14
    Sergeant
    Join Date
    Jan 9 2007
    Location
    Bath, United Kingdom
    Posts
    154
    Author of the Thread
    Okay chappies!

    Just done a quick MP Test and sadly, it doesn't appear to be working. I say this only because it does not hint when the player had paid the fine. Although I'm only testing on AI on our dedicated server, it doesn't work *weeps*

    So, I've got the "finez.sqf" script that I call from my init.sqf, which reads what you have placed above, Sickboy Then, for the "Fine.sqf" which is called when the officer approaches the unit and gives the fine, displays:

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">&#91;_civilian, _officer&#93; call fine_updateFunction;[/QUOTE]

    Am I missing something here? Sorry, it&#39;s probably because it&#39;s early(ish).. I am very much grateful for the help thus far though

  5. #15
    Quote Originally Posted by (Somerville @ July 02 2008,12:36)
    Am I missing something here? Sorry, it&#39;s probably because it&#39;s early(ish).. I am very much grateful for the help thus far though
    What is the contents of _civilian and _officer?
    you could add a debug just where you call the fine_updateFunction like this:
    player globalChat format["Civ: %1 Off: %2", _civilian, _officer];


    Also, you use groupChat: _officer groupchat ["%1 fined.", _civilian];
    This means anyone not in the group of the _officer, will not see the message
    sideChat or globalChat are required to display the message to everyone on the same side or, simply everyone.




  6. #16
    As you are using SPON Core anyway if you are using SPON Money, you could just (Assuming you use SPON Core v0.2.0 or higher):
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
    &#91;&#34;Frog&#34;, { do this code on ALL machines }&#93; call SPON_addEventHandler;

    &#91;&#34;Frog&#34;, &#91;12, 24&#93;&#93; call SPON_publishGlobalEvent;
    [/QUOTE]

    This just wraps the PVEH and runs the code on all machines, including the sender (In older versions, it wrapped around setvehicleInit, so it had all the limitations of that method). Using Sickboy&#39;s general method is possibly better for most people though, since it doesn&#39;t rely on external stuff.
    CBA: Community Base Addons for A2
    DevHeaven: development unraveled!
    SPON scripts/addons (A1) | Roller island tool (OFP -> A1)
    OFPEC: The editing center (for OFP, A1 and A2)

  7. #17
    Sergeant
    Join Date
    Jan 9 2007
    Location
    Bath, United Kingdom
    Posts
    154
    Author of the Thread
    Oh noez.. still doesn&#39;t work - just tried testing with another player, and their money doesn&#39;t get taken away either

    I&#39;ve now got this:

    Finez.sqf
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">fine = &#91;&#93;;

    fine_updateFunction =
    {
    fine = _this;
    publicVariable &#34;fine&#34;; // send fine var over the network
    _this call fine_function; // call the fine function also on this machine, because the pvEH will not trigger on the sending machine by default
    };

    fine_function =
    {
    private &#91;&#34;_civilian&#34;, &#34;_officer&#34;, &#34;_fine&#34;&#93;;
    _civilian = _this select 0;
    _officer = _this select 1;
    _fine = 1000;

    if &#40;player == _civilian&#41; then
    {
    SPON_playerBankBalance = SPON_playerBankBalance - _fine; _civilian groupchat format &#91;&#34;You were fined &#036;%1 by the establishment&#33;&#34;, _fine&#93;;
    } else {
    _officer globalchat &#91;&#34;%1 fined.&#34;, _civilian&#93;;
    };
    };

    switch &#40;side player&#41; do
    {
    case CIVILIAN&#58; {if &#40;SPON_playerBankBalance &#60; _fine&#41; then {player globalchat &#34;I can&#39;t afford the fine.&#34; }else{ SPON_playerBankBalance = SPON_playerBankBalance - _fine; player globalchat &#34;I paid the fine.&#34;;};};
    case WEST&#58; {_msg=Format&#91;&#34;I gave %1 a fine.&#34;, _civilian&#93;; _officer globalchat _msg;};
    };

    &#34;fine&#34; addPublicVariableEventHandler
    {
    &#40;_this select 1&#41; call fine_function; // &#40;_this select 1&#41; contains the value of &#34;fine&#34; pv, at the time of the event
    };[/QUOTE]

  8. #18
    Sergeant
    Join Date
    Jan 9 2007
    Location
    Bath, United Kingdom
    Posts
    154
    Author of the Thread
    Yay&#33; JasonO suggested that in the Init.sqf I put this:

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">fine = &#91;&#93;;
    fine_player = &#91;&#93;;
    &#34;fine&#34; addPublicVariableEventHandler {if &#40;player == fine_player&#41; then {_civilian = fine_player&#59; SPON_playerBankBalance = SPON_playerBankBalance - fine; _civilian groupchat format &#91;&#34;You were fined &#036;%1 by the establishment&#33;&#34;, fine&#93;;}else{_officer groupchat &#91;&#34;%1 fined.&#34;, _civilian&#93;;};};[/QUOTE]

    And fine.sqf should be this:

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_civilian = _this select 0;
    _officer = _this select 1;
    _fine = 1000;

    fine_player = _civilian;
    publicvariable &#34;fine_player&#34;;

    fine = _fine;
    publicvariable &#34;fine&#34;;
    _msg=Format&#91;&#34;I gave %1 a fine of &#036;%2&#34;, _civilian,_fine&#93;;
    _officer globalchat _msg;[/QUOTE]

    And it works - thanks for all ze help everyone

  9. #19
    Quote Originally Posted by (Somerville @ July 02 2008,16:22)
    Yay&#33; JasonO suggested that in the Init.sqf I put this
    I supplied my code merely as example for PV-eh, I was expecting you would be able to mold it to your needs

    The code you posted is incorrect because of a few things, example: _officer not specified within the publicvariable eh.
    I would at least loose the fine_player var and fix the officer thing , ala:
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">fine = &#91;&#93;;
    &#34;fine&#34; addPublicVariableEventHandler
    {
    *** _args = _this select 1;
    *** _fine = _args select 0; _civilian = _args select 1; _officer = _args select 2;
    *** if &#40;player == _civilian&#41; then
    *** {
    *** *** ***SPON_playerBankBalance = SPON_playerBankBalance - _fine;
    *** *** ***_civilian groupChat format &#91;&#34;You were fined &#036;%1 by the establishment&#33;&#34;, _fine&#93;;
    *** } else {
    *** *** ***_officer groupchat &#91;&#34;%1 fined.&#34;, _civilian&#93;;
    *** };
    };[/QUOTE]

    And fine.sqf should be this:
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_civilian = _this select 0;
    _officer = _this select 1;
    _fine = 1000;

    fine = &#91;_fine, _civilian, _officer&#93;;
    publicVariable &#34;fine&#34;;
    _msg=Format&#91;&#34;I gave %1 a fine of &#036;%2&#34;, _civilian,_fine&#93;;
    _officer globalchat _msg;[/QUOTE]
    Altough by not using a wrapper function that also executes on the sending machine, as supplied in my earlier example, you might end up with problems, depending on the situation.




  10. #20
    I guess I was the only one to misinterpreted this line on the wiki.

    Quote Originally Posted by [b
    Quote[/b] ]Note that the EH is only fired on clients where the publicVariable command has not been executed, as publicVariable does not change the variable where it has been executed.
    I took this to mean that once a variable had been broadcast with PublicVariable, a Public Variable event attached to that variable, on the same client, would no longer work. I just did a quick test and realised I jumped to the wrong conclusion

    Quote Originally Posted by [b
    Quote[/b] ]Altough by not using a wrapper function that also executes on the sending machine, as supplied in my earlier example, you might end up with problems, depending on the situation.
    Yeah, you also get similar problems if your launching the code from multiple clients and server, but only want it to be executed once.

    This is a function we use to emulate global commands like DeleteVehicle.

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">//Server side delete event
    &#34;RKSL_SYSDELETE&#34; AddPublicVariableEventHandler {&#91;_This Select 1&#93; Call RKSL_DeleteVehicleMP};[/QUOTE]

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">//Only launch the delete event directly if its called localy to the server
    If IsServer Then
    *** *** *** ***{
    *** *** *** ***//Don&#39;t execute it if a client has already made a request
    *** *** *** ***If &#40;RKSL_SYSDELETE&#33;=_Object&#41; Then
    *** *** *** *** *** *** *** ***{
    *** *** *** *** *** *** *** ***//Call the function directly
    *** *** *** *** *** *** *** ***&#91;_Object&#93; Call RKSL_DeleteVehicleMP;
    *** *** *** *** *** *** *** ***};
    *** *** *** ***}
    *** *** *** ***Else
    *** *** *** ***{
    *** *** *** ***//It&#39;s a client so get the server to handle it
    *** *** *** ***RKSL_SYSDELETE=_Object;
    *** *** *** ***PublicVariable &#34;RKSL_SYSDELETE&#34;;
    *** *** *** ***};[/QUOTE]

Page 2 of 2 FirstFirst 12

Posting Permissions

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