Help with taxes
#1

Hello guys,i've made this code for let pay automatically at the player the taxes:

pawn Код:
new random_money = 1000+random(15000);
    for(new i=GetMaxPlayers()-1; i >=0; i--)
    {
        if(!IsPlayerConnected(i))continue;
        GivePlayerMoney(i,-random_money);
        new string[128];
        format(string, 100, "You paid %d$ in taxes to finance the State.", random_money);
        SendClientMessage(i,COLOR_GREEN, string);
Everything works fine,i need now to show how much taxes IN TOTAL where paid.

Ex: "You paid %d$ in taxes to finance the State.Global tax pays: %d"

How?Thanks.
Reply
#2

First of all, you will need a variable to store amount of total tax.
So put it at the top of your gamemode:
pawn Код:
new TotalTaxPaid;
Now you need to update this variable after someone pays some tax.
So your code will looks like:
pawn Код:
new random_money = 1000+random(15000);
    for(new i=GetMaxPlayers()-1; i >=0; i--)
    {
        if(!IsPlayerConnected(i))continue;
        GivePlayerMoney(i,-random_money);
        new string[128];
        TotalTaxPaid +=random_money; // update total tax
        format(string, 100, "You paid %d$ in taxes to finance the State. Total tax pays: $%d", random_money,TotalTaxPaid);
        SendClientMessage(i,COLOR_GREEN, string);
Also, you will need to save TotalTaxPaid if you don't want it to reset after each server's restart.
Reply
#3

Thanks for the fast reply,where i need to save the TotalTaxidPaid?In a file?Can u show me how?Thanks :3
Reply
#4

I haven't tested it, but it should work:
pawn Код:
bool:LoadTax() // load TotalTaxPays amount, use it in OnGameModeInit
{
    new File:aFile = fopen("taxes.ini",io_read);
    if(!aFile) return false;
    new str[32];
    fread(aFile,str,sizeof(str));
    GlobalTaxPays = strval(str);
    fclose(aFile);
    return true;
}

bool:SaveTax() // save GlobalTaxPays amount, use it in OnGameModeExit
{
    new File:aFile = fopen("taxes.ini",io_write);
    if(!aFile) return false;
    new str[32];
    format(str,sizeof(str),"%d",GlobalTaxPays);
    fwrite(aFile,str);
    fclose(aFile);
    return true;
}
Reply
#5

Quote:
Originally Posted by Norck
Посмотреть сообщение
I haven't tested it, but it should work:
pawn Код:
bool:LoadTax() // load TotalTaxPaid amount, use it in OnGameModeInit
{
    new File:aFile = fopen("taxes.ini",io_read);
    if(!aFile) return false;
    new str[32];
    fread(aFile,str,sizeof(str));
    TotalTaxPaid = strval(str);
    fclose(aFile);
    return true;
}

bool:SaveTax() // save TotalTaxPaid amount, use it in OnGameModeExit
{
    new File:aFile = fopen("taxes.ini",io_write);
    if(!aFile) return false;
    new str[32];
    format(str,sizeof(str),"%d",TotalTaxPaid);
    fwrite(aFile,str);
    fclose(aFile);
    return true;
}
EDIT: just mixed some var names
Reply
#6

Thanks!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)