Vcreate
#1

Hey guys,
i've written a command that should spawn a vehicle that does not get saved in the database just temp vehicles for events etc.

the command so far i got
Код:
CMD:vcreate(playerid, params[])
{
	new vehicleid, model, color1, color2;
	if(sscanf(params, "k<vehicle>I(1)I(0)", model, color1, color2))
		return SendClientMessage(playerid, COLOR_WHITE, "{ff0000}[Error]:{ffffff} /vcreate [vehicle name]");
	else if(model == INVALID_VEHICLE_ID)
		return SendClientMessage(playerid, 0xFF0000FF, "{ff0000}[Error]:{ffffff} Invalid Vehicle.");
	else if(IsPlayerInAnyVehicle(playerid))
		return SendClientMessage(playerid, 0xFF0000FF, "{ff0000}[Error]:{ffffff} You are already in a vehicle.");
				
	new Float:x,Float:y,Float:z,Float:r,Float:nX,Float:nY,Float:nZ;
	
	GetPlayerPos(playerid, x, y, z);
	GetPlayerFacingAngle(playerid,r);
	x += (3.0 * floatsin(-r, degrees));
	y += (3.0 * floatcos(-r, degrees));

	vehicleid = CreateVehicle(model, x, y, z+1.0, r+90, color1, color2, 5000);
	
	SetVehicleVirtualWorld(vehicleid, GetPlayerVirtualWorld(playerid));
	LinkVehicleToInterior(vehicleid, GetPlayerInterior(playerid));
	
	new tmpstr[100];
	format(tmpstr, sizeof(tmpstr), "You have spawned a %s.", GetVehicleName(vehicleid));
	return SendClientMessage(playerid, COLOR_WHITE, tmpstr);
}
However i wish i could fill in the vehicle name instead of the modelid, so for example
/vcreate NRG, and it picking random colors, is there anyone able to assist me with this?
I have the stock from another script, but it only says you have spawned a sultan if i use the ID,
If i use the vehicle name to spawn it gives me an error.

stock :

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

stock GetVehicleName(vehicleid)
{
	new String[128];
	format(String,sizeof(String),"%s",VehicleNames[GetVehicleModel(vehicleid) - 400]);
	return String;
}
Reply
#2

PHP код:
stock GetModelVehicle(vname[]) 
{
    for(new 
0211i++)
    {
        if(
strfind(VehicleNames[i], vnametrue) != -1)
        return 
400;
    }
    return 
false;
}
CMD:vcreate(playeridparams[])
{
    new 
vname[30];
    if(
sscanf(params"s[30]"vname))
        return 
SendClientMessage(playeridCOLOR_WHITE"{ff0000}[Error]:{ffffff} /vcreate [vehicle name]");
    else if(
IsPlayerInAnyVehicle(playerid))
        return 
SendClientMessage(playerid0xFF0000FF"{ff0000}[Error]:{ffffff} You are already in a vehicle.");
    new 
model GetModelVehicle(vname);
    if(
model 400 || model 611) return SendClientMessage(playerid, -1"{ff0000}[Error]:{ffffff} /vcreate [vehicle name]");
                
    new 
Float:x,Float:y,Float:z,Float:r,Float:nX,Float:nY,Float:nZ;
    
    
GetPlayerPos(playeridxyz);
    
GetPlayerFacingAngle(playerid,r);
    
+= (3.0 floatsin(-rdegrees));
    
+= (3.0 floatcos(-rdegrees));
    new 
vehicleid CreateVehicle(modelxyz+1.0r+90, -1, -15000);
    
    
SetVehicleVirtualWorld(vehicleidGetPlayerVirtualWorld(playerid));
    
LinkVehicleToInterior(vehicleidGetPlayerInterior(playerid));
    
    new 
tmpstr[100];
    
format(tmpstrsizeof(tmpstr), "You have spawned a %s."GetVehicleName(vehicleid));
    return 
SendClientMessage(playeridCOLOR_WHITEtmpstr);

EDIT: Updated code. Try again.
Reply
#3

If you don't use a modified version of the custom specifier "vehicle", then replace:
pawn Код:
else if(model == INVALID_VEHICLE_ID)
with
pawn Код:
else if(model == -1)
For random colors: "k<vehicle>I(-1)I(-1)".

You have already the modelid (a valid one) so just:
pawn Код:
format(tmpstr, sizeof(tmpstr), "You have spawned a %s.", VehicleNames[model - 400]);
I'd also like to point out that if the limit (for vehicles) is reached and CreateVehicle returns INVALID_VEHICLE_ID, the function GetVehicleName will fail because it will try to access element at negative index (-400).
Reply
#4

This is working however, how can i set it so once a player executes this lets say
/vcreate nrg, a nrg gets spawned infront of the player, but i would like it to be once a player executes this
he gets placed as driver on the vehicle?
Reply
#5

https://sampwiki.blast.hk/wiki/PutPlayerInVehicle
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)