SA-MP Forums Archive
Vehicle spawner. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Vehicle spawner. (/showthread.php?tid=503652)



Vehicle spawner. - biker122 - 30.03.2014

Command :
pawn Code:
CMD:v(playerid,params[])
{
    if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,COLOR_RED,"[ERROR] You already have a vehicle!");
    new vehicle;
    vehicle = GetVehicleModelIDFromName(params);
    if(isnull(params)) return ShowPlayerDefaultDialog(playerid);
    if(vehicle  < 400 || vehicle  > 611) return SendClientMessage(playerid,COLOR_RED,"[ERROR] Invalid vehicle name!");
    CreatePlayerVehicle(playerid,vehicle);
    return 1;
}
What's wrong with this? When I type /v it will show a dialog. It's perfect. But, When I type /v (carname), It spawns the same car even if I type someother car ID's / names.
I don't know the name of the car, sorry.
and "CreatePlayerVehicle" function :
pawn Code:
function CreatePlayerVehicle(playerid, modelid)
{
    if(PlayerInfo[playerid][PlayerCar] != -1 && !IsVehicleOccupied(PlayerInfo[playerid][PlayerCar]))
    {
        DestroyVehicle(PlayerInfo[playerid][PlayerCar]);
        PlayerInfo[playerid][PlayerCar] = -1;
    }
    new Float:x, Float:y, Float:z, Float:a;
    GetPlayerFacingAngle(playerid, a);
    GetPlayerPos(playerid, x, y, z);

    PlayerInfo[playerid][PlayerCar] = CreateVehicle(modelid, x, y, z, a, random(255), random(255), -1);
    LinkVehicleToInterior(PlayerInfo[playerid][PlayerCar], GetPlayerInterior(playerid));
    PutPlayerInVehicle(playerid, PlayerInfo[playerid][PlayerCar], 0);
    return PlayerInfo[playerid][PlayerCar];
}
Hope someone will help me,
Thanks.


Re: Vehicle spawner. - RenovanZ - 30.03.2014

Show us GetVehicleModelIdFromName.


Re: Vehicle spawner. - biker122 - 30.03.2014

Here you go,
pawn Code:
function GetVehicleModelIDFromName(vname[])
{
    for(new i = 0; i < 211; i++)
    {
        if(strfind(vname[i], vname, true) != -1)
        return i + 400;
    }
    return -1;
}



Re: Vehicle spawner. - RenovanZ - 30.03.2014

pawn Code:
function GetVehicleModelIDFromName(vnameX[])
{
    for(new i = 0; i < 211; i++)
    {
        if(strfind(vname[i], vnameX, true) != -1)
        return i + 400;
    }
    return -1;
}



Re: Vehicle spawner. - biker122 - 30.03.2014

pawn Code:
C:\Users\Matt\Desktop\samp03z_svr_R1_win32\gamemodes\stunting.pwn(1246) : error 017: undefined symbol "vname"
C:\Users\Matt\Desktop\samp03z_svr_R1_win32\gamemodes\stunting.pwn(1246) : warning 215: expression has no effect
C:\Users\Matt\Desktop\samp03z_svr_R1_win32\gamemodes\stunting.pwn(1246) : error 001: expected token: ";", but found "]"
C:\Users\Matt\Desktop\samp03z_svr_R1_win32\gamemodes\stunting.pwn(1246) : error 029: invalid expression, assumed zero
C:\Users\Matt\Desktop\samp03z_svr_R1_win32\gamemodes\stunting.pwn(1246) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.



Re: Vehicle spawner. - RenovanZ - 30.03.2014

Put this somewhere else, before CMD:v or whatever.
pawn Code:
new vname[212][] =
{
    "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"
};



Re: Vehicle spawner. - biker122 - 30.03.2014

Tried to use GetVehicleName.inc for this and eventually it worked.
Thanks for your help! (: