SA-MP Forums Archive
Help: /deleteveh - 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: Help: /deleteveh (/showthread.php?tid=440108)



Help: /deleteveh - Areax - 28.05.2013

Hello!

It's me again

Ok, I have the /veh command, which spawn a vehicles...But I don't know how to make the /deleteveh command, which will delete all vehicles that were spawned with the /veh command.

/Veh command:

pawn Код:
new vNames[212][] =
{
            {"Landstalker"},    {"Bravura"},            {"Buffalo"},            {"Linerunner"},     {"Perrenial"},      {"Sentinel"},       {"Dumper"},
            {"Firetruck"},      {"Trashmaster"},        {"Stretch"},            {"Manana"},         {"Infernus"},       {"Voodoo"},         {"Pony"},           {"Mule"},
            {"Cheetah"},        {"Ambulance"},          {"Leviathan"},          {"Moonbeam"},       {"Esperanto"},      {"Taxi"},           {"Washington"},
            {"Bobcat"},         {"Mr Whoopee"},         {"BF Injection"},       {"Hunter"},         {"Premier"},        {"Enforcer"},       {"Securicar"},
            {"Banshee"},        {"Predator"},           {"Bus"},{"Rhino"},      {"Barracks"},       {"Hotknife"},       {"Trailer 1"},      {"Previon"},
            {"Coach"},          {"Cabbie"},             {"Stallion"},           {"Rumpo"},          {"RC Bandit"},      {"Romero"},         {"Packer"},         {"Monster"},
            {"Admiral"},        {"Squalo"},             {"Seasparrow"},         {"Pizzaboy"},       {"Tram"},           {"Trailer 2"},      {"Turismo"},
            {"Speeder"},        {"Reefer"},             {"Tropic"},             {"Flatbed"},        {"Yankee"},         {"Caddy"},          {"Solair"},         {"Berkley's RC Van"},
            {"Skimmer"},        {"PCJ-6_0_0"},          {"Faggio"},             {"Freeway"},        {"RC Baron"},       {"RC Raider"},      {"Glendale"},       {"Oceanic"},
            {"Sanchez"},        {"Sparrow"},            {"Patriot"},            {"Quad"},           {"Coastguard"},     {"Dinghy"},         {"Hermes"},         {"Sabre"},
            {"Rustler"},        {"ZR-3_5_0"},           {"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"},         {"Cropdust"},       {"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 LA"},   {"Hustler"},            {"Intruder"},           {"Primo"},          {"Cargobob"},       {"Tampa"},          {"Sunrise"},        {"Merit"},
            {"Utility"},        {"Nevada"},             {"Yosemite"},           {"Windsor"},        {"Monster A"},      {"Monster B"},      {"Uranus"},         {"Jester"},
            {"Sultan"},         {"Stratum"},            {"Elegy"},              {"Raindance"},      {"RC Tiger"},       {"Flash"},          {"Tahoma"},         {"Savanna"},
            {"Bandito"},        {"Freight Flat"},       {"Streak Carriage"},    {"Kart"},           {"Mower"},          {"Duneride"},       {"Sweeper"},
            {"Broadway"},       {"Tornado"},            {"AT-400"},             {"DFT-30"},         {"Huntley"},        {"Stafford"},       {"BF-400"},         {"Newsvan"},
            {"Tug"},            {"Trailer 3"},          {"Emperor"},            {"Wayfarer"},       {"Euros"},          {"Hotdog"},         {"Club"},           {"Freight Carriage"},
            {"Trailer 3"},      {"Andromada"},          {"Dodo"},               {"RC Cam"},         {"Launch"},         {"Police Car LSPD"},{"Police Car SFPD"},
            {"Police _LVPD"},   {"Police Ranger"},      {"Picador"},            {"SWAT. Van"},      {"Alpha"},          {"Phoenix"},        {"Glendale"},
            {"Sadler"},         {"Luggage Trailer A"},  {"Luggage Trailer B"},  {"Stair Trailer"},{"Boxville"},         {"Farm Plow"},
            {"Utility Trailer"}

};

GetVehicleModelID(vName[])
{
    for ( new i = 400; i <= 611; i ++ )
        if( strfind( vNames[ i - 400 ], vName, true ) != -1 )
            return ( i );

    return ( -1 );
}

CMD:veh(playerid, params[])
{
    new aVehicle[64];
    new Color1;
    new Color2;
    new string[200];
    if(sscanf(params, "s[64]I(-1)I(-1)", aVehicle, Color1, Color2)) return SCM(playerid, COLOR_GREY, "[USAGE]: /veh [carid/name][color1] [color2]");
    new veh = GetVehicleModelID(aVehicle);
    if(veh < 400 || veh > 611) return SCM(playerid, COLOR_RED, "[ERROR]: Invalid Vehicle model! (400-611)");
    new Float:Pos[4];
    GetPlayerPos(playerid, Pos[0],Pos[1],Pos[2]);
    GetPlayerFacingAngle(playerid, Pos[3]);
    new PVeh = CreateVehicle(veh, Pos[0], Pos[1], Pos[2], Pos[3]+90, Color1, Color2, -1);
    LinkVehicleToInterior(PVeh, GetPlayerInterior(playerid));
    SetVehicleVirtualWorld(PVeh, GetPlayerVirtualWorld(playerid));
    format(string, sizeof(string), "{80FF00}[Admin]:{400080} %s(ID:%d) has spawned %s(ID:%d) to him!", GetName(playerid), playerid, aVehicle, veh);
    SCMToAll(COLOR_PURPLE, string);
    return 1;
}
Then how should I make /deleteveh command? Thanks for your help


Re: Help: /deleteveh - dubyabeast - 28.05.2013

pawn Код:
new spawnedVeh[MAX_VEHICLES];
// ongamemodeinit, or onfilterscriptinit:
for(new i = 0; i < MAX_VEHICLES; i++) spawnedVeh[MAX_VEHICLES] = 0;

CMD:veh(playerid, params[])
{
    new aVehicle[64];
    new Color1;
    new Color2;
    new string[200];
    if(sscanf(params, "s[64]I(-1)I(-1)", aVehicle, Color1, Color2)) return SCM(playerid, COLOR_GREY, "[USAGE]: /veh [carid/name][color1] [color2]");
    new veh = GetVehicleModelID(aVehicle);
    if(veh < 400 || veh > 611) return SCM(playerid, COLOR_RED, "[ERROR]: Invalid Vehicle model! (400-611)");
    new Float:Pos[4];
    GetPlayerPos(playerid, Pos[0],Pos[1],Pos[2]);
    GetPlayerFacingAngle(playerid, Pos[3]);
    new PVeh = CreateVehicle(veh, Pos[0], Pos[1], Pos[2], Pos[3]+90, Color1, Color2, -1);
    spawnedVeh[PVeh] = 1;
    LinkVehicleToInterior(PVeh, GetPlayerInterior(playerid));
    SetVehicleVirtualWorld(PVeh, GetPlayerVirtualWorld(playerid));
    format(string, sizeof(string), "{80FF00}[Admin]:{400080} %s(ID:%d) has spawned %s(ID:%d) to him!", GetName(playerid), playerid, aVehicle, veh);
    SCMToAll(COLOR_PURPLE, string);
    return 1;
}

CMD:deleteveh(playerid)
{
    for(new i = 0; i < MAX_VEHICLES; i++)
    {
        if(spawnedVeh[i] == 1)
        {
            spawnedVeh[i] = 0;
            DestroyVehicle(i);
        }
    }
    return 1;
}



Re: Help: /deleteveh - Areax - 28.05.2013

Thanks, but I get 1 ERROR:

pawn Код:
C:\Users\tadej\Desktop\SAMP\gamemodes\FMJ2.0.pwn(204) : error 032: array index out of bounds (variable "spawnedVeh")
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


1 Error.
On this line:

pawn Код:
for(new i = 0; i < MAX_VEHICLES; i++) spawnedVeh[MAX_VEHICLES] = 0;



Re: Help: /deleteveh - SuperViper - 28.05.2013

pawn Код:
spawnedVeh[i] = 0;



Re: Help: /deleteveh - Areax - 28.05.2013

Thanks REP+ for both