SERVER: Unknown command
#3

I know this entirely depends on the coder's personal preference, but I'm just going to note this down as a small suggestion for you.

Instead of doing:
pawn Код:
if(Player[playerid][pAdmin] >= 1)
{
    new string[128], carid, carcolor1, carcolor2;
    if(!sscanf(params, "iii", carid, carcolor1, carcolor2))
    {
        if(carid >= 400 && carid <= 611)
        {
            if(carcolor2 >= 0 && carcolor2 <= 252)
            {
                // ...
            }
            else return SendClientMessage(playerid, COLOR_RED, "Неверный ID цвета!Используйте числа от 0 до 252.");
        }
        else return SendClientMessage(playerid, COLOR_RED, "Неверный ID транспорта!Используйте от 400 до 611.");
    }
    else return SendClientMessage(playerid, COLOR_GREEN, "Используйте: /car [ID] [цвет 1][цвет 2].");
}
You can easily do:
pawn Код:
if(Player[playerid][pAdmin] == 0)
    return SendClientMessage(playerid, COLOR_RED, "У Вас недостаточно высокий уровень,для использования этой команды!");

new carid, carcolor1, carcolor2;
if(sscanf(params, "iii", carid, carcolor1, carcolor2))
    return SendClientMessage(playerid, COLOR_GREEN, "Используйте: /car [ID] [цвет 1][цвет 2].");

if(!(400 <= carid <= 611)) // this is the same as if(carid < 400 || carid > 600)!
    return SendClientMessage(playerid, COLOR_RED, "Неверный ID транспорта!Используйте от 400 до 611.");

if(!(0 <= carcolor1 <= 252) || !(0 <= carcolor2 <= 252))
    return SendClientMessage(playerid, COLOR_RED, "Неверный ID цвета!Используйте числа от 0 до 252.");

// Now rest of the code
return true;
When I got introduced to commands back in 2007, I wasn't really familiar with scripting or programming, so I couldn't even think some more readability could be introduced. I remember having a really heavy scope-in-scope structure :P
Reply


Messages In This Thread
SERVER: Unknown command - by [HHT]DRON - 04.04.2012, 13:45
Re: SERVER: Unknown command - by ViniBorn - 04.04.2012, 14:45
Re: SERVER: Unknown command - by AndreT - 04.04.2012, 15:44
Re: SERVER: Unknown command - by [HHT]DRON - 05.04.2012, 10:51

Forum Jump:


Users browsing this thread: 1 Guest(s)