[+REP] /createcar command
#1

Hello everyone, so I wanted to make a command for admins to create cars.. here is the usage:

/createcar [VEHICLE_NAME]

So my question is.. how to check if the Vehicle Name the player typed is valid and how to find the model id of that vehicle name?

Thanks for reading.
I need help asap.
Reply
#2

Код:
const 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"
};

GetVehicleModelFromName(vehicle_name[])
{
    new vehicleid = -1;
    if (sscanf(vehicle_name, "i", vehicleid))
    {
        for (new i = 0; i < sizeof (VehicleNames); i++)
        {
            if (strfind(VehicleNames[i], vehicle_name, true) != -1)
            {
                vehicleid = i + 400;
            }
        }
    }
    else if (!(400 <= vehicleid <= 611)) vehicleid = -1;
    return vehicleid;
}
And then just use GetVehicleModelFromName.
If you're not using sscanf, you should start doing that. It's very fast and makes stuff easier.
It returns -1 if the vehicle is invalid.
Reply
#3

Quote:
Originally Posted by Stinged
Посмотреть сообщение
Код:
const 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"
};

GetVehicleModelFromName(vehicle_name[])
{
    new vehicleid = -1;
    if (sscanf(vehicle_name, "i", vehicleid))
    {
        for (new i = 0; i < sizeof (VehicleNames); i++)
        {
            if (strfind(VehicleNames[i], vehicle_name, true) != -1)
            {
                vehicleid = i + 400;
            }
        }
    }
    else if (!(400 <= vehicleid <= 611)) vehicleid = -1;
    return vehicleid;
}
And then just use GetVehicleModelFromName.
If you're not using sscanf, you should start doing that. It's very fast and makes stuff easier.
It returns -1 if the vehicle is invalid.
Thank you so much bro! +REP
Reply
#4

Well, I got some errors:

Код HTML:
C:\Program Files\ahmadCNR\pawno\include\required/new.inc(11) : error 001: expected token: "=", but found "["
C:\Program Files\ahmadCNR\pawno\include\required/new.inc(45) : error 010: invalid function or declaration
C:\Program Files\ahmadCNR\pawno\include\required/stocks.inc(709) : error 039: constant symbol has no size
C:\Program Files\ahmadCNR\pawno\include\required/stocks.inc(711) : error 028: invalid subscript (not an array or too many subscripts): "VehicleNames"
C:\Program Files\ahmadCNR\pawno\include\required/stocks.inc(711) : warning 215: expression has no effect
C:\Program Files\ahmadCNR\pawno\include\required/stocks.inc(711) : error 001: expected token: ";", but found "]"
C:\Program Files\ahmadCNR\pawno\include\required/stocks.inc(711) : error 029: invalid expression, assumed zero
C:\Program Files\ahmadCNR\pawno\include\required/stocks.inc(711) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


7 Errors.
Here's my command:
PHP код:
CMD:vehiclecreate(playeridparams[])
{
    if(!
IsAdminLevel(playerid3)) return NoPermsMSG(playerid);
    
    new 
carname[50];
    if(
sscanf(params"s[50]"carname)) return SendUsageMSG(playerid"/vehiclecreate [VEHICLE_NAME]");
    
    new 
carmodel GetVehicleModelFromName(carname);
    if(
carmodel == -1) return SendErrorMSG(playerid"Invalid vehicle name.");
    
    new 
Float:XFloat:YFloat:ZFloat:Amycar;
    
GetPlayerPos(playeridXYZ);
    
GetPlayerFacingAngle(playeridA);
    
mycar CreateVehicle(carmodelXYZ+2A, -1, -1, -1);
    
PutPlayerInVehicle(playeridmycar0);
    return 
1;

Reply
#5

Try changing this
Код:
const VehicleNames[][]
To this
Код:
new VehicleNames[][]
Reply
#6

Quote:
Originally Posted by Stinged
Посмотреть сообщение
Try changing this
Код:
const VehicleNames[][]
To this
Код:
new VehicleNames[][]
Thank you. Fixed but.. one more request:
When an admin creates a vehicle, I want to send him a message including the full-name of the car.

Example:
If an admin uses: "/vehiclecreate inf", he gets a message: "You have spawned an Infernus".

How so?
Reply
#7

Код:
CMD:vehiclecreate(playerid, params[]) 
{ 
    if(!IsAdminLevel(playerid, 3)) return NoPermsMSG(playerid); 
     
    new carname[50]; 
    if(sscanf(params, "s[50]", carname)) return SendUsageMSG(playerid, "/vehiclecreate [VEHICLE_NAME]"); 
     
    new carmodel = GetVehicleModelFromName(carname); 
    if(carmodel == -1) return SendErrorMSG(playerid, "Invalid vehicle name."); 
     
    new Float:X, Float:Y, Float:Z, Float:A, mycar; 
    new str[128];

    GetPlayerPos(playerid, X, Y, Z); 
    GetPlayerFacingAngle(playerid, A); 
    mycar = CreateVehicle(carmodel, X, Y, Z+2, A, -1, -1, -1); 
    PutPlayerInVehicle(playerid, mycar, 0); 
    format(str, 128, "You have spawned a %s", VehicleNames[carmodel - 400]);
    SendClientMessage(playerid, 0xFFFF0096, str);
    return 1; 
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)