04.02.2011, 07:36
pawn Code:
// Top of your script
new
g_PlayerVehicle[MAX_PLAYERS],
g_SeatID[MAX_PLAYERS]
;
// OnPlayerStateChange
public OnPlayerStateChange(playerid, newstate, oldstate)
{
// Store vehicle's ID
if ((newstate == PLAYER_STATE_DRIVER) || (newstate == PLAYER_STATE_PASSENGER))
{
g_PlayerVehicle[playerid] = GetPlayerVehicleID(playerid);
g_SeatID[playerid] = GetPlayerVehicleSeat(playerid);
}
// Making not possible to get out of the car
if ((newstate == PLAYER_STATE_ONFOOT) && ((oldstate == PLAYER_STATE_DRIVER) || (oldstate == PLAYER_STATE_PASSENGER)))
PutPlayerInVehicle(playerid, g_PlayerVehicle[playerid], g_SeatID[playerid]);
// Return
return 1;
}
EDIT: Sorry, I thought you want to put player back in vehicle after he get outs.
This code should work:
pawn Code:
// Top of your script
new
g_PlayerVehicle[MAX_PLAYERS],
g_SeatID[MAX_PLAYERS]
;
forward PutPlayerBackInVehicle(playerid);
public PutPlayerBackInVehicle(playerid)
{
PutPlayerInVehicle(playerid, g_PlayerVehicle[playerid], g_SeatID[playerid]);
return 1;
}
// OnPlayerStateChange
public OnPlayerStateChange(playerid, newstate, oldstate)
{
// Store vehicle's ID
if ((newstate == PLAYER_STATE_DRIVER) || (newstate == PLAYER_STATE_PASSENGER))
{
g_PlayerVehicle[playerid] = GetPlayerVehicleID(playerid);
g_SeatID[playerid] = GetPlayerVehicleSeat(playerid);
}
// Return
return 1;
}
// OnPlayerKeyStateChange
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
// Making not possible to get out of the car
if (IsPlayerInAnyVehicle(playerid))
{
if (newkeys & KEY_SECONDARY_ATTACK)
{
SetTimerEx("PutPlayerBackInVehicle", 100, false, "i", playerid);
}
}
// Return
return 1;
}