SA-MP Forums Archive
Is there any shorter way to write that? - 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: Is there any shorter way to write that? (/showthread.php?tid=314983)



Is there any shorter way to write that? - nuriel8833 - 01.02.2012

Is there any shorter form of this code?
pawn Код:
if(iRace_Pos == 1)
            {
                GivePlayerMoney(playerid,100000);
                format(PosString, sizeof(PosString),"{ffaa00}%s {ffffff}has finished the race {ffaa00}1st!",Max_Reward/iRace_Pos, GetName(playerid));
                SendClientMessageToAll(0xff0000, PosString);
            }
            else if(iRace_Pos == 2)
            {
                GivePlayerMoney(playerid,85000);
                format(PosString, sizeof(PosString),"{ffaa00}%s {ffffff}has finished the race {ffaa00}2nd!",Max_Reward/iRace_Pos, GetName(playerid));
                SendClientMessageToAll(0xff0000, PosString);
            }
            else if(iRace_Pos == 3)
            {
                GivePlayerMoney(playerid,75000);
                format(PosString, sizeof(PosString),"{ffaa00}%s {ffffff}has finished the race {ffaa00}3rd!",Max_Reward/iRace_Pos, GetName(playerid));
                SendClientMessageToAll(0xff0000, PosString);
            }
            else if(iRace_Pos > 3 || iRace_Pos < 21)
            {
                GivePlayerMoney(playerid,(200000/iRace_Pos));
                format(PosString, sizeof(PosString),"{ffaa00}%s {ffffff}has finished the race {ffaa00}%sth!",Max_Reward/iRace_Pos, GetName(playerid));
                SendClientMessageToAll(0xff0000, PosString);
            }
            if(iRace_Pos == 21)
            {
                format(PosString, sizeof(PosString),"{ffaa00}%s {ffffff}has finished the race {ffaa00}21st!",Max_Reward/iRace_Pos, GetName(playerid));
                SendClientMessageToAll(0xff0000, PosString);
            }
            else if(iRace_Pos == 22)
            {
                format(PosString, sizeof(PosString),"{ffaa00}%s {ffffff}has finished the race {ffaa00}22nd!",Max_Reward/iRace_Pos, GetName(playerid));
                SendClientMessageToAll(0xff0000, PosString);
            }
            else if(iRace_Pos == 23)
            {
                format(PosString, sizeof(PosString),"{ffaa00}%s {ffffff}has finished the race {ffaa00}23rd!",Max_Reward/iRace_Pos, GetName(playerid));
                SendClientMessageToAll(0xff0000, PosString);
            }
            else if(iRace_Pos > 23 || iRace_Pos < 31 || iRace_Pos == 34)
            {
                format(PosString, sizeof(PosString),"{ffaa00}%s {ffffff}has finished the race {ffaa00}%sth!",Max_Reward/iRace_Pos, GetName(playerid));
                SendClientMessageToAll(0xff0000, PosString);
            }
            if(iRace_Pos == 31)
            {
                format(PosString, sizeof(PosString),"{ffaa00}%s {ffffff}has finished the race {ffaa00}31st!",Max_Reward/iRace_Pos, GetName(playerid));
                SendClientMessageToAll(0xff0000, PosString);
            }
            else if(iRace_Pos == 32)
            {
                format(PosString, sizeof(PosString),"{ffaa00}%s {ffffff}has finished the race {ffaa00}32nd!",Max_Reward/iRace_Pos, GetName(playerid));
                SendClientMessageToAll(0xff0000, PosString);
            }
            else if(iRace_Pos == 33)
            {
                format(PosString, sizeof(PosString),"{ffaa00}%s {ffffff}has finished the race {ffaa00}33rd!",Max_Reward/iRace_Pos, GetName(playerid));
                SendClientMessageToAll(0xff0000, PosString);
            }
Thanks 4 helpers


Re: Is there any shorter way to write that? - T0pAz - 01.02.2012

pawn Код:
switch(iRace_Pos)
{
    case 1:
    {
        GivePlayerMoney(playerid,100000);
        format(PosString, sizeof(PosString),"{ffaa00}%s {ffffff}has finished the race {ffaa00}1st!",Max_Reward/iRace_Pos, GetName(playerid));
        SendClientMessageToAll(0xff0000, PosString);
    }
    case 2:
    {
        GivePlayerMoney(playerid,85000);
        format(PosString, sizeof(PosString),"{ffaa00}%s {ffffff}has finished the race {ffaa00}2nd!",Max_Reward/iRace_Pos, GetName(playerid));
        SendClientMessageToAll(0xff0000, PosString);
    }
    case 3:
    {
        GivePlayerMoney(playerid,75000);
        format(PosString, sizeof(PosString),"{ffaa00}%s {ffffff}has finished the race {ffaa00}3rd!",Max_Reward/iRace_Pos, GetName(playerid));
        SendClientMessageToAll(0xff0000, PosString);
    }
    case 4..21:
    {
        GivePlayerMoney(playerid,(200000/iRace_Pos));
        format(PosString, sizeof(PosString),"{ffaa00}%s {ffffff}has finished the race {ffaa00}%sth!",Max_Reward/iRace_Pos, GetName(playerid));
        SendClientMessageToAll(0xff0000, PosString);
    }
    ...
}
If I were you, I would first of all make it dynamic.


Re: Is there any shorter way to write that? - -ExG-VirusKiller - 01.02.2012

I found a bug in your code.I don't have the way but there's a bug in your code.The bug is you're giving the first coming person 100,000 while the positions between 3 and 21 get 200,000.I think it's a typo and should be 20,000.Fix it.


Re: Is there any shorter way to write that? - nuriel8833 - 01.02.2012

Quote:
Originally Posted by -ExG-VirusKiller
Посмотреть сообщение
I found a bug in your code.I don't have the way but there's a bug in your code.The bug is you're giving the first coming person 100,000 while the positions between 3 and 21 get 200,000.I think it's a typo and should be 20,000.Fix it.
200000 / The race position
Which means that 4th position gets 50000$,5th position gets 40000$,10th position gets 20000$ and so on..
Its not a bug
--------------------
@T0pAz - thanks a lot,+1 rep