Car spawn via car name?
#1

So, I have this command, which works, spawning the car via the vehicle id, however, I want to use the vehicle name instead.

pawn Код:
CMD:v(playerid, params[])
    {
        new
            toid,
            carid,
            color1,
            color2;
           
        if(pInfo[playerid][Admin] > 1){

             if(!sscanf(params, "iiii", toid, carid, color1, color2)) {
               
                if(IsPlayerConnected(toid)){
                    if(carid >399 && carid < 612){
                    new
                        Float: curX,
                        Float: curY,
                        Float: curZ,
                        Float: curR;
                       
                    GetPlayerPos(toid, curX, curY, curZ);
                    GetPlayerFacingAngle(playerid, curR);
                    CreateVehicle(carid, curX+1, curY+1, curZ, curR, color1, color2, -1);
                       
                    new MessageToSender[128];
                    new MessageToReciever[128];
                    new allmessage[128];
                    new SenderName[25];
                    new RecieverName[25];
                       
                    GetPlayerName(playerid, SenderName, 18);
                    GetPlayerName(toid, RecieverName, 18);
                       
                    format(MessageToSender, sizeof(MessageToSender), "Car '%s' sent to %s.",  GetVehicleName(carid), RecieverName);
                    format(MessageToReciever, sizeof(MessageToReciever), "%s has just spawned you a car (%s).", SenderName, GetVehicleName(carid));
                    format(allmessage, sizeof(allmessage), "%s has sent a(n) %s to %s!", SenderName, GetVehicleName(carid), RecieverName);
                    SendClientMessage(playerid, COLOR_LIGHTPINK, MessageToSender);
                    SendClientMessage(toid, COLOR_LIGHTPINK, MessageToReciever);
                    SendClientMessageToAllButTwo(playerid, toid, COLOR_LIGHTPINK, allmessage);
                   
                    return true;

                    } else {
                        new errorstring[128];
                        format(errorstring, sizeof(errorstring), "ERROR: %i is not a valid car id!", carid);
                        SendClientMessage(playerid, COLOR_LIGHTPINK, errorstring);
                    }
                   
                } else {
                    new errorstring[128];
                    format(errorstring, sizeof(errorstring), "ERROR: %i is not a valid player!", toid);
                    SendClientMessage(playerid, COLOR_LIGHTPINK, errorstring);
                }

             } else {
                SendClientMessage(playerid, -1, "USAGE: /v [playerid] [car] [color1] [color2]");
             }

        } else {
            SendClientMessage(playerid, COLOR_LIGHTBLUE, "You don't have access to this command.");
        }
        return 1;
    }
Now, Can I do it somehow with an array like this?
pawn Код:
new VehicleNames[][] =
{
    "Landstalker", "Bravura", "Buffalo", "Linerunner", "Perrenial", "Sentinel",
    "Dumper", "Firetruck", "Trashmaster", "Stretch", "Manana", "Infernus",
    "Voodoo", "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam",
    "Esperanto", "Taxi", "Washington", "Bobcat", "Whoopee", "BF Injection",
    "Hunter", "Premier", "Enforcer", "Securicar", "Banshee", "Predator", "Bus",
    "Rhino", "Barracks", "Hotknife", "Trailer", "Previon", "Coach", "Cabbie",
    "Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster", "Admiral",
    "Squalo", "Seasparrow", "Pizzaboy", "Tram", "Trailer", "Turismo", "Speeder",
    "Reefer", "Tropic", "Flatbed", "Yankee", "Caddy", "Solair", "Berkley's RC 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", "Comet", "BMX",
    "Burrito", "Camper", "Marquis", "Baggage", "Dozer", "Maverick", "News Chopper",
    "Rancher", "FBI Rancher", "Virgo", "Greenwood", "Jetmax", "Hotring", "Sandking",
    "Blista Compact", "Police Maverick", "Boxville", "Benson", "Mesa", "RC Goblin",
    "Hotring Racer A", "Hotring Racer B", "Bloodring Banger", "Rancher", "Super GT",
    "Elegant", "Journey", "Bike", "Mountain Bike", "Beagle", "Cropduster", "Stunt",
    "Tanker", "Roadtrain", "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra",
    "FCR-900", "NRG-500", "HPV1000", "Cement Truck", "Tow Truck", "Fortune",
    "Cadrona", "FBI Truck", "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", "Monster", "Monster", "Uranus", "Jester", "Sultan", "Stratium",
    "Elegy", "Raindance", "RC Tiger", "Flash", "Tahoma", "Savanna", "Bandito",
    "Freight Flat", "Streak Carriage", "Kart", "Mower", "Dune", "Sweeper",
    "Broadway", "Tornado", "AT-400", "DFT-30", "Huntley", "Stafford", "BF-400",
    "News Van", "Tug", "Trailer", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club",
    "Freight Box", "Trailer", "Andromada", "Dodo", "RC Cam", "Launch", "Police Car",
    "Police Car", "Police Car", "Police Ranger", "Picador", "S.W.A.T", "Alpha",
    "Phoenix", "Glendale", "Sadler", "Luggage", "Luggage", "Stairs", "Boxville",
    "Tiller", "Utility Trailer"
};
The current script takes the id, and then looks in the array for the car name, can I reverse that and make the command paramaters a string (for vehicleid), and two integers (for colors) and grab the ID (slot of the array) from the vehicle name? Or what is the easiest way of doing it?
Reply


Messages In This Thread
Car spawn via car name? - by Nathan_Taylor - 06.03.2013, 23:18
Re: Car spawn via car name? - by Jefff - 06.03.2013, 23:50
Re: Car spawn via car name? - by MP2 - 07.03.2013, 00:00
Re: Car spawn via car name? - by Nathan_Taylor - 07.03.2013, 00:39
Re: Car spawn via car name? - by Nathan_Taylor - 07.03.2013, 00:47
Re: Car spawn via car name? - by MP2 - 07.03.2013, 00:49

Forum Jump:


Users browsing this thread: 2 Guest(s)