destroy vehicle
#1

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.
Reply
#2

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.
Reply
#3

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.
Reply
#4

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.
Reply
#5

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)