06.03.2010, 01:26
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
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?
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?