Is there any shorter way to write that?
#1

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
Reply
#2

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.
Reply
#3

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.
Reply
#4

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)