Help with taxes - 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: Help with taxes (
/showthread.php?tid=308233)
Help with taxes -
Face9000 - 02.01.2012
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.
Re: Help with taxes -
Norck - 02.01.2012
First of all, you will need a variable to store amount of total tax.
So put it at the top of your gamemode:
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.
Re: Help with taxes -
Face9000 - 02.01.2012
Thanks for the fast reply,where i need to save the TotalTaxidPaid?In a file?Can u show me how?Thanks :3
Re: Help with taxes -
Norck - 02.01.2012
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;
}
Re: Help with taxes -
Norck - 02.01.2012
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
Re: Help with taxes -
Face9000 - 02.01.2012
Thanks!