SA-MP Forums Archive
Paycheck Problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Paycheck Problem (/showthread.php?tid=423884)



Paycheck Problem - mrtms - 19.03.2013

This code should on every hour on the MinuteTimer it will execute the SyncTime function will then execute the Payday() function on the 00 hour. For some reason it does it randomly in between the hour and on top of that it doesn't give every single person there paycheck. What I'm actually thinking is that the server does this function for the player every hour. Does anyone have any idea as to what is going on here?
PHP код:
task MinuteTimer[60000]()
{
    new 
string[128], cMinute, cHour;
     
//, iv = INVALID_PLAYER_ID; For fuel system
    
    
foreach(new playerid: Player)
    {
        
MinutesConnected[playerid]++;
        
SyncTime();
    }
}
forward SyncTime();
public 
SyncTime()
{
    new
        
string[64],
        
tmphour,
        
tmpminute,
        
tmpsecond;
    
gettime(tmphour, tmpminute, tmpsecond);
    
FixHour(tmphour);
    
tmphour = shifthour;
    if((
tmphour > ghour) || (tmphour == 0 && ghour == 23))
    {
        
format(string, sizeof(string), "The time is now %d:00.",tmphour);
        
SendClientMessageToAll(COLOR_WHITE,string);
        
ghour = tmphour;
        
Payday();
    }
}
Payday()
{
    foreach(new 
playerid: Player)
    {
        new 
moneyGiven, PhoneBill, Float:InterestRate, Interest, MinutesTabbed, MinutesReal, PlayerLevel, taxamount, exp, extra = 1;
         if(
MinutesConnected[playerid] < MINUTES_FOR_PAYDAY)
           {
             return 
SendClientMessage(playerid, COLOR_GRAD3, "You have not played long enough to receive a paycheck.");
        }
        
printf("Tab Time3: %d", totalTimeTab[playerid]);
        
printf("Minutes Time3: %d", MinutesConnected[playerid]);
        
printf("PlayerID3: %d", playerid);
        
//Interest Rates
        
if(PlayerInfo[playerid][pVIP] == 0)
        {
            
InterestRate = 0.01;
        }
        else if(
PlayerInfo[playerid][pVIP] == 1)
        {
            
InterestRate = 0.015;
        }
        else if(
PlayerInfo[playerid][pVIP] == 2)
        {
            
InterestRate = 0.02;
        }
        else if(
PlayerInfo[playerid][pVIP] == 3)
        {
            
InterestRate = 0.03;
        }
        else
        {
            
InterestRate = 0.01;
        }
        
PhoneBill = floatround((PlayerInfo[playerid][pTexts] + PlayerInfo[playerid][pCalls])*0.75);
        
Interest = floatround(PlayerInfo[playerid][pBank] * InterestRate);
        
MinutesTabbed = floatround(totalTimeTab[playerid]/60);
        
MinutesReal = MinutesConnected[playerid] - MinutesTabbed;
        
        if(
MinutesReal <= 0)
        {
            
MinutesReal = 1;
              
PlayerLevel = (PlayerInfo[playerid][pLevel] * 2) * MinutesReal;
          }
          else
          {
              
PlayerLevel = (PlayerInfo[playerid][pLevel] * 2) * MinutesReal;
          }
        
        
printf("Interest1: %.3f", InterestRate);
        
printf("Minutes Connected: %d", MinutesConnected[playerid]);
          
printf("Minutes Tabbed: %d", MinutesTabbed);
          
printf("Minutes Total: %d", MinutesReal);
        
        
moneyGiven = PlayerLevel + Interest - PhoneBill;
        
        
taxamount = floatround(tax*moneyGiven);
        
moneyGiven -= taxamount;
        
safeamount += taxamount;
        
SendClientMessage(playerid, COLOR_WHITE, "__________________ PAYDAY __________________");
        
SendClientMessageEx(playerid, COLOR_GRAD3, "Money: $%d", PlayerLevel);
        
SendClientMessageEx(playerid, COLOR_GRAD4, "%.3f Interest (Limit 10000): $%d", InterestRate, Interest);
        
SendClientMessageEx(playerid, COLOR_GRAD4, "Phone Bill: $%d", PhoneBill);
        
SendClientMessageEx(playerid, COLOR_GRAD4, "Tax: %.3f percent, $%d", tax, taxamount);
        
SendClientMessageEx(playerid, COLOR_GRAD5, "Total Money: $%d", moneyGiven);
         new 
extraVariableTwo = 1;
        if(
DOUBLE_EXP_WEEK > extraVariableTwo)
        {
              
exp = moneyGiven * DOUBLE_EXP_WEEK;
            
moneyGiven = exp;
              
SendClientMessageEx(playerid, COLOR_GRAD5, "New Total Money (Double EXP Enabled): $%d", exp);
        }
        if(
PlayerInfo[playerid][pCash] > 0) SendClientMessage(playerid, COLOR_YELLOW, "Your paycheck has been deposited into your bank account.");
        
SendClientMessage(playerid, COLOR_WHITE, "____________________________________________");
          if(
PlayerInfo[playerid][pCash] <= 0) PlayerInfo[playerid][pCash] += floatround(moneyGiven);
        else 
PlayerInfo[playerid][pBank] += floatround(moneyGiven);
        
PlayerInfo[playerid][pTexts] = 0;
        
PlayerInfo[playerid][pCalls] = 0;
        
totalTimeTab[playerid] = 0;
        
MinutesConnected[playerid] = 0;
        
PlayerInfo[playerid][pPlayingHours]++;
        
        if(
DOUBLE_EXP_WEEK > extra)
        {
            
exp = 1 * DOUBLE_EXP_WEEK;
            
PlayerInfo[playerid][pEXP] += exp;
        }
        else
        {
            
PlayerInfo[playerid][pEXP]++;
        }
        if(
PlayerInfo[playerid][pEXP] >= PlayerInfo[playerid][pLevel]*REQUIRED_HOURS_PER_LEVEL)
        {
              
PlayerInfo[playerid][pLevel]++;
            
PlayerInfo[playerid][pEXP] = 0;
            
SetPlayerScore(playerid, PlayerInfo[playerid][pLevel]);
            
SendClientMessageEx(playerid, COLOR_YELLOW, "You have leveled up to level %d. You must achieve %d more playing hours to receive level %d.", PlayerInfo[playerid][pLevel], REQUIRED_HOURS_PER_LEVEL, PlayerInfo[playerid][pLevel]+1);
        }
        break;
    }
    return 
1;
} 



Re: Paycheck Problem - mrtms - 19.03.2013

Anyone have any clue at all as to what can be causing this issue?