SA-MP Forums Archive
Cleaning up my command - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Cleaning up my command (/showthread.php?tid=258673)



Cleaning up my command - bartje01 - 31.05.2011

Hey everyone. I started scripting again, it's just so much fun.
I need someone to clean up my command if that's possible and if it''s needed
I made this command:

pawn Код:
COMMAND:takewood(playerid,params[])
{
    new amount,string[70];
    if(IsPlayerInRangeOfPoint(playerid, 7.0, 1018.5685,-2195.3081,37.7154))
    {
    if(PlayerInfo[playerid][Job] != Woodjob) return SendClientMessage(playerid,COLOR_RED,"You're not a wood deliverer.");
    if(sscanf(params,"d",amount)) return SendClientMessage(playerid,COLOR_GREY,"USAGE:/pickwood [amount] 10$ each");
    if(amount >100) return SendClientMessage(playerid,COLOR_RED,"Value must be between 1-100");
    if(amount <1) return SendClientMessage(playerid,COLOR_RED,"Value must be between 1-100");
    if(PlayerInfo[playerid][pCash] <10*amount) return SendClientMessage(playerid,COLOR_RED,"You don't have enough money.");
    if(PlayerInfo[playerid][Wood] + amount > 5 && PlayerInfo[playerid][pScore] <5) return SendClientMessage(playerid,COLOR_RED,"You need atleast 5 score to cary more then 5 wood.");
    PlayerInfo[playerid][Wood] += amount;
    PlayerInfo[playerid][pCash] -= amount*10;
    format(string,sizeof(string),"You've bought %d wood for $%d",amount,amount*10);
    SendClientMessage(playerid,COLOR_YELLOW,string);
    SendClientMessage(playerid,COLOR_YELLOW,"Bring them to the dropoff point at the docs.");
    }
    else
    {
    SendClientMessage(playerid,COLOR_RED,"You're not at the pickup point");
    }
    return 1;
}
It works excellent.
The problem is that I think that I could've scripted this on a better and decent way.
Can anybody clean up my command please?

Thanks


Re: Cleaning up my command - Laronic - 31.05.2011

Maybe
pawn Код:
COMMAND:takewood(playerid, params[])
{
    new amount, string[70];
    if(sscanf(params, "d", amount)) return SendClientMessage(playerid, COLOR_GREY, "USAGE:/pickwood [amount] 10$ each");
    {
        if(!IsPlayerInRangeOfPoint(playerid, 7.0, 1018.5685, -2195.3081, 37.7154)) return SendClientMessage(playerid, COLOR_RED, "You're not at the pickup point");
        else if(amount <= 0 || amount => 101) return SendClientMessage(playerid, COLOR_RED, "Value must be between 1-100");
        else if(PlayerInfo[playerid][Job] != Woodjob) return SendClientMessage(playerid, COLOR_RED, "You're not a wood deliverer.");
        else if(PlayerInfo[playerid][pCash] < 10 * amount) return SendClientMessage(playerid, COLOR_RED, "You don't have enough money.");
        else if(PlayerInfo[playerid][Wood] + amount > 5 && PlayerInfo[playerid][pScore] < 5) return SendClientMessage(playerid, COLOR_RED, "You need atleast 5 score to cary more then 5 wood.");
        {
            PlayerInfo[playerid][Wood] += amount;
            PlayerInfo[playerid][pCash] -= amount * 10;
           
            format(string, sizeof(string), "You've bought %d wood for $%d", amount, amount * 10);
            SendClientMessage(playerid, COLOR_YELLOW, string);
           
            SendClientMessage(playerid, COLOR_YELLOW, "Bring them to the dropoff point at the docs.");
        }
    }
    return 1;
}



Re: Cleaning up my command - bartje01 - 31.05.2011

Allright, thanks. But did mine look decent enough?


Re: Cleaning up my command - Steven82 - 31.05.2011

Quote:
Originally Posted by bartje01
Посмотреть сообщение
Allright, thanks. But did mine look decent enough?
Every programmer/coder/script whatever you want to call it, has their own scripting style. You may not like to indent, while the code he cleaned out was nicely indented just things like that is what make personal coding unique. But it looked decent as far as optimization, i'm no expert or anything with optimization so maybe someone else can help you on that one.