Need help: How can I tidy this script, it seems a bit buggy ?

Discussion in 'Scripting/Addon Discussion' started by KrisiS, Dec 29, 2015.

  1. KrisiS

    KrisiS Member

    Joined:
    Aug 17, 2013
    Messages:
    89
    Likes Received:
    1
    It is meant to give players some respect and money for every 30mins of play. The server restarts at 6hrs.
    Something seems a bit odd though as it sometimes resets peoples respect and money back to 400 if they relog or die. Am I missing something very simple here?

    I'm really not sure about the if (ExileClientPlayerMoney > -1000) then {
    I had no idea of how else to call it, sadly.

    Any help is much appreciated


    init.sqf

    Code:
    execVM "addons\reward\reward.sqf";

    reward.sqf
    Code:
        uiSleep 1800;
        if (ExileClientPlayerMoney > -1000) then {
            titleText ["", "PLAIN DOWN"];
           
                _newPoptabs = ExileClientPlayerMoney + 400;
                ENIGMA_UpdateStats = [player,_newPoptabs];
                publicVariableServer "ENIGMA_UpdateStats";
               
    
                _newScore = ExileClientPlayerScore + 400;
                ENIGMA_UpdateStats = [player,0,_newScore];
                publicVariableServer "ENIGMA_UpdateStats";
               
        uiSleep 3;
        ["<br /><br /><br /><t color='#ffff00'>Loyalty Bonus Added (30 Mins)</t><br /><t color='#ffffff'> You received $400 + 400 Respect <img size='1.0'  shadowColor='#000000' image='addons\statusbar\icons\exile.paa' color='%10'/></t>",0,0.9,10,2] spawn bis_fnc_dynamictext;
               
        };
       
            uiSleep 1800;
        if (ExileClientPlayerMoney > -1000) then {
            titleText ["", "PLAIN DOWN"];
           
    
                _newPoptabs = ExileClientPlayerMoney + 400;
                ENIGMA_UpdateStats = [player,_newPoptabs];
                publicVariableServer "ENIGMA_UpdateStats";
               
    
                _newScore = ExileClientPlayerScore + 400;
                ENIGMA_UpdateStats = [player,0,_newScore];
                publicVariableServer "ENIGMA_UpdateStats";
               
        uiSleep 3;
        ["<br /><br /><br /><t color='#ffff00'>Loyalty Bonus Added (1 Hour)</t><br /><t color='#ffffff'> You received $400 + 400 Respect <img size='1.0'  shadowColor='#000000' image='addons\statusbar\icons\exile.paa' color='%10'/></t>",0,0.9,10,2] spawn bis_fnc_dynamictext;
               
        };
       
       
            uiSleep 1800;
        if (ExileClientPlayerMoney > -1000) then {
            titleText ["", "PLAIN DOWN"];
           
    
                _newPoptabs = ExileClientPlayerMoney + 450;
                ENIGMA_UpdateStats = [player,_newPoptabs];
                publicVariableServer "ENIGMA_UpdateStats";
               
    
                _newScore = ExileClientPlayerScore + 450;
                ENIGMA_UpdateStats = [player,0,_newScore];
                publicVariableServer "ENIGMA_UpdateStats";
               
        uiSleep 3;
        ["<br /><br /><br /><t color='#ffff00'>Loyalty Bonus Added:</t><br /><t color='#ffffff'> You received $450 + 450 Respect <img size='1.0'  shadowColor='#000000' image='addons\statusbar\icons\exile.paa' color='%10'/></t>",0,0.9,10,2] spawn bis_fnc_dynamictext;
               
        };
       
            uiSleep 1800;
        if (ExileClientPlayerMoney > -1000) then {
            titleText ["", "PLAIN DOWN"];
           
    
                _newPoptabs = ExileClientPlayerMoney + 450;
                ENIGMA_UpdateStats = [player,_newPoptabs];
                publicVariableServer "ENIGMA_UpdateStats";
               
    
                _newScore = ExileClientPlayerScore + 450;
                ENIGMA_UpdateStats = [player,0,_newScore];
                publicVariableServer "ENIGMA_UpdateStats";
               
        uiSleep 3;
        ["<br /><br /><br /><t color='#ffff00'>Loyalty Bonus Added:</t><br /><t color='#ffffff'> You received $450 + 450 Respect <img size='1.0'  shadowColor='#000000' image='addons\statusbar\icons\exile.paa' color='%10'/></t>",0,0.9,10,2] spawn bis_fnc_dynamictext;
               
        };
       
       
            uiSleep 1800;
        if (ExileClientPlayerMoney > -1000) then {
            titleText ["", "PLAIN DOWN"];
           
    
                _newPoptabs = ExileClientPlayerMoney + 500;
                ENIGMA_UpdateStats = [player,_newPoptabs];
                publicVariableServer "ENIGMA_UpdateStats";
               
    
                _newScore = ExileClientPlayerScore + 500;
                ENIGMA_UpdateStats = [player,0,_newScore];
                publicVariableServer "ENIGMA_UpdateStats";
               
        uiSleep 3;
        ["<br /><br /><br /><t color='#ffff00'>Loyalty Bonus Added:</t><br /><t color='#ffffff'> You received $500 + 500 Respect <img size='1.0'  shadowColor='#000000' image='addons\statusbar\icons\exile.paa' color='%10'/></t>",0,0.9,10,2] spawn bis_fnc_dynamictext;
               
        };
       
            uiSleep 1800;
        if (ExileClientPlayerMoney > -1000) then {
            titleText ["", "PLAIN DOWN"];
           
    
                _newPoptabs = ExileClientPlayerMoney + 500;
                ENIGMA_UpdateStats = [player,_newPoptabs];
                publicVariableServer "ENIGMA_UpdateStats";
               
    
                _newScore = ExileClientPlayerScore + 500;
                ENIGMA_UpdateStats = [player,0,_newScore];
                publicVariableServer "ENIGMA_UpdateStats";
               
        uiSleep 3;
        ["<br /><br /><br /><t color='#ffff00'>Loyalty Bonus Added:</t><br /><t color='#ffffff'> You received $500 + 500 Respect <img size='1.0'  shadowColor='#000000' image='addons\statusbar\icons\exile.paa' color='%10'/></t>",0,0.9,10,2] spawn bis_fnc_dynamictext;
               
        };
       
       
            uiSleep 1800;
        if (ExileClientPlayerMoney > -1000) then {
            titleText ["", "PLAIN DOWN"];
           
    
                _newPoptabs = ExileClientPlayerMoney + 550;
                ENIGMA_UpdateStats = [player,_newPoptabs];
                publicVariableServer "ENIGMA_UpdateStats";
               
    
                _newScore = ExileClientPlayerScore + 550;
                ENIGMA_UpdateStats = [player,0,_newScore];
                publicVariableServer "ENIGMA_UpdateStats";
               
        uiSleep 3;
        ["<br /><br /><br /><t color='#ffff00'>Loyalty Bonus Added:</t><br /><t color='#ffffff'> You received $550 + 550 Respect <img size='1.0'  shadowColor='#000000' image='addons\statusbar\icons\exile.paa' color='%10'/></t>",0,0.9,10,2] spawn bis_fnc_dynamictext;
               
        };
       
            uiSleep 1800;
        if (ExileClientPlayerMoney > -1000) then {
            titleText ["", "PLAIN DOWN"];
           
    
                _newPoptabs = ExileClientPlayerMoney + 550;
                ENIGMA_UpdateStats = [player,_newPoptabs];
                publicVariableServer "ENIGMA_UpdateStats";
               
    
                _newScore = ExileClientPlayerScore + 550;
                ENIGMA_UpdateStats = [player,0,_newScore];
                publicVariableServer "ENIGMA_UpdateStats";
               
        uiSleep 3;
        ["<br /><br /><br /><t color='#ffff00'>Loyalty Bonus Added:</t><br /><t color='#ffffff'> You received $550 + 550 Respect <img size='1.0'  shadowColor='#000000' image='addons\statusbar\icons\exile.paa' color='%10'/></t>",0,0.9,10,2] spawn bis_fnc_dynamictext;
               
        };
       
       
            uiSleep 1800;
        if (ExileClientPlayerMoney > -1000) then {
            titleText ["", "PLAIN DOWN"];
           
    
                _newPoptabs = ExileClientPlayerMoney + 18000;
                ENIGMA_UpdateStats = [player,_newPoptabs];
                publicVariableServer "ENIGMA_UpdateStats";
               
    
                _newScore = ExileClientPlayerScore + 18000;
                ENIGMA_UpdateStats = [player,0,_newScore];
                publicVariableServer "ENIGMA_UpdateStats";
               
        uiSleep 3;
        ["<br /><br /><br /><t color='#ffff00'>Loyalty Bonus Added:</t><br /><t color='#ffffff'> You received $18000 + 18000 Respect <img size='1.0'  shadowColor='#000000' image='addons\statusbar\icons\exile.paa' color='%10'/></t>",0,0.9,10,2] spawn bis_fnc_dynamictext;
               
        };
       
            uiSleep 1800;
        if (ExileClientPlayerMoney > -1000) then {
            titleText ["", "PLAIN DOWN"];
           
    
                _newPoptabs = ExileClientPlayerMoney + 18000;
                ENIGMA_UpdateStats = [player,_newPoptabs];
                publicVariableServer "ENIGMA_UpdateStats";
               
    
                _newScore = ExileClientPlayerScore + 18000;
                ENIGMA_UpdateStats = [player,0,_newScore];
                publicVariableServer "ENIGMA_UpdateStats";
               
        uiSleep 3;
        ["<br /><br /><br /><t color='#ffff00'>Loyalty Bonus Added:</t><br /><t color='#ffffff'> You received $18000 + 18000 Respect <img size='1.0'  shadowColor='#000000' image='addons\statusbar\icons\exile.paa' color='%10'/></t>",0,0.9,10,2] spawn bis_fnc_dynamictext;
               
        };
       
       
            uiSleep 1800;
        if (ExileClientPlayerMoney > -1000) then {
            titleText ["", "PLAIN DOWN"];
           
    
                _newPoptabs = ExileClientPlayerMoney + 650;
                ENIGMA_UpdateStats = [player,_newPoptabs];
                publicVariableServer "ENIGMA_UpdateStats";
               
    
                _newScore = ExileClientPlayerScore + 650;
                ENIGMA_UpdateStats = [player,0,_newScore];
                publicVariableServer "ENIGMA_UpdateStats";
               
        uiSleep 3;
        ["<br /><br /><br /><t color='#ffff00'>Loyalty Bonus Added:</t><br /><t color='#ffffff'> You received $650 + 650 Respect <img size='1.0'  shadowColor='#000000' image='addons\statusbar\icons\exile.paa' color='%10'/></t>",0,0.9,10,2] spawn bis_fnc_dynamictext;
               
        };
       
            uiSleep 1500;
        if (ExileClientPlayerMoney > -1000) then {
            titleText ["", "PLAIN DOWN"];
           
    
                _newPoptabs = ExileClientPlayerMoney + 650;
                ENIGMA_UpdateStats = [player,_newPoptabs];
                publicVariableServer "ENIGMA_UpdateStats";
               
    
                _newScore = ExileClientPlayerScore + 650;
                ENIGMA_UpdateStats = [player,0,_newScore];
                publicVariableServer "ENIGMA_UpdateStats";
               
        uiSleep 3;
        ["<br /><br /><br /><t color='#ffff00'>Loyalty Bonus Added:</t><br /><t color='#ffffff'> You received $650 + 650 Respect <img size='1.0'  shadowColor='#000000' image='addons\statusbar\icons\exile.paa' color='%10'/></t>",0,0.9,10,2] spawn bis_fnc_dynamictext;
               
        };
        
     
  2. ShootingBlanks

    ShootingBlanks OpenDayZ Guru!

    Joined:
    Mar 31, 2013
    Messages:
    2,422
    Likes Received:
    336
    will look at the code this afternoon. looks like an error somewhere in that after they die the variable is not being retrieved correctly since it resets to 400.
    nust guessing here:
    in exile, the player doesnt go back to the 'lobby' so the script maybe probably running while dead, it doesnt get restarted upon spawning. so while the player is dead, money is zero.
    create a debug version of your script that prints the variables to a hintbox all the time and see what is getting returned. so remove the sleep and print the values constantly without updating.
     
    KrisiS likes this.
  3. KrisiS

    KrisiS Member

    Joined:
    Aug 17, 2013
    Messages:
    89
    Likes Received:
    1
    Cool, thank you for the input friend. :)
    I won't be home until tomorrow evening so won't get a chance to do anything until then.

    What you have mentioned makes sense to me. I'm not really sure what I'd be looking for with a debug version of the script but I will certainly give it a try as soon as I'm home :)

    You're very kind to help people all the time with this stuff man, thank you for your endless contributions!
     
  4. ShootingBlanks

    ShootingBlanks OpenDayZ Guru!

    Joined:
    Mar 31, 2013
    Messages:
    2,422
    Likes Received:
    336
    your player, you know how many poptabs and money you have. you,are retrievin those values and then addindg 400. at some point, those values must be getting retrieved as zero. so you want to see if its zero only for a few moments after death or are they always being retrieved correctly. in that case thehe error is in saving the values. as usual, am on cellphone so my usefullness is limited. i can look at the code at home tonight.

    excuse my fat finger message errors ... comma is too close to space for my thumb
     
  5. KrisiS

    KrisiS Member

    Joined:
    Aug 17, 2013
    Messages:
    89
    Likes Received:
    1
    Haha, I know the feeling :)


    Thanks for the extra info, I hope there is a fix for the error.

    Cheers :)
     
  6. ShootingBlanks

    ShootingBlanks OpenDayZ Guru!

    Joined:
    Mar 31, 2013
    Messages:
    2,422
    Likes Received:
    336
    I assume you got your idea and code from this https://github.com/happydayz-enigma/Enigma_Exile_Custom
    Your code looks like it should work, so the issue must be introduced either in the time checks or in the check > -1000 which is not required at all.

    Try using this code instead, see what happens. Not sure if code resets every time player dies or not. this will tell us.

    I simply multiply 400 times reward cycle so they will get 400,800,1200 etc etc

    The debug hint displays should always be showing the players correct money and poptabs, it should never be zero for either. We might have to add in a check to see if player is alive to retrieve correct amounts.
    Code:
    if (!isServer) then {
    _rewardcycle = 0;
    
    //********************************************
    //If player dies, this will be shown when they spawn and when they first join.
    uisleep 60; // wait for screen to be displayed
    hint format["*** REWARDS INITIALIZED *** REWARDCYCLE %1, ExilceClientPlayerMoney %2, ExileClientPlayerScore %3", _rewardcycle, ExilceClientPlayerMoney, ExileClientPlayerScore]
    //******************************************
    
    while {true} do {
    //wait from current time until 30 minutes.
    _rewardTime = time + 1800;
    waitUntil {time >= _rewardTime};  /* continue after 30 minutes... */
    // which reward level are we on, increment on each iteration.
    _rewardcycle = _rewardcycle + 1;
    //******************DEBUG INFO ******
    hint format["rewardcycle %1, ExilceClientPlayerMoney %2, ExileClientPlayerScore %3", _rewardcycle, ExilceClientPlayerMoney, ExileClientPlayerScore];
    //**************************************
                titleText ["", "PLAIN DOWN"];
    
                _newPoptabs = ExileClientPlayerMoney + (400 * _rewardcycle);
                ENIGMA_UpdateStats = [player,_newPoptabs];
                publicVariableServer "ENIGMA_UpdateStats";
          
    
                _newScore = ExileClientPlayerScore + (400 * _rewardcycle);
                ENIGMA_UpdateStats = [player,0,_newScore];
                publicVariableServer "ENIGMA_UpdateStats";
          
                uiSleep 3;
                ["<br /><br /><br /><t color='#ffff00'>Loyalty Bonus Added </t><br /><t color='#ffffff'> You received Respect and Money for survival bonus <img size='1.0'  shadowColor='#000000' image='addons\statusbar\icons\exile.paa' color='%10'/></t>",0,0.9,10,2] spawn bis_fnc_dynamictext;
    };
    };
    
     
    Last edited: Jan 3, 2016
    KrisiS likes this.
  7. KrisiS

    KrisiS Member

    Joined:
    Aug 17, 2013
    Messages:
    89
    Likes Received:
    1
    Yeah, that is what I was using to apply the poptabs and respect updates. I changed it slightly in order to try it differently to see if I was still getting the same type of error.

    Thank you so much for taking the time to write this out for me. It certainly looks a bit better than what I was using and hopefully it will work! I'm looking forward to getting a chance to test this out tomorrow.

    Thanks again, you have always been a super help for me!


    I had a feeling the check > -1000 was not necessary but was not sure how to go about not using it :)
    Learn a little something new every day :D
     
  8. ShootingBlanks

    ShootingBlanks OpenDayZ Guru!

    Joined:
    Mar 31, 2013
    Messages:
    2,422
    Likes Received:
    336
    of course this all hinges on the Enigma updatestats functioning correctly. With all the Exile updates, maybe that file is out of date ... it is 6 weeks old.

    Code:
    if (!isServer) then {
    _rewardcycle = 0;
    
    //********************************************
    //If player dies, this will be shown when they spawn and when they first join.
    uisleep 60; // wait for screen to be displayed
    hint format["*** REWARDS INITIALIZED *** REWARDCYCLE %1, ExilceClientPlayerMoney %2, ExileClientPlayerScore %3", _rewardcycle, ExilceClientPlayerMoney, ExileClientPlayerScore];
    //******************************************
    
    while {true} do {
    //wait from current time until 30 minutes.
    _rewardTime = time + 1800;
    waitUntil {time >= _rewardTime};  /* continue after 30 minutes... */
    // which reward level are we on, increment on each iteration.
    _rewardcycle = _rewardcycle + 1;
    //******************DEBUG INFO ******
    hint format["rewardcycle %1, ExilceClientPlayerMoney %2, ExileClientPlayerScore %3", _rewardcycle, ExilceClientPlayerMoney, ExileClientPlayerScore];
    //**************************************
                titleText ["", "PLAIN DOWN"];
    
                _newPoptabs = ExileClientPlayerMoney + (400 * _rewardcycle);
                ENIGMA_UpdateStats = [player,_newPoptabs];
                publicVariableServer "ENIGMA_UpdateStats";
         
    
                _newScore = ExileClientPlayerScore + (400 * _rewardcycle);
                ENIGMA_UpdateStats = [player,0,_newScore];
                publicVariableServer "ENIGMA_UpdateStats";
         
                uiSleep 3;
                ["<br /><br /><br /><t color='#ffff00'>Loyalty Bonus Added </t><br /><t color='#ffffff'> You received Respect and Money for survival bonus <img size='1.0'  shadowColor='#000000' image='addons\statusbar\icons\exile.paa' color='%10'/></t>",0,0.9,10,2] spawn bis_fnc_dynamictext;
    };
    };
    do some syntax checks, just noticed i forgot a semicolon on the first hint display... might be more ..
     
  9. KrisiS

    KrisiS Member

    Joined:
    Aug 17, 2013
    Messages:
    89
    Likes Received:
    1
    That's very true, I'll have my fingers crossed that it still works correctly.

    I'll be sure to check for syntax before trying it out, thanks for the heads up :)
     
  10. KrisiS

    KrisiS Member

    Joined:
    Aug 17, 2013
    Messages:
    89
    Likes Received:
    1
    Hey buddy,

    This appears to have worked for me :) . It's live on our public server about 12 hours now and still seems to not have any issues.

    I can actually see the logic in how you have written the script and your 'notes' help to understand what is happening.

    Thank you so much,
    You've been really helpful for me for so many months and across multiple games now!!
     
    Last edited: Jan 4, 2016

Share This Page