i've written a command that should spawn a vehicle that does not get saved in the database just temp vehicles for events etc.
Код:
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.
Код:
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;
}
PHP код:
stock GetModelVehicle(vname[])
{
for(new i = 0; i < 211; i++)
{
if(strfind(VehicleNames[i], vname, true) != -1)
return i + 400;
}
return false;
}
CMD:vcreate(playerid, params[])
{
new vname[30];
if(sscanf(params, "s[30]", vname))
return SendClientMessage(playerid, COLOR_WHITE, "{ff0000}[Error]:{ffffff} /vcreate [vehicle name]");
else if(IsPlayerInAnyVehicle(playerid))
return SendClientMessage(playerid, 0xFF0000FF, "{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(playerid, x, y, z);
GetPlayerFacingAngle(playerid,r);
x += (3.0 * floatsin(-r, degrees));
y += (3.0 * floatcos(-r, degrees));
new vehicleid = CreateVehicle(model, x, y, z+1.0, r+90, -1, -1, 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);
}
EDIT: Updated code. Try again.
If you don't use a modified version of the custom specifier "vehicle", then replace:
For random colors: "k<vehicle>I(-1)I(-1)".
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).
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