Destroy cars after they spawned
#1

I want a command that will destroy the spawned cars but have no idea how
pawn Code:
CMD:eveh(playerid, params[])
{
    new vehid;
    if(sscanf(params, "i", vehid)) SendClientMessage(playerid, Red, Use: /eveh <car id>");
    else
    {
        new Float:x, Float:y, Float:z;new Float:angle;
        GetPlayerFacingAngle(playerid,angle);
        GetPlayerPos(playerid, x, y, z);
        CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);
        CreateVehicle(vehid, x + 5, y -2, z, angle-180, 2,2, 60000);
       
        CreateVehicle(vehid, x + 11, y +2, z, angle-180, 3,3, 60000);
        CreateVehicle(vehid, x + 11, y -2, z, angle-180, 4,4, 60000);
       
        CreateVehicle(vehid, x + 17, y +2, z, angle-180, 5,5, 60000);
        CreateVehicle(vehid, x + 17, y -2, z, angle-180, 6,6, 60000);
       
    }
    return 1;
}
Reply
#2

Assign the spawned vehicles to static variables.
After that destroy the static variable cars.
Reply
#3

Quote:
Originally Posted by milanosie
View Post
Assign the spawned vehicles to static variables.
After that destroy the static variable cars.
Can you give me an example?
Reply
#4

That's how it should be, just a example.


pawn Code:
new lol;


CMD:eveh(playerid, params[])
{
    new vehid;
    if(sscanf(params, "i", vehid)) return SendClientMessage(playerid, Red, Use: /eveh <car id>");
    new Float:x, Float:y, Float:z;new Float:angle;
    GetPlayerFacingAngle(playerid,angle);
    GetPlayerPos(playerid, x, y, z);
    lol = CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);        
    return 1;
}
CMD:destroyveh(playerid, params[])
{
   DestroyVehicle(lol);
   return 1;
}
Reply
#5

This only removes the last car spawned.

pawn Code:
new Auto[MAX_PLAYERS];
pawn Code:
CMD:eveh(playerid, params[])
{
    new vehid;
    if(sscanf(params, "i", vehid)) SendClientMessage(playerid, CRVENA, "Koristi: /eveh <id vozila>");
    else
    {
        new Float:x, Float:y, Float:z;new Float:kut;
        GetPlayerFacingAngle(playerid,kut);
        GetPlayerPos(playerid, x, y, z);
        Auto[playerid] = CreateVehicle(vehid, x + 5, y +2, z, kut-180, 1,1, 60000);
        Auto[playerid] = CreateVehicle(vehid, x + 5, y -2, z, kut-180, 2,2, 60000);
       
        Auto[playerid] = CreateVehicle(vehid, x + 11, y +2, z, kut-180, 3,3, 60000);
        Auto[playerid] = CreateVehicle(vehid, x + 11, y -2, z, kut-180, 4,4, 60000);
       
        Auto[playerid] = CreateVehicle(vehid, x + 17, y +2, z, kut-180, 5,5, 60000);
        Auto[playerid] = CreateVehicle(vehid, x + 17, y -2, z, kut-180, 6,6, 60000);
       
        Auto[playerid] = CreateVehicle(vehid, x + 23, y +2, z, kut-180, 7,5, 60000);
        Auto[playerid] = CreateVehicle(vehid, x + 23, y -2, z, kut-180, 8,6, 60000);
       
        Auto[playerid] = CreateVehicle(vehid, x + 29, y +2, z, kut-180, 9,5, 60000);
        Auto[playerid] = CreateVehicle(vehid, x + 29, y -2, z, kut-180, 10,6, 60000);
       
        Auto[playerid] = CreateVehicle(vehid, x + 35, y +2, z, kut-180, 11,5, 60000);
        Auto[playerid] = CreateVehicle(vehid, x + 35, y -2, z, kut-180, 12,6, 60000);
    }
    return 1;
}
pawn Code:
CMD:vehu(playerid, params[])
{
   DestroyVehicle(Auto[playerid]);
   return 1;
}
Reply
#6

Well, because you redefine AUTO every time...
Reply
#7

The var just can be used only one time, You're redefining each time. For new cars just make new vars.

Ex:

pawn Code:
new lol[10];


CMD:eveh(playerid, params[])
{
    new vehid;
    if(sscanf(params, "i", vehid)) return SendClientMessage(playerid, Red, Use: /eveh <car id>");
    new Float:x, Float:y, Float:z;new Float:angle;
    GetPlayerFacingAngle(playerid,angle);
    GetPlayerPos(playerid, x, y, z);
    lol[0] = CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);
    lol[1] = CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);
    lol[2] = CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);
    lol[3] = CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);
    lol[4] = CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);
    lol[5] = CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);    
    lol[6] = CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);
    lol[7] = CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);
    lol[8] = CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);    
    lol[9] = CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);  
    return 1;
}
CMD:destroyveh(playerid, params[])
{  
   DestroyVehicle(lol); // it will destroy all lol.
   return 1;
}
Reply
#8

Quote:
Originally Posted by leonardo1434
View Post
The var just can be used only one time, You're redefining each time. For new cars just make new vars.

Ex:

pawn Code:
new lol[10];


CMD:eveh(playerid, params[])
{
    new vehid;
    if(sscanf(params, "i", vehid)) return SendClientMessage(playerid, Red, Use: /eveh <car id>");
    new Float:x, Float:y, Float:z;new Float:angle;
    GetPlayerFacingAngle(playerid,angle);
    GetPlayerPos(playerid, x, y, z);
    lol[0] = CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);
    lol[1] = CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);
    lol[2] = CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);
    lol[3] = CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);
    lol[4] = CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);
    lol[5] = CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);    
    lol[6] = CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);
    lol[7] = CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);
    lol[8] = CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);    
    lol[9] = CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);  
    return 1;
}
CMD:destroyveh(playerid, params[])
{  
   DestroyVehicle(lol); // it will destroy all lol.
   return 1;
}
Hmm, there might be a need of loop like this:-

pawn Code:
CMD:destroyveh( playerid, params[ ] )
{
    for( new f = 0; f < sizeof( lol ); f++ )
    {
        DestroyVehicle( lol[ f ] ); // it will destroy all lol.
    }
   return 1;
}

-FalconX
Reply
#9

Instead of native function of samp, use foreach. it's better and simple than samp method.

pawn Code:
CMD:destroyveh( playerid, params[ ] )
{
    foreach(player,i)
    {
        DestroyVehicle(i, lol);
    }
    return 1;
}
Reply
#10

Quote:
Originally Posted by leonardo1434
View Post
Instead of native function of samp, use foreach. it's better and simple than samp method.

[pawn]
CMD:destroyveh( playerid, params[ ] )
{
foreach(player,i)
{
DestroyVehicle(i, lol);
}
return 1;
}
[pawn]
that doesnt work, learn your facts.
Neither does your previous post.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)