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

Thread: "addPublicVariableEventHandler" for Sahraniville

  1. #1
    Morning people!

    Sorry if this seems very straight forward, but I'm struggling to get my head around "addPublicVariableEventHandler". I'm using SPON_Money for Sahraniville, a Roleplaying mission, but I can't seem to get the fines to work. I've e-mailed the developer of SPON_Money/Core, and he suggested trying addPublicVariableEventHandler. There are two variables - one is SPON_PlayerBankBalance, the other SPON_PlayerCashBalance. I've been told that I can't use CashBalance. I am trying to make it so that when a police officer hits the "Fine $1,000 option", the unit in question has that amount removed from their bank account. I had some help from a chap called DeChevs, who provided the following, which he advised to put into my init.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;;
    &#34;fine&#34; addPublicVariableEventHandler {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]

    The action "Fine" for the cop executes the following:

    <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;

    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;};
    };[/QUOTE]

    But this does not seem to work. Originally I tried a CrimeCity style BankBalance = BankBalance - Fine, but that took the money away from every unit that was alive, and I can&#39;t figure out a way around it&#33;

    Any help will be very much appreciated fellas

  2. #2
    Quote Originally Posted by (Somerville @ July 01 2008,10:07)
    <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 {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]

    Typo ?

    "fine" addPublicVariableEventHandler....

    but inside the eventhandler you are using

    _fine

    And where do you send the fine variable with publicVariable ?

    Xeno

  3. #3
    Sergeant
    Join Date
    Jan 9 2007
    Location
    Bath, United Kingdom
    Posts
    154
    Author of the Thread
    Oopps, my bad - that&#39;s from an older version. It&#39;s supposed to be just "Fine" - I realised you can&#39;t use local variables for it

    I thought you need not PublicVariable it if you use addPublicVariableEventHandler?

  4. #4
    Quote Originally Posted by (Somerville @ July 01 2008,10:34)
    I thought you need not PublicVariable it if you use addPublicVariableEventHandler?
    That&#39;s the purpose behind addPublicVariableEventHandler, it reacts if the variable gets broadcasted via publicVariable.
    But be aware that it doesn&#39;t get executed on the machine where the variable was send with publicVariable and it won&#39;t work in a hosted environment.

    Xeno

  5. #5
    Sergeant
    Join Date
    Jan 9 2007
    Location
    Bath, United Kingdom
    Posts
    154
    Author of the Thread
    So it doesn&#39;t work, or won&#39;t work, on our clan&#39;s dedicated server? Bugger..

    Does anybody know a way around this? Pretty please?

  6. #6
    Quote Originally Posted by (Somerville @ July 01 2008,11:08)
    So it doesn&#39;t work, or won&#39;t work, on our clan&#39;s dedicated server? Bugger..
    Dedicated Server &#33;= hosted environment.

    addPublicVariableEventhandler works fine on dedicated servers, that is what it was made for.

    You just have remember that if you send a variable with publicVariable on the server the addPublicVariableHandler won&#39;t get executed on the server but only on the clients. The same applies to clients. The client that sends the variable with publicVariable will not execute addPublicVariableEventhandler.

    Xeno




  7. #7
    Quote Originally Posted by [b
    Quote[/b] ] So it doesn&#39;t work, or won&#39;t work, on our clan&#39;s dedicated server?
    What _Xeno_ meant was, it won&#39;t work in Single Player or player&#92;server. So you have to add some extra checks to account for single player and player&#92;server.

    The first thing you have to work out is, where the fines will be issued from:

    If the fine is always issued from the server then you need to create a variable for playerfines on the server and clients. With the event handler added to each client for the playerFines variable.

    If it&#39;s only ever issued from a single client, then you just need the event handler on the server.

    If it can be issued from either one or all the clients, and the server, then it becomes a bit more complex.

  8. #8
    Sergeant
    Join Date
    Jan 9 2007
    Location
    Bath, United Kingdom
    Posts
    154
    Author of the Thread
    Hi guys,

    Thanks for all the help so far

    What I&#39;ve got is a situation where it can be called from any 1 of 22 playable civilians. The cop walks up, hits the "Fine" option. What I basically need is for the money to come off of the civilian who has been fined. So I guess it&#39;s a situation where it only needs to be PublicVariabled on the client end..?

  9. #9
    Looking at the original code you posted, I would suggest using SetvehicleInit instead of public variable. The basic criteria I use is. If you want to send something to a specific client then use Public Variable event handlers. If you want to send something to more than one client, use SetVehicleInit. In this case you want to send data to both the offending player and all the other players on side West.

    You can still use Public Variable Event Handlers to send info to both the offender and all the players on side West. But it gets much more complicated.




  10. #10
    You could use something like 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_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 groupchat &#91;&#34;%1 fined.&#34;, _civilian&#93;;
    *** };
    };

    &#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]

    Anytime you want to run the finefunctions, just use:
    [_civilian, _officer] call fine_updateFunction;

    Not sure where this fits in, but I guess you can use my examples above to make it fitting
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
    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;};
    };[/QUOTE]

    Quote Originally Posted by (UNN @ July 01 2008,22:48)
    Looking at the original code you posted, I would suggest using SetvehicleInit instead of public variable. The basic criteria I use is. If you want to send something to a specific client then use Public Variable event handlers. If you want to send something to more than one client, use SetVehicleInit. In this case you want to send data to both the offending player and all the other players on side West.

    You can still use Public Variable Event Handlers to send info to both the offender and all the players on side West. But it gets much more complicated.
    Hey mate I disagree with your logic.
    setVehicleInit should IMO be used for persistent actions, e.g. actions that also must be received by all following join in progress players.
    As setVehicleInit&#39;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

    Any non persistent actions, or time based actions (like a unit shouting something or a sound playing somewhere, etc. etc), IMO should be done with publicVariableEventHandler.

    Not to mention that PVEH can send any data type, where as you will need helper objects and pv&#39;s to get certain data across with setVehicleInit.

    Simply sending values, persistent or non persistent, should imo be done by just pv&#39;s. And until BI has finished their hotfix for JIP-player lag etc, I would try to keep to a low amount as possible



    A.C.E. Advanced Combat Environment

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

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
  •