23.06.2012, 01:29
Anyone can help me after spawning another car the vehicle destroy. And after exiting the car it will destroy after 3mins.
public OnPlayerExitVehicle(playerid, vehicleid)
{
SetTimerEx("DestoryCars",180000,0,"i",vehicleid);
return 1;
}
forward DesytoryCars(vehicleid);
public DesytoryCars(vehicleid)
{
DestroyVechicle(vechicleid);
return 1;
}
|
Code:
public OnPlayerExitVehicle(playerid, vehicleid)
{
SetTimerEx("DestoryCars",180000,0,"i",vehicleid);
return 1;
}
forward DesytoryCars(vehicleid);
public DesytoryCars(vehicleid)
{
DestroyVechicle(vechicleid);
return 1;
}
|
new cars[MAX_PLAYERS];
COMMAND:car(playerid,params[]) //you can change to another command
{
CreateVehicle(vechicleid,x,y,z); //don't follow me to do
cars[playerid] = vechicleid; // the most important
return 1;
}
then
when player spawn a new car using the command
you can use DestroyVechicle(cars[playerid]); to destory that car
new IsVehTemp[MAX_VEHICLES]; // a global variable for temporary vehicles
// now in your vehicle spawner command //
// make sure you do this with any temporary vehicle
new veh = GetPlayerVehicleID(playerid); // after putting the player into the vehicle get its id
IsVehTemp[veh] = 1; // now setting it to 1 which means it's temporary
// and add this before you spawn a new vehicle for a player, it will destroy the prev vehicle
if(IsPlayerInAnyVehicle(playerid))
{
new veh = GetPlayerVehicleID(playerid);
RemovePlayerFromVehicle(playerid);
IsVehTemp[veh] = 0; // setting it to 0 means it's not temporary
DestroyVehicle(veh); // destroy it
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(oldstate == PLAYER_STATE_DRIVER) // if driver
{
new v = GetPlayerVehicleID(playerid); // storing the player's vehicle id into the variable v
SetTimerEx("DestroyVehic", 180000, false, "d", v); // setting a timer that will call DestroyVehic after 3 minutes
}
return 1;
}
// forwarding the public
forward DestroyVehic(v);
public DestroyVehic(v)
{
// when the DestroyVehic public is called
DestroyVehicle(v); // destroy the vehicle v
return 1;
}
|
then when the player spawn he's first car
you should do that Code:
new cars[MAX_PLAYERS];
COMMAND:car(playerid,params[]) //you can change to another command
{
CreateVehicle(vechicleid,x,y,z); //don't follow me to do
cars[playerid] = vechicleid; // the most important
return 1;
}
then
when player spawn a new car using the command
you can use DestroyVechicle(cars[playerid]); to destory that car
|