SA-MP Forums Archive
destroy vehicle - 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: destroy vehicle (/showthread.php?tid=391367)



destroy vehicle - Virus. - 10.11.2012

Hello guys. I want to destry the vehicles I have created with createvehicle() and by using enums.

I tried to do this.
Код:
public OnVehicleDeath(vehicleid)
{
         if(vehicleid==CEM[playerid][createdvehid])
         {
                   DestroyVehicle(vehicleid);
         }
}
I get an error :
Код:
error 017: undefined symbol "playerid"
And I want to know how can that created vehicle get automatically destroyed if the cehicle is empty for 15-20 secs.

Thanks.


Re: destroy vehicle - SKAzini - 10.11.2012

I guess you can make a loop:

pawn Код:
public OnVehicleDeath(vehicleid)
{
    for(new i; i < MAX_PLAYERS; i++)
        {
            if(vehicleid == CEM[i][createdvehid])
        {
            DestroyVehicle(vehicleid);
        }
    }
}
Correct me if im wrong, people. Long time since I last worked with SAMP gamemode scripting.


Re: destroy vehicle - Skillet` - 10.11.2012

the callback don't have the parameter : "playerid" which means you can't use functions that require the id of the player.
So to fix this you'll need to store the playerid in array and then use it when you need it(when the vehicle die\explode):
pawn Код:
new pid[MAX_PLAYERS]; // Array that will hold the playerid
public OnPlayerConnect(playerid)
{
    pid[playerid] = playerid;// here we store the playerid in the pid array
    return 1;
}
public OnVehicleDeath(vehicleid)
{
         if(vehicleid==CEM[pid][createdvehid])  // here we use it,if the vehicleid equals the vehicleid of the player,the vehicle will destroy
         {
                   DestroyVehicle(vehicleid);
         }
}
now everything should work properly.


Re: destroy vehicle - Virus. - 10.11.2012

Quote:
Originally Posted by SKAzini
Посмотреть сообщение
I guess you can make a loop:

pawn Код:
public OnVehicleDeath(vehicleid)
{
    for(new i; i < MAX_PLAYERS; i++)
        {
            if(vehicleid == CEM[i][createdvehid])
        {
            DestroyVehicle(vehicleid);
        }
    }
}
Correct me if im wrong, people. Long time since I last worked with SAMP gamemode scripting.
Thanks this worked. Thaks Skillet` but i found SKAzini's code easy to understand. But I want one more help.

how can that created vehicle get automatically destroyed if the cehicle is empty for 15-20 secs.


Re: destroy vehicle - SKAzini - 10.11.2012

pawn Код:
CreateVehicle(Vehicle, X, Y, Z, Angle, Color, Color, 15);
// Alternative:
AddStaticVehicleEx (Vehicle, X, Y, Z, Angle, Color, Color, 15);
In which 15 is the respawn time without a driver.