SA-MP Forums Archive
How to structure this command properly? - 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: How to structure this command properly? (/showthread.php?tid=405808)



How to structure this command properly? - NinjaChicken - 08.01.2013

im a nub scripter what is the correct layout of this?

pawn Код:
CMD:goldrims(playerid, params[])
{
    if(PlayerInfo[playerid][pRGoldRims] > 0)
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "Error: You don't have any gold rims, buy them of a craftsman");
    }
    if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, 0xFFFFFFFF, "You are not driving a vehicle.");
    AddVehicleComponent(GetPlayerVehicleID(playerid),1080);
    SendClientMessage(playerid, 0xFFFFFFFF, "You have added gold rims to your vehicle.");
    PlayerInfo[playerid][pGoldRims]--;
    return 1;
}



Re: How to structure this command properly? - Black Wolf - 08.01.2013

Nothing's wrong its perfect.


Re: How to structure this command properly? - [HK]Ryder[AN] - 08.01.2013

I guess, theres a problem in the first "if" statement.
You are checking that if a player's goldrims are GREATER than 0 then he CANT use the cmd. I guess it should be
pawn Код:
CMD:goldrims(playerid, params[])
{
    if(PlayerInfo[playerid][pRGoldRims] == 0)
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "Error: You don't have any gold rims, buy them of a craftsman");
    }
    if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, 0xFFFFFFFF, "You are not driving a vehicle.");
    AddVehicleComponent(GetPlayerVehicleID(playerid),1080);
    SendClientMessage(playerid, 0xFFFFFFFF, "You have added gold rims to your vehicle.");
    PlayerInfo[playerid][pGoldRims]--;
    return 1;
}



Re: How to structure this command properly? - papedo - 08.01.2013

Quote:
Originally Posted by NinjaChicken
Посмотреть сообщение
im a nub scripter what is the correct layout of this?

pawn Код:
CMD:goldrims(playerid, params[])
{
    if(PlayerInfo[playerid][pRGoldRims] > 0)
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "Error: You don't have any gold rims, buy them of a craftsman");
    }
    if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, 0xFFFFFFFF, "You are not driving a vehicle.");
    AddVehicleComponent(GetPlayerVehicleID(playerid),1080);
    SendClientMessage(playerid, 0xFFFFFFFF, "You have added gold rims to your vehicle.");
    PlayerInfo[playerid][pGoldRims]--;
    return 1;
}
pawn Код:
CMD:goldrims(playerid, params[])
{
    if(PlayerInfo[playerid][pRGoldRims] > 0)return SendClientMessage(playerid, 0xFFFFFFFF, "Error: You don't have any gold rims, buy them of a craftsman");
    if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, 0xFFFFFFFF, "You are not driving a vehicle.");
    new veh = GetPlayerVehicleID(playerid);
    new component = GetVehicleComponentInSlot(veh,CARMODTYPE_WHEELS);
    if(component == 1080) return SendClientMessage(playerid, 0xFFFFFFFF, "You allready have this component.");
    AddVehicleComponent(GetPlayerVehicleID(playerid),1080);
    SendClientMessage(playerid, 0xFFFFFFFF, "You have added gold rims to your vehicle.");
    PlayerInfo[playerid][pGoldRims]--;
    return 1;
}



Re: How to structure this command properly? - Jarnu - 08.01.2013

Proper (No bugs)
pawn Код:
CMD:goldrims(playerid, params[])
{
    if(PlayerInfo[playerid][pRGoldRims] > 0) //If player's gold rim amount is > (greater) than 0
    {
          if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) //If Player is driver...
          {
               AddVehicleComponent(GetPlayerVehicleID(playerid),1080);
               SendClientMessage(playerid, 0xFFFFFFFF, "You have added gold rims to your vehicle.");
               PlayerInfo[playerid][pGoldRims]--;
          }
          else return SendClientMessage(playerid, 0xFFFFFFFF, "You are not driving a vehicle."); //If player is not driver return error
     }
     else return SendClientMessage(playerid, 0xFF0000FF,"You don't have any gold rims buy before using this command!"); //if rims amount < (less than) 0, return error.
     return 1; //else return value. (true)
}



Re: How to structure this command properly? - Jarnu - 08.01.2013

Quote:
Originally Posted by ******
Посмотреть сообщение
I would say always use braces, even on the single line if statements, it makes things generally clearer and easier to modify.
Exactly, also, using "return" sometimes makes the command bugged if scripted badly.