Need some help..
#1

I'm not sure how the big servers do it, with their /buyvehicle commands, so I'm here to ask you. What is the most efficient way to load a /buyvehicle command? By the way, I'm talking about /buyvehicle model color1 color2

pawn Код:
dcmd_buyvehicle(playerid, params[])
{
    new
        modelid,
        color1,
        color2;
    if (sscanf(params, "iii", modelid, color1, color2)) SendClientMessage(playerid, COLOR_WHITE, "Usage: /buyvehicle <modelid> <color1> <color2>");
    else if (modelid == 0) SendClientMessage(playerid, 0xFF0000AA, "[ERROR:] You typed '0'.");
    else
    {
    switch (modelid)
    {
        case 411,415,429,477:
        {
        if(GetPlayerCash(playerid) == 200000)
        {
        GivePlayerCash(playerid, -200000);
        } else {
        SendClientMessage(playerid, COLOR_RED, "[ERROR:] You do not have this much money!");
        return 1;
        }
        }
        case 525:
        {
        if(GetPlayerCash(playerid) == 20000)
        {
        GivePlayerCash(playerid, -20000);
        } else {
        SendClientMessage(playerid, COLOR_RED, "[ERROR:] You do not have this much money!");
        return 1;
        }
        }
        case 402,405,439,445,550,559,560,562:
        {
        if(GetPlayerCash(playerid) == 125000)
        {
        GivePlayerCash(playerid, -125000);
        } else {
        SendClientMessage(playerid, COLOR_RED, "[ERROR:] You do not have this much money!");
        return 1;
        }
        }
        case 451,541:
        {
        if(GetPlayerCash(playerid) == 295000)
        {
        GivePlayerCash(playerid, -295000);
        } else {
        SendClientMessage(playerid, COLOR_RED, "[ERROR:] You do not have this much money!");
        return 1;
        }
        }
        case 475,579,603:
        {
        if(GetPlayerCash(playerid) == 72000)
        {
        GivePlayerCash(playerid, -72000);
        } else {
        SendClientMessage(playerid, COLOR_RED, "[ERROR:] You do not have this much money!");
        return 1;
        }
        }
        default:
        {
        SendClientMessage(playerid, COLOR_RED, "[ERROR:] This car cannot be bought yet, if you need it, talk to an admin");
        SendClientMessage(playerid, COLOR_WHITE, "[HINT:] Check the forums for a complete list of vehicles and prices!");
        return 1;
        }
    }
    new playervehicleid = GetPlayerFreeVehicleId(playerid);
    if(playervehicleid == -1) return SendClientMessage(playerid, COLOR_RED, "[ERROR:] You already have the max number of cars.");
    CreatePlayerVehicle(playerid, playervehicleid, modelid, 2119.1, -1152.6, 24.5, 4.0, color1, color2);
    }
    return 1;
}

As you can see it uses a switch statement at the moment (Ignore the sloppy If statements for money, I did that for a quick fix.)
I don't necessarily want to go through all the cars that people would want, using cases. So what would be a fast efficient way to code this?
Reply


Messages In This Thread
Need some help.. - by Mini` - 06.03.2010, 01:26
Re: Need some help.. - by Lilcuete - 06.03.2010, 01:34
Re: Need some help.. - by Eazy_Efolife - 06.03.2010, 01:46
Re: Need some help.. - by Mini` - 06.03.2010, 01:50
Re: Need some help.. - by Miguel - 06.03.2010, 02:51

Forum Jump:


Users browsing this thread: 2 Guest(s)