Detecting names
#1

Hey!
So, I'm trying to make this system where I can type for example /car inf or /car infernus, or whatever to get a car.
The thing I'm stuck at, is when I tried to detect the text after the /car command.
Here's an example I tried.

pawn Код:
COMMAND:car(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        new id, nameofcar;
        if(sscanf(params, "us", id, nameofcar)) return SendClientMessage(playerid, RED, "USAGE /car <ID> <NameOfCar>");
        if(nameofcar == "infernus")
        {
        }
    }return 1;
}
Thanks, in advance.
Reply
#2

you cannot use '==' for string equations.
That's only for numbers and math.

For string comparision you use strcmp(string1,string2,ignorecase,lenght);
https://sampwiki.blast.hk/wiki/Strcmp

and btw in <id> instead of u , u can use d or i.
Reply
#3

Will this work if I use ZCMD?
Reply
#4

Yes. It definitly will work.
example:
pawn Код:
COMMAND:car(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        new id, nameofcar[32];// do not forget the array size!
        if(sscanf(params, "us", id, nameofcar)) return SendClientMessage(playerid, RED, "USAGE /car <ID> <NameOfCar>");
        if(!strcmp(nameofcar,"infernus",true))
        {
//do your code
        }
    }return 1;
}
if you want a car spawn script I have one.
Reply
#5

Well, thanks alot. I'll test it out .
Reply
#6

Well, I can't seem to figure it out, plus there is no example script on the wiki. Coul you "lend" me an example script?


EDIT: Crap, double post...
EDIT2: I don't think I can delete this post..
Reply
#7

I think something like this you mean?

pawn Код:
COMMAND:car(playerid, params[])
{
    new string[128];
    if(sscanf(params, "s[128]", params)) return SendClientMessage(playerid, RED, "USAGE /car <ID>");
    new carid = GetVehicleModelIDFromName(params);
    if(IsNumeric(params)) carid = strval(params);
    else carid = GetVehicleModelIDFromName(params);
    if(carid < 400 || carid > 611) return SendClientMessage(playerid, RED, "Invalid vehicle ID");
    else
    {
        format(string, 128, "Car ID: %d. Vehicle Name: %s", carid, aVehicleNames[carid - 400]);
        SendClientMessage(playerid, COLOR_GREEN, string);
    }
    return 1;
}
And paste these functions in your script http://pastebin.com/T3BfTY2Z
Reply
#8

here you go:
pawn Код:
new
    NazwyPojazdow[212][24] =
    {
        "Landstalker",
        "Bravura",
        "Buffalo",
        "Linerunner",
        "Pereniel",
        "Sentinel",
        "Dumper",
        "Firetruck",
        "Trashmaster",
        "Stretch",
        "Manana",
        "Infernus",
        "Voodoo",
        "Pony",
        "Mule",
        "Cheetah",
        "Ambulance",
        "Leviathan",
        "Moonbeam",
        "Esperanto",
        "Taxi",
        "Washington",
        "Bobcat",
        "MrWhoopee",
        "BFInjection",
        "Hunter",
        "Premier",
        "Enforcer",
        "Securicar",
        "Banshee",
        "Predator",
        "Bus",
        "Rhino",
        "Barracks",
        "Hotknife",
        "TrailerA",
        "Previon",
        "Coach",
        "Cabbie",
        "Stallion",
        "Rumpo",
        "RCBandit",
        "Romero",
        "Packer",
        "MonsterA",
        "Admiral",
        "Squalo",
        "Seasparrow",
        "Pizzaboy",
        "Tram",
        "TrailerB",
        "Turismo",
        "Speeder",
        "Reefer",
        "Tropic",
        "Flatbed",
        "Yankee",
        "Caddy",
        "Solair",
        "BerkleysRCVan",
        "Skimmer",
        "PCJ-600",
        "Faggio",
        "Freeway",
        "RCBaron",
        "RCRaider",
        "Glendale",
        "Oceanic",
        "Sanchez",
        "Sparrow",
        "Patriot",
        "Quad",
        "Coastguard",
        "Dinghy",
        "Hermes",
        "Sabre",
        "Rustler",
        "ZR350",
        "Walton",
        "Regina",
        "Comet",
        "BMX",
        "Burrito",
        "Camper",
        "Marquis",
        "Baggage",
        "Dozer",
        "Maverick",
        "newsChopper",
        "Rancher",
        "FBIRancher",
        "Virgo",
        "Greenwood",
        "Jetmax",
        "Hotring",
        "Sandking",
        "BlistaCompact",
        "PoliceMaverick",
        "Boxville",
        "Benson",
        "Mesa",
        "RCGoblin",
        "HotringRacer",
        "HotringRacer",
        "BloodringBanger",
        "Rancher",
        "SuperGT",
        "Elegant",
        "Journey",
        "Bike",
        "MountainBike",
        "Beagle",
        "Cropdust",
        "Stunt",
        "Tanker",
        "RoadTrain",
        "Nebula",
        "Majestic",
        "Buccaneer",
        "Shamal",
        "Hydra",
        "FCR-900",
        "NRG-500",
        "HPV1000",
        "CementTruck",
        "TowTruck",
        "Fortune",
        "Cadrona",
        "FBITruck",
        "Willard",
        "Forklift",
        "Tractor",
        "Combine",
        "Feltzer",
        "Remington",
        "Slamvan",
        "Blade",
        "Freight",
        "Streak",
        "Vortex",
        "Vincent",
        "Bullet",
        "Clover",
        "Sadler",
        "Firetruck",
        "Hustler",
        "Intruder",
        "Primo",
        "Cargobob",
        "Tampa",
        "Sunrise",
        "Merit",
        "Utility",
        "Nevada",
        "Yosemite",
        "Windsor",
        "MonsterB",
        "MonsterC",
        "Uranus",
        "Jester",
        "Sultan",
        "Stratum",
        "Elegy",
        "Raindance",
        "RCTiger",
        "Flash",
        "Tahoma",
        "Savanna",
        "Bandito",
        "Freight",
        "TrailerC",
        "Kart",
        "Mower",
        "Duneride",
        "Sweeper",
        "Broadway",
        "Tornado",
        "AT-400",
        "DFT-30",
        "Huntley",
        "Stafford",
        "BF-400",
        "newsvan",
        "Tug",
        "TrailerD",
        "Emperor",
        "Wayfarer",
        "Euros",
        "Hotdog",
        "Club",
        "TrailerE",
        "TrailerF",
        "Andromada",
        "Dodo",
        "RCCam",
        "Launch",
        "CopCatLS",
        "CopCarSF",
        "CopCarLV",
        "PoliceRanger",
        "Picador",
        "S.W.A.T.Van",
        "Alpha",
        "Phoenix",
        "Glendale",
        "Sadler",
        "LuggageTrailerA",
        "LuggageTrailerB",
        "StairTrailer",
        "Boxville",
        "FarmPlow",
        "UtilityTrailer"
    }
;
   
COMMAND:v(playerid,params[])
{

    new tmp[64];
    if(sscanf(params,"s",tmp))return SendClientMessage(playerid, 0xFFFFFFFF, "USE: /v [Vehicle Name/ID]");

    new val = 0;
   
    if(IsNumeric(tmp))
    {
        val = strval(tmp);
        goto ISNUMBER;
    }

    for(new i = 0; i < 211; i++)
    {
        if(strfind(NazwyPojazdow[i], tmp, true) != -1)
        {
            i += 400;

            ISNUMBER:

            if(val != 0)
            {
                i = val;
            }

            if(i < 400 || i > 611) return SendClientMessage(playerid, 0xFF0000FF, "* ERROR: BAD VEHICLE ID");

            /*
            if(!IsPlayerAdmin2(playerid))
            {
                if(i == 432 || i == 520 || i == 538 || i == 570 || i == 569 || i == 425)
                {
                    SendClientMessage(playerid,CWARN,"You are not allowed to spawn this vehicle!");
                    return 1;
                }
            }
            */


            new
                Float:X,
                Float:Y,
                Float:Z,
                Float:Angle,
                PlayerVeh;

            GetPlayerPos(playerid, X, Y, Z);
            GetPlayerFacingAngle(playerid, Angle);

            PlayerVeh = CreateVehicle(i, X , Y, Z + 1 , Angle, random(126), random(126), 9999999);

            LinkVehicleToInterior(PlayerVeh, GetPlayerInterior(playerid));
            SetVehicleVirtualWorld(PlayerVeh, GetPlayerVirtualWorld(playerid));

            if(!IsPlayerInAnyVehicle(playerid)) PutPlayerInVehicle(playerid,PlayerVeh,0);

            SendClientFormatMessage(playerid, 0xFFFFFFFF, "** You have spawned a/an %s! (modelID: %d)(vehicleID: %d)", NazwyPojazdow[i - 400],i,PlayerVeh);

            return 1;
        }

        return 1;
    }

    SendClientMessage(playerid,0xFF0000FF,"Car not found!");
    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;
}
just paste this into your script.
It's an edit but it should work.. from my gm
Reply
#9

rubygta do you want to spawn a vehicle with name? Or do you want to found out a car name by typing a car ID?
Reply
#10

he wants to do with ID i think but I made one for ID & Name in my previous post so we don't need to worry about that xD
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)