Limit a player to a certain amount of characters when using a command[+REP]
#8

I only did the first few, I don't get paid enough to do the full 300+ lines.
pawn Код:
COMMAND:car(playerid, params[])
{
    if(!IsPlayerInAnyVehicle(playerid))
        return SendClientError(playerid, "You are not in any vehicle!");
    if(!strlen(params))
        return SCP(playerid, "[ buy / sell / unsell / park / lock / help / tow / find / respray / savemod / unmod / dupekey / takekey / factionize / scrap / paintjob / nitro / plate / control ]");

    new tmp2, tmp3;
    if(!sscanf(params, "'respray'ii", tmp2, tmp3))
    {
        if(PlayerTemp[playerid][sm] < dini_Int("Pay_N_Spray.txt", "entrance"))
            return SendClientError(playerid, "Not enough money!");
           
        new vid = GetPlayerVehicleID(playerid);
        if(strlen(Vehicles[vid][carowner] && strcmp(PlayerName(playerid), Vehicles[vid][carowner], false))
            return SendClientError(playerid, "You do not own this vehicle!");

        new bizz = IsPlayerOutBiz(playerid);
        if(bizz != -1 && biz[bizz][biztype] == 11)
        {
            if(!(0 <= tmp2 <= 255 && 0 <= tmp3 <= 255))
                return SendClientWarning(playerid, "Invalid colour ID!");
            dini_IntSet(CarFile(vid), "color1", tmp2);
            dini_IntSet(CarFile(vid), "color2", tmp3);
            ChangeVehicleColor(vid, tmp2, tmp3);
            Vehicles[vid][color1] = tmp2;
            Vehicles[vid][color2] = tmp3;
            GameTextForPlayer(playerid, "~g~resprayed", 3000, 1);
            GivePlayerMoneyEx(playerid, -dini_Int("Pay_N_Spray.txt", "entrance"));
            dini_IntSet("Pay_N_Spray.txt", "bizcash", dini_Int("Pay_N_Spray.txt", "bizcash") + dini_Int("Pay_N_Spray.txt", "entrance"));
            dini_IntSet("Pay_N_Spray.txt", "comps", dini_Int("Pay_N_Spray.txt", "comps") - 2);
            //GivePlayerMoneyEx(playerid, -dini_Int("Pay_N_Spray.txt", "entrance"));
            //dini_IntSet("Pay_N_Spray.txt", "bizcash", dini_Int("Pay_N_Spray.txt", "bizcash") + dini_Int("Pay_N_Spray.txt", "entrance"));
            //dini_IntSet("Pay_N_Spray.txt", "comps", dini_Int("Pay_N_Spray.txt", "comps") - 2);
            format(iStr, sizeof(iStr), "6[VEHICLE] %s has resprayed their %s to %d and %d for $%d.", PlayerName(playerid), GetVehicleName(vid), tmp2, tmp3, dini_Int("Pay_N_Spray.txt", "entrance"));
            iEcho(iStr);
        }
        // else...?
        return 1;
    }
    else if(!strcmp(params, "neon", true))
    {
        if(PlayerTemp[playerid][sm] < dini_Int("Car_Neon.txt", "entrance"))
            return SendClientError(playerid, "Not enough money!");

        new bizz = IsPlayerOutBiz(playerid);
        if(bizz != -1 && biz[bizz][biztype] == 25)
        {
            GivePlayerMoneyEx(playerid, -dini_Int("Car_Neon.txt", "entrance"));
            dini_IntSet("Car_Neon.txt", "bizcash", dini_Int("Car_Neon.txt", "bizcash") + dini_Int("Car_Neon.txt", "entrance"));
            dini_IntSet("Car_Neon.txt", "cmps", dini_Int("Car_Neon.txt", "comps") - 2);
            format(iStr, sizeof(iStr), "6[VEHICLE] %s has instaled neon on their %s for $%d.", PlayerName(playerid), GetVehicleName(GetPlayerVehicleID(playerid)), dini_Int("Car_Neon.txt", "entrance"));
            iEcho(iStr);
            ShowPlayerDialog(playerid, 52, DIALOG_STYLE_LIST, "{FFFF00} Car Neon", "DarkBlue\nRed\nGreen\nWhite\nViolet\nYellow\nCyan\nLightBlue\nPink\nOrange\nLightGreen\nLightYellow\nDelete Neon", "Select", "Cancel");
        }
        return 1;
    }
    else if(!strcmp(params, "control", true))
    {
        ShowPlayerDialog(playerid, 50, DIALOG_STYLE_LIST, "{FFFF00} Car Control", "Lighting   [ On / Off ]\nBonnect   [ Open / Close ]\nBoot/Trunk   [ Open / Close ]", "Select", "Cancel");
        return 1;
    }
    else if(!strcmp(params, "plate", true))
    {
        if(PlayerInfo[playerid][premium])
            return SendClientError(playerid, CANT_USE_CMD);
        ShowPlayerDialog(playerid, 45, DIALOG_STYLE_INPUT,"{FFFF00} Plate Registration", "{ea150a}What should the {17a005}plate {ffffff}be?", "{ffffff}Set", " ");
        return 1;
    }
// etc.
If you continue with that format, you'll eventually get to a command where you're not relying on so many variables and string comparisons.

If the parameter requires additional parameters (i.e. "respray" or "paintjob" etc.), then use sscanf lines. If you don't require any more than 1 parameter, use strcmp.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)