/car command, works with car IDs, but not with car names.
#1

Thanks for putting some time aside and reading this.

So, here's my code:
pawn Код:
GetVehicleFromName(string[], playerid, Float:x, Float:y, Float:z, Float:a, color1, color2)
{
    new var[20];
    new vehid;
    new countForMe, CountFor;
    for(new pp = 0; pp < 210; pp++)
    {
        countForMe = 0;
        format(var, sizeof(var), "%s", Vehicles[pp+400]);
        for(i = 0; i < sizeof(var)+1; i++)
        {
            if(strcmp(var[i], string[i], true) == 0)
            {
                countForMe++;
            }
            if(countForMe > CountFor)
            {
                vehid = pp + 400;
            }
        }
    }
    if(vehid == 0) return SendClientMessage(playerid, COLOR_ERROR, "Error: The vehicle name you chose does not exist.");
    CreateVehicle(vehid, x+3, y, z, a, color1, color2, -1);
    return 1;
}




IsNumeric(const string[])
{
    new j;
    for ( i = 0, j = strlen(string); i < j; i++)
    {
        if (string[i] > '9' || string[i] < '0') return 0;
    }
    IsNumber = 1;
    return 1;
}
       


CMD:car(playerid, params[])
{
    IsNumber = 0;
    new car[20], color1, color2;
    if(!IsPlayerAdmin(playerid) && PlayerInfo[playerid][AdminLevel] == 0) return SendClientMessage(playerid, COLOR_ERROR, "Error: You are not authorized to use this command.");
    if(sscanf(params, "s[20]dd", car, color1, color2)) return SendClientMessage(playerid, COLOR_USAGE, "USAGE: {ABABAB}/car [car name/id] [color 1] [color 2]");
    if(color1 < 0 || color1 > 255 || color2 < 0 || color2 > 255) return SendClientMessage(playerid, COLOR_ERROR, "Error: Color number must be between 0 and 255.");
    new Float:x, Float:y, Float:z, Float:a;
    GetPlayerPos(playerid, x, y, z);
    GetPlayerFacingAngle(playerid, a);
   
    IsNumeric(car);
    if(IsNumber == 1)
    {
        if(strval(car) < 400 || strval(car) > 610) return SendClientMessage(playerid, COLOR_ERROR, "Error: You must select an ID between 400 and 610.");
        CreateVehicle(strval(car), x+2, y, z, a, color1, color2, -1);
    }
    else
    {
        GetVehicleFromName(car, playerid, x, y, z, a, color1, color2);
    }

    return 1;
}
When I use /car and put a vehicle name it says command unknown.

EDIT: I used some different variations of /car command and GetVehicleFromName or whatever it was, none worked.
Reply
#2

You need a list of all the cars, and not only the car nummbers. A list with the names.
Reply
#3

Forgot to upload it, sec, I have it.
pawn Код:
new Vehicles[210][25] = {{"Landstalker"}, {"Bravura"}, {"Buffalo"}, {"Linerunner"}, {"Perenniel"}, {"Sentinel"}, {"Dumper"},  {"Firetruck"},
{"Trashmaster"}, {"Stretch"}, {"Manana"}, {"Infernus"}, {"Voodoo"}, {"Pony"}, {"Mule"}, {"Cheetah"}, {"Ambulance"}, {"Leviathan"}, {"Moonbeam"},
{"Esperanto"}, {"Taxi"}, {"Washington"}, {"Bobcat"}, {"Mr.Whoopee"}, {"BF Injection"}, {"Hunter"}, {"Premier"}, {"Enforcer"}, {"Securicar"},
{"Banshee"}, {"Predator"}, {"Bus"}, {"Rhino"}, {"Barracks"}, {"Hotknife"}, {"Article Trailer"}, {"Previon"}, {"Coach"}, {"Cabbie"}, {"Stallion"},
{"Rumpo"}, {"RC Bandit"}, {"Romero"}, {"Packer"}, {"Monster"}, {"Admiral"}, {"Squallo"}, {"Seasparrow"}, {"Pizzaboy"}, {"Tram"}, {"Article Trailer 2"},
{"Turismo"}, {"Speeder"}, {"Reefer"}, {"Tropic"}, {"Flatbed"}, {"Yankee"}, {"Caddy"}, {"Solair"}, {"Topfun Van"}, {"Skimmer"}, {"PCJ-600"}, {"Faggio"},
{"Freeway"}, {"RC Baron"}, {"RC Raider"}, {"Glendale"}, {"Oceanic"}, {"Sanchez"}, {"Sparrow"}, {"Patriot"}, {"Quad"}, {"Coastguard"}, {"Dinghy"}, {"Hermes"},
{"Sabre"}, {"Rustler"}, {"ZR-350"}, {"Walton"}, {"Regina"}, {"BMX"}, {"Burrito"}, {"Camper"}, {"Marquis"}, {"Baggage"}, {"Dozer"}, {"Maverick"},
{"SAN News Maverick"},{"Rancher"}, {"FBI Rancher"}, {"Virgo"}, {"Greenwood"}, {"Jetmax"}, {"Hotring Racer A"}, {"Sandking"}, {"Blista Compact"},
{"Police Maverick"}, {"Boxville"},{"Benson"}, {"Mesa"}, {"RC Goblin"}, {"Hotring Racer B"}, {"Hotring Racer C"}, {"Rancher"}, {"Super GT"}, {"Elegant"},
{"Journey"}, {"Normal Bike"},{"Mountain Bike"}, {"Beagle"}, {"Cropduster"}, {"Stuntplane"}, {"Tanker"}, {"Roadtrain"}, {"Nebula"}, {"Majestic"}, {"Buccaneer"},
{"Shamal"}, {"Hydra"}, {"FCR-900"}, {"NRG-500"}, {"HPV1000"}, {"Cement Truck"}, {"Tow Truck"}, {"Fortune"}, {"Cadrona"}, {"FBI Truck"}, {"Willard"},
{"Forklift"}, {"Tractor"}, {"Combine Harvester"}, {"Feltzer"}, {"Remington"}, {"Slamvan"}, {"Blade"}, {"Freight"}, {"Brownstreak"}, {"Vortex"}, {"Vincent"},
{"Bullet"}, {"Clover"}, {"Sadler"}, {"Firetruck"}, {"Hustler"}, {"Intruder"}, {"Primo"}, {"Cargobob"}, {"Tampa"}, {"Sunrise"}, {"Merit"},
{"Utility Van"}, {"Nevada"}, {"Yosemite"}, {"Windsor"}, {"Monster A"}, {"Monster B"}, {"Uranus"}, {"Jester"}, {"Sultan"}, {"Stratum"}, {"Elegy"},
{"Raindance"}, {"RC Tiger"}, {"Flash"}, {"Tahoma"}, {"Savanna"}, {"Bandito"}, {"Freight Flat Trailer"}, {"Streak Trailer"}, {"Kart"}, {"Mower"}, {"Dune"},
{"Sweeper"}, {"Broadway"}, {"Tornado"}, {"AT400"}, {"DFT-30"}, {"Huntley"}, {"Stafford"}, {"BF-400"}, {"Newsvan"}, {"Tug"}, {"Petrol Trailer"},
{"Emperor"}, {"Wayfarer"}, {"Euros"}, {"Hotdog"}, {"Club"}, {"Freight Box Trailer"}, {"Article Trailer 3"}, {"Andromada"}, {"Dodo"}, {"RC Cam"}, {"Launch"},
{"LSPD Police Car"}, {"SFPD Police Car"}, {"LVPD Police Car"}, {"Police Ranger"}, {"Picador"}, {"S.W.A.T."}, {"Alpha"}, {"Phoenix"}, {"Glendale Shit"},
{"Sadler Shit"}, {"Baggage Trailer A"}, {"Baggage Trailer B"}, {"Tug Stairs Trailer"}, {"Boxville"}, {"Farm Trailer"}, {"Utility Trailer"}};
EDIT: Nope, I didn't.
Reply
#4

Why don't you just use strfind for it?

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;
}
PS: Vehicles array has size of 210 and there are currently 212 vehicles.
Reply
#5

Because I forgot that function! I returned scripting a few days ago. And when I was 'searching in my head' for a function to be able to check if the two cells have the same value, I couldn't think of anything other than strcmp. I even ******d. Anyway, thank you, that should do the trick. I'll let you know if it doesn't.


EDIT: It's working, and ye, I must've missed 2 vehicles while copying it. Such a huge fail (I knew there were 212 but was too lazy to search which ones were missing. XD)(I'll fix that later, not in a rush tbh) +rep
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)