SA-MP Forums Archive
Shorten this - 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: Shorten this (/showthread.php?tid=659560)



Shorten this - KinderClans - 07.10.2018

I'm sure there is a shorter and fastest way to do this:

pawn Код:
task PayBankTaxes[2400000]() //40 minutes
{
    foreach (new i : Player)
    {
        new str[128];

        if(Player[i][Bank] > 25000 || Player[i][Bank] < 74999) //2.0125%
        {
            new taxes = Player[i][Bank] / 64;
            Player[i][Bank] = Player[i][Bank] - Player[i][Bank] / 64;
           
            SCM(i, COLOR_WHITE, "|___ BANK STATEMENT ___|");
            SCMEX(i, COLOR_FADE1, "   Balance: %s", formatInt(Player[i][Bank]));
            SCMEX(i, COLOR_FADE1, "   Taxes paid: %s", formatInt(taxes));
            SCM(i, COLOR_WHITE, "|________________________|");

            format(str, sizeof(str), "~y~Taxes~n~~w~Paid~n~~g~%s", formatInt(taxes));
            GameTextForPlayer(i, str, 3000, 1);
        }

        else if(Player[i][Bank] > 75000 || Player[i][Bank] < 149999) //3.125%
        {
            new taxes = Player[i][Bank] / 32;
            Player[i][Bank] = Player[i][Bank] - Player[i][Bank] / 32;
           
            SCM(i, COLOR_WHITE, "|___ BANK STATEMENT ___|");
            SCMEX(i, COLOR_FADE1, "   Balance: %s", formatInt(Player[i][Bank]));
            SCMEX(i, COLOR_FADE1, "   Taxes paid: %s", formatInt(taxes));
            SCM(i, COLOR_WHITE, "|________________________|");

            format(str, sizeof(str), "~y~Taxes~n~~w~Paid~n~~g~%s", formatInt(taxes));
            GameTextForPlayer(i, str, 3000, 1);
        }

        else if(Player[i][Bank] >= 150000) //6.25%
        {
            new taxes = Player[i][Bank] / 16;
            Player[i][Bank] = Player[i][Bank] - Player[i][Bank] / 16;
           
            SCM(i, COLOR_WHITE, "|___ BANK STATEMENT ___|");
            SCMEX(i, COLOR_FADE1, "   Balance: %s", formatInt(Player[i][Bank]));
            SCMEX(i, COLOR_FADE1, "   Taxes paid: %s", formatInt(taxes));
            SCM(i, COLOR_WHITE, "|________________________|");

            format(str, sizeof(str), "~y~Taxes~n~~w~Paid~n~~g~%s", formatInt(taxes));
            GameTextForPlayer(i, str, 3000, 1);
        }
    }
}
I've tried to add the bank statement messages at bottom but got some errors. Any help?


Re: Shorten this - SyS - 07.10.2018

Put the repeated statements out side if else block

Quote:
Originally Posted by KinderClans
Посмотреть сообщение
I've tried to add the bank statement messages at bottom but got some errors. Any help?
What errors and show how you did it


Re: Shorten this - Dennis12 - 07.10.2018

I think it's better to use ptask.

Код:
ptask PayBankTaxes[2400000](playerid)
{
	new
		str[128],
		taxes;
		
	if(Player[playerid][Bank] > 25000 || Player[playerid][Bank] < 74999)
	{
		taxes = Player[playerid][Bank] / 64;
		Player[playerid][Bank] = Player[playerid][Bank] - Player[playerid][Bank] / 64;
	}
	else if(Player[i][Bank] > 75000 || Player[i][Bank] < 149999)
	{
                taxes = Player[playerid][Bank] / 32;
		Player[playerid][Bank] = Player[playerid][Bank] - Player[playerid][Bank] / 32;
	}
	else if(Player[i][Bank] >= 150000) //6.25%
        {
                taxes = Player[i][Bank] / 16;
                Player[i][Bank] = Player[i][Bank] - Player[i][Bank] / 16;
        }
	
	SCM(i, COLOR_WHITE, "|___ BANK STATEMENT ___|");
        SCMEX(i, COLOR_FADE1, "   Balance: %s", formatInt(Player[i][Bank]));
        SCMEX(i, COLOR_FADE1, "   Taxes paid: %s", formatInt(taxes));
        SCM(i, COLOR_WHITE, "|________________________|");

        format(str, sizeof(str), "~y~Taxes~n~~w~Paid~n~~g~%s", formatInt(taxes));
        GameTextForPlayer(i, str, 3000, 1);
}



Re: Shorten this - Beckett - 07.10.2018

Код:
            SCMEX(i, COLOR_FADE1, "   Balance: %s", formatInt(Player[i][Bank]));
            SCMEX(i, COLOR_FADE1, "   Taxes paid: %s", formatInt(taxes));
This is a bad idea, especially when you're looping through all players. Use one string and format it instead of doing this.