[PROBLEM] Vehicle spawn (only one)
#1

Hello, I have this script for the vehicle spawn, but I can't spawn more than one vehicle, because this script deletes the previous vehicle... Does somebody know the solution for this problem?
This is the script:

Quote:

#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 Floatos[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;
}

Reply
#2

The script relies on the player itself, I have revised the script a bit and now you can spawn vehicles as much as you like ("#MAX_SPAWN_VEHICLES") - Once the MAX_SPAWN_VEHICLES is exceeded, the player can't spawn more vehicle unless it's destroyed. I have also revised the way how you created the /veh command

PHP код:
#include <a_samp>
#include <sscanf2>
#include <zcmd>

#define MAX_SPAWN_VEHICLES 50 // Every player can spawn up to 50 vehicles (once exceeded, one of the vehicle must be deleted for a free slot)
// Edit the value yourself, don't make it way too high

new vehicle_spawn[MAX_SPAWN_VEHICLES];

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(playeridmodelid// 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(playeridpos[0], pos[1], pos[2]); // obtain position in the floats.
        
GetPlayerFacingAngle(playeridpos[3]); // obtain angle playerid and continue function..
    
}
    
    for(new 
iMAX_SPAWN_VEHICLESi++) if(vehicle_spawn[i] == INVALID_VEHICLE_ID)
    {
        
vehicle_spawn[i] = CreateVehicle(modelidpos[0], pos[1], pos[2], pos[3], -1, -160); // Create vehicle in pos obtain the floats.
        
LinkVehicleToInterior(vehicle_spawn[i], GetPlayerInterior(playerid)); // Changes inside the vehicle to which the user is located.
        
SetVehicleVirtualWorld(vehicle_spawn[i], GetPlayerVirtualWorld(playerid)); // Change the world the vehicle spawn to which you will find a player
        
PutPlayerInVehicle(playeridvehicle_spawn[i], 0); // The playerid enters the vehicle and driver.
        
SetVehicleZAngle(vehicle_spawn[i], pos[3]); // Set angle te obtain float.
        
return i// Successfully spawned.
    
}
    return -
1// Not successfully spawned.
}

command(vehplayeridparams[])
{
    new 
result = -1carID[30], car;

    if(
sscanf(params"s[30]"carID))
        return 
SendClientMessage(playeridCOLOR_RED"usage: /veh <name/modelid>.");

    if(!
IsNumeric(carID))
        
car GetModelVehicle(carID);
    else
        
car strval(carID);

    if(
car 400 || car 611)
        return return 
SendClientMessage(playerid, -1"modelid invalid, usage: /veh <modelid 400-611>.");

    
result CreateVehicleEx(playeridparams[0]);
    
    if(
result == -1)
        return 
SendClientMessage(playerid, -1"* Unable to spawn vehicle, Limit ("#MAX_SPAWN_VEHICLES") reached.");
    
return true;
}

public 
OnVehicleDeath(vehicleidkillerid)
{
    for(new 
iMAX_SPAWN_VEHICLESi++)
    {
        if(
vehicle_spawn[i] == vehicleid)
        {
            
vehicle_spawn[i] = INVALID_VEHICLE_ID;
            return 
DestroyVehicle(vehicle_spawn[i]);
        }
    }
    return 
1;
}

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

stock GetModelVehicle(vname[]) // fuction getmodelvehicle in the names
{
    for(new 
0211i++)
    {
        if(
strfind(NameVehicles[i], vnametrue) != -1)
        return 
400;
    }
    return 
false;

Reply
#3

Ok, thank you very much!!!!
Reply
#4

I have a problem... It gives me these errors when I compile (the three marked line)
Reply
#5

Can somebody help me?
Reply
#6

Delete this line and try to write it manually, maybe some unprintable character snuck in and you pasted it.
Reply
#7

Infact, this was the problem.
I resolved. Thanks.
Reply
#8

Jake, can you post it on pastebin, please?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)