Destroy car on player exit
#1

Hello all. I made a destroy car when a player exit`s his vehicle. It works but, when a passenger exits, the car also gets destroyed. So you can destroy each other vehicle, and i dont want that. How to do it, that only if the driver exits, the vehicle gets destroyed?

Код:
	public OnPlayerExitVehicle(playerid, vehicleid)
			{
			new currentveh;
          	currentveh = GetPlayerVehicleID(playerid);
          	DestroyVehicle(currentveh);
          	TextDrawShowForPlayer(playerid,Cardestroyed);
          	SetTimerEx("cardestroyedhide", 5000, 0, "i", playerid);
			}
Reply
#2

pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
     if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
     {
          new currentveh;
          currentveh = GetPlayerVehicleID(playerid);
          DestroyVehicle(currentveh);
          TextDrawShowForPlayer(playerid,Cardestroyed);
          SetTimerEx("cardestroyedhide", 5000, 0, "i", playerid);
     }
     return 1;
}
Make sure you fix the indentations.
Reply
#3

pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        new currentveh;
        currentveh = GetPlayerVehicleID(playerid);
        DestroyVehicle(currentveh);
        TextDrawShowForPlayer(playerid,Cardestroyed);
        SetTimerEx("cardestroyedhide", 5000, 0, "i", playerid);
    }
    return 1;
}
Reply
#4

well the easiest way i think would be:
pawn Код:
new bool:IsDriver[MAX_PLAYERS] = false;
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
  {
  if(newstate==PLAYER_STATE_DRIVER)
    {
    IsDriver[playerid]=true;
    }
  }
pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
  {
  if(IsDriver)
    {
    new currentveh;
    currentveh = GetPlayerVehicleID(playerid);
    DestroyVehicle(currentveh);
    IsDriver[playerid]=false;
    TextDrawShowForPlayer(playerid,Cardestroyed);
    SetTimerEx("cardestroyedhide", 5000, 0, "i", playerid);
    }
}
OR SMTH LIKE THAT!!!!

Edit: yes even like @ post above
Reply
#5

Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
//	new currentveh;
//	currentveh = GetPlayerVehicleID(playerid);
	if(GetPlayerState(playerid)==PLAYER_STATE_DRIVER)
	{
		DestroyVehicle(vehicleid);//thats supposed to be in the timer. no slapping out
	}
//	TextDrawShowForPlayer(playerid,Cardestroyed);
//	SetTimerEx("cardestroyedhide", 5000, 0, "i", playerid);
	SetTimerEx("cardestroyedhide", 5000, 0, "i", vehicleid);
}
you dont need to get the players vehicleid, its already in the callback ^^
in my suggestion for the timer, i presume that its going to destroy the vehicleid. its the better solution to use the time, not my "cheap" version, coz it looks ugly to get slapped out of the car hehe
Reply
#6

Thanks boys, it worked. Im very happy
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)