16.05.2014, 16:32
Why don't you just use strfind for it?
PS: Vehicles array has size of 210 and there are currently 212 vehicles.
pawn Код:
CMD:car(playerid, params[])
{
if (!IsPlayerAdmin(playerid) && !PlayerInfo[playerid][AdminLevel]) return SendClientMessage(playerid, COLOR_ERROR, "Error: You are not authorized to use this command.");
new car[25], color1, color2;
if (sscanf(params, "s[25]dd", car, color1, color2)) return SendClientMessage(playerid, COLOR_USAGE, "USAGE: {ABABAB}/car [car name/id] [color 1] [color 2]");
if (!(0 <= color1 <= 255) || !(0 <= color2 <= 255)) return SendClientMessage(playerid, COLOR_ERROR, "Error: Color number must be between 0 and 255.");
new modelid;
if (IsNumeric(car)) modelid = strval(car);
else modelid = GetVehicleModelFromName(car);
if (!(400 <= modelid <= 611)) return SendClientMessage(playerid, COLOR_ERROR, "Error: Invalid vehicle name or vehicle modelid");
new Float:x, Float:y, Float:z, Float:a;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
CreateVehicle(modelid, x+2, y, z, a, color1, color2, -1);
return 1;
}
GetVehicleModelFromName(const veh_name[])
{
for (new i; i != sizeof (Vehicles); ++i)
{
if (strfind(Vehicles[i], veh_name, true) != -1) return i + 400;
}
return -1;
}
IsNumeric(const string[])
{
for (new i = 0, j = strlen(string); i < j; i++)
{
if (string[i] > '9' || string[i] < '0') return 0;
}
return 1;
}