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
#2

Well......
Reply
#3

Quote:
Originally Posted by Lilcuete
Well i know how add me and i will tell you lilweezy58@live.com
Are you that lonely?
Reply
#4

Quote:
Originally Posted by Eric_
Quote:
Originally Posted by Lilcuete
Well i know how add me and i will tell you lilweezy58@live.com
Are you that lonely?
He added me and told me to use "Strcmp" after telling me I need to use "CreateVehicle(blahblah"
And now he says this:
Quote:

XmINiX says:
I used Dcmd on purpose.. And I just wanted a more efficient way to load the price of each car
XmINiX says:
As you can see in my post I'm using a switch statement... But I don't want to go through every line of code with a new vehicle
lilcuete says:
I will do this den
lilcuete says:
Instead of puting all the if(
lilcuete says:
for the money
lilcuete says:
Use GivePlayerMoney
lilcuete says:
thats it
lilcuete says:
GivePlayerMoney(playerid, -27495);
lilcuete says:
like dat
XmINiX says:
No.

Reply
#5

Quote:
Originally Posted by Mini`
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?
Using switch and case is the best way IMO, but you can use vehicle names aswell, search for it in this forum.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)