public UpdateTimeAndWeather()
{
foreach(Player, i)
{
if(IsPlayerConnected(i) && LoggedIn[i] == 1)
{
gettime(hour, minute,seconds);
format(timestr,32,"%02d:%02d:%02d",hour + 2,minute,seconds);
SetPlayerTime(i,hour+2,minute);
seconds ++;
if(seconds == 60)
{
minute ++;
}
if(minute == 00)
{
hour ++;
foreach(Player, x)
{
doPayDay(x);
}
}
TextDrawSetString(txtTimeDisp,timestr);
SetWorldTime(hour);
}
}
}
public doPayDay(playerid)
{
new unstring[100],string[256], benefits, rank, onlinebonus, faction,subtotal,taxtotal, total;
benefits = PlayerLevel[playerid] * RandomEx(200, 700);
rank = FRank[playerid] * RandomEx(300, 1200);
onlinebonus = PlayerLevel[playerid] * RandomEx(250, 700);
faction = RandomEx(200, 800);
//special = RandomEx(300, 1000);
subtotal = benefits + rank + onlinebonus + faction;
taxtotal = subtotal / 100 * 30;
total = subtotal-taxtotal;
new param1[32], param2[32];
if(Faction[playerid] == 0) {
param1 = "Civilian (0)";
param2 = "N/A";
}
else {
strcpy(param1, FactionName[Faction[playerid]], sizeof(param1));
switch(FRank[playerid]) { // strcpy(dest, source, length);
case 1: strcpy(param2, FactionRank1[Faction[playerid]], sizeof(param2));
case 2: strcpy(param2, FactionRank2[Faction[playerid]], sizeof(param2));
case 3: strcpy(param2, FactionRank3[Faction[playerid]], sizeof(param2));
case 4: strcpy(param2, FactionRank4[Faction[playerid]], sizeof(param2));
case 5: strcpy(param2, FactionRank5[Faction[playerid]], sizeof(param2));
case 6: strcpy(param2, FactionRank6[Faction[playerid]], sizeof(param2));
case 7: strcpy(param2, FactionRank7[Faction[playerid]], sizeof(param2));
}
}
SendClientMessage(playerid, COLOUR_LIGHTBLUE, "P_______A_______Y_______D_______A_______Y");
if(Faction[playerid] == 0)
{
format(unstring, sizeof(unstring), "Benefits for Un-Employment: $%d | Faction Rank: (N/A, $0)", benefits);
SendClientMessage(playerid, 0xFFFF90FF, unstring);
}
if(Faction[playerid] > 0)
{
format(string, sizeof(string), "Pay for %s: $%d | Faction Rank: %s (%d): $%d | ((Online Bonus)): $%d",FactionName[Faction[playerid]], faction, param2, FRank[playerid], rank, onlinebonus);
SendClientMessage(playerid, 0xFFFF90FF, string);
}
format(string, sizeof(string), "Total without Tax Deduction: $%d",subtotal);
SendClientMessage(playerid, 0xFFFF90FF, string);
format(string, sizeof(string), "Total Tax Deduction at 30%%: $%d (Money Transferred to your bank account.)",total);
SendClientMessage(playerid, 0xFFFF90FF, string);
PlayerSQLID[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "id", "accounts");
BankMoney[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "BankMoney", "accounts");
new sum = BankMoney[playerid] += taxtotal;
MySQL_SetInteger(PlayerSQLID[playerid], "BankMoney", sum, "accounts");
return 1;
}
I would use a global variable to keep track of the last hour that paydays were given out for.
I'm kind of confused by your code though. Why manually increase the seconds, minutes and hours instead of just waiting for that to update on the next cycle? |
public UpdateTimeAndWeather()
{
new
hour,
minute,
second
;
gettime(hour, minute, second);
SetWorldTime(hour);
format(timestr,32,"%02d:%02d:%02d",hour + 2,minute,seconds);
TextDrawSetString(txtTimeDisp,timestr);
foreach(Player, i)
{
if(IsPlayerConnected(i) && LoggedIn[i] == 1)
{
SetPlayerTime(i, hour+2, minute);
if(minute == 0) doPayDay(i);
}
}
return 1;
}
No worries about the other time I helped you, Dokins.
![]() Either way, your code confused the hell out of me. I wasn't sure why you were adding one to each variable (hour, minute, second). See if this helps at all: pawn Код:
|
new gLastPayday = -1;
public UpdateTimeAndWeather()
{
// this code doesn't belong in the foreach loop, you can just do it once
gettime(hour, minute,seconds);
hour += 2; // increase the hour by 2 here instead of doing it twice below
if (hour > 23)
hour -= 24; // hour can't be greater than 23, so if it is, fix it
new bool:timeForPaycheck = (minute == 0);
format(timestr,32,"%02d:%02d:%02d",hour,minute,seconds);
TextDrawSetString(txtTimeDisp,timestr);
SetWorldTime(hour);
foreach(Player, i)
{
if(IsPlayerConnected(i) && LoggedIn[i] == 1)
{
SetPlayerTime(i,hour,minute);
if (timeForPaycheck)
doPayDay(i);
}
}
}
Guess I'm a little late on this, but here's my version:
pawn Код:
|