car spawning system
#1

Код:
 #include <a_samp>
#include <sscanf2>
#include <zcmd>

new vehicle_spawn[MAX_PLAYERS]; // Create a variable to give only a vehicle to the user

new NameVehicles[][] = // Name the all vehicles
{
    "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"
};

stock CreateVehicleEx(playerid, modelid) // With this feature we can create vehicles in all our indent usage CreateVehicleEx(playerid, modelid);
{
	new Float:pos[4]; // Create float 4 slots to obtain pos_x, pos_y, pos_z and GetVehicleZangle If you are in a vehicle the user.
	
	if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) // obtain getplayerstate (if this driver)..
	{
		GetVehiclePos(GetPlayerVehicleID(playerid), pos[0], pos[1], pos[2]); // Obtain position in the floats.
		GetVehicleZAngle(GetPlayerVehicleID(playerid), pos[3]); // obtan angle vehicle.
		DestroyVehicle(GetPlayerVehicleID(playerid)); // Destroy last vehicle created and continue function.
	}
	else // if not this driver..
	{
		GetPlayerPos(playerid, pos[0], pos[1], pos[2]);  // obtain position in the floats.
		GetPlayerFacingAngle(playerid, pos[3]); // obtain angle playerid and continue function..
	}
	if(vehicle_spawn[playerid] != 0) DestroyVehicle(vehicle_spawn[playerid]); // if variable is greater than 0 destroy the last vehicle created.
	vehicle_spawn[playerid] = CreateVehicle(modelid, pos[0], pos[1], pos[2], pos[3], -1, -1, 60); // Create vehicle in pos obtain the floats.
	LinkVehicleToInterior(vehicle_spawn[playerid], GetPlayerInterior(playerid)); // Changes inside the vehicle to which the user is located.
	SetVehicleVirtualWorld(vehicle_spawn[playerid], GetPlayerVirtualWorld(playerid)); // Change the world the vehicle spawn to which you will find a player
	PutPlayerInVehicle(playerid, vehicle_spawn[playerid], 0); // The playerid enters the vehicle and driver.
	SetVehicleZAngle(vehicle_spawn[playerid], pos[3]); // Set angle te obtain float.
	return true;
}

command(veh, playerid, params[])
{
	if(IsNumeric(params)) // if is numeric params.
	{
	    if(sscanf(params, "i", params[0])) return SendClientMessage(playerid, -1, "usage: /veh <name/modelid>.");
	    if(params[0] < 400 || params[0] > 611) return SendClientMessage(playerid, -1, "modelid invalid, usage: /veh <modelid 400-611>.");
	    CreateVehicleEx(playerid, params[0]);
    }
    else // not is numeric
    {
        new name_vehicle[30], i_create_vehicle;
        if(sscanf(params, "s[30]", name_vehicle)) return SendClientMessage(playerid, -1, "usage: /veh <name/modelid>.");
        i_create_vehicle = GetModelVehicle(name_vehicle);
        if(i_create_vehicle < 400 || i_create_vehicle > 611) return SendClientMessage(playerid, -1, "name invalid, usage: /veh <name correct>.");
        CreateVehicleEx(playerid, i_create_vehicle);
    }
    return true;
}

stock IsNumeric(const string[]) // function comprobate is numeric
{
    for (new i = 0, j = strlen(string); i < j; i++)
    {
        if (string[i] > '9' || string[i] < '0')
		return 0;
    }
    return true;
}

stock GetModelVehicle(vname[]) // fuction getmodelvehicle in the names
{
    for(new i = 0; i < 211; i++)
    {
        if(strfind(NameVehicles[i], vname, true) != -1)
        return i + 400;
    }
    return false;
}
Hi there could anyone help me i wanted to know how to make it so i can use the vehicle id instead of names, also how to add the option to set color of the vehicle?
Reply
#2

as for the spawning command, asssuming you use sscanf and ZCMD
PHP код:
CMD:v(playerid,params[])
{
   new 
String[200];
   new 
Float:xFloat:yFloat:z;
   if(!
IsNumeric(params)) return SendClienMessage(playerid, -1"use only numbers");
   new 
vehiclee GetModelVehicle(params);
   if(!
strlen(params)) return SendClientMessage(playerid,  -1"[USAGE] /v (Car Name)");
   if(
vehiclee 400 || vehiclee 611) return SendClientMessage(playerid,  -1"[ERROR] That vehicle name does not exist in our database.");
   new 
Float:a;
   
GetPlayerFacingAngle(playerida);
   
GetPlayerPos(playeridxyz);
   new 
mrand =random(200);
   new 
frand =random(200);
   new 
PlayersVehicle CreateVehicle(vehicleex+2y+2za+90mrandfrand, -1);
   
LinkVehicleToInterior(PlayersVehicleGetPlayerInterior(playerid));
   
format(Stringsizeof(String), "[VEHICLE] You have spawned a vehicle. [Vehicle: %s]"NameVehicles[vehiclee 400]);
   
SendClientMessage(playerid,  -1String);
   return 
1;

PHP код:
CMD:vcolor(playerid,params[])
{
   new 
String[200];
   new 
xy;
   new 
vid GetPlayerVehicleID(playerid);
   if(
sscanf(params"ii"x,y))
   {
          
SendClientMessage(playerid,  -1"[USAGE] /vcolor (0-255) (0-255)");
          return 
1;
   }
   if(!
IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,  -1"[ERROR] You must be in a vehicle to use this command.");
   
ChangeVehicleColor(vid,xy);
   
format(Stringsizeof(String), "[VEHICLE] You have set your vehicle color to [%d] and[%d]"xy);
   
SendClientMessage(playerid, -1String);
   return 
1;

Reply
#3

It already spawns with /veh {vehicle name} but want to change it to /veh {vehicle id} but thanks for help
Reply
#4

@Vanter, his CreateVehicleEx function deals with most of that. The command itself can be a lot simpler:

PHP код:
command(vehplayeridparams[]) {
    new
        
vehicleid[30];
    if(
sscanf(params"s[30]"vehicleid)) {
        return 
SendClientMessage(playerid, -1"usage: /veh <name/modelid>");
    }
    new
        
carid;
    if(
IsNumeric(vehicleid)) {
        
carid strval(vehicleid);
    }
    else {
        
carid GetVehicleModelID(vehicleid);
    }
    if(
carid 400 || carid 611) {
        return 
SendClientMessage(playerid, -1"error: The vehicle ID/Name you specified is invalid.");
    }
    
CreateVehicleEx(playeridcarid);
    return 
true;

The code is not hard to understand, so I believe an explanation is not required.
Reply
#5

When i type the cmd in /veh 560 it says that names not in the database? but thats the sultan vehicle id...
Reply
#6

Quote:
Originally Posted by CSLangdale
Посмотреть сообщение
When i type the cmd in /veh 560 it says that names not in the database? but thats the sultan vehicle id...
Check it again. I had made a few mistakes in the code.
Reply
#7

Will i need to change the stock aswell so it can read the vehicleids from the names?
Reply
#8

pawn Код:
stock GetModelVehicleFromID(vname[]) //NOTE THAT you have to add "FromID" to the stock in the command because i renamed it
{
        for(new i = 0; i < 211; i++)
        {
                if(strfind(NameVehicles[i], vname, true) != -1)
                return i + 400;
        }
        return -1;
}
thats mine edited to fit your script
Reply
#9

You can merge a few things together:
PHP код:
command(vehplayeridparams[]) {
    new
        
vehicleid[30];
    if(
sscanf(params"s[30]"vehicleid)) {
        return 
SendClientMessage(playerid, -1"usage: /veh <name/modelid>");
    }
    if((
vehicleid[0] = GetVehicleModelByName(model)) == 0) {
        return 
SendClientMessage(playerid, -1"error: invalid model id.");
    }
    
CreateVehicleEx(playeridvehicleid);
    return 
true;
}
GetVehicleModelByName(const name[])
{
    if (
IsNumeric(name) && (strval(name) >= 400 && strval(name) <= 611))
        return 
strval(name);
    for (new 
0sizeof(NameVehicles); ++)
    {
        if (
strfind(NameVehicles[i], nametrue) != -1)
        {
            return 
400;
        }
    }
    return 
0;

Reply
#10

Right i used the cmd and the only id that works is 400 any other id says its not in the database....
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)