04.02.2011, 06:02
pawn Code:
public OnPlayerExitVehicle(playerid, vehicleid)
{
PutPlayerInVehicle(playerid,vehicleid,GetPlayerVehicleSeat(playerid));
Mesaj(playerid,-1,"HEY, don't leave the car.");
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
PutPlayerInVehicle(playerid,vehicleid,GetPlayerVehicleSeat(playerid));
Mesaj(playerid,-1,"HEY, don't leave the car.");
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if (newkeys & KEY_SECONDARY_ATTACK)
{
}
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if ( (newkeys & KEY_SECONDARY_ATTACK) && IsPlayerInAnyVehicle(playerid) )
{
PutPlayerInVehicle(playerid, GetPlayerVehicleID(playerid), GetPlayerSeat(playerid));
}
}
stock GetNearestVehicle(playerid, Float:dis)
{
new Float:X, Float:Y, Float:Z;
if(GetPlayerPos(playerid, X, Y, Z))
{
new vehicleid = INVALID_VEHICLE_ID;
for(new v, Float:temp, Float:VX, Float:VY, Float:VZ; v != MAX_VEHICLES; v++)
{
if(GetVehiclePos(v, VX, VY, VZ))
{
VX -= X, VY -= Y, VZ -= Z;
temp = VX * VX + VY * VY + VZ * VZ;
if(temp < dis) dis = temp, vehicleid = v;
}
}
dis = floatpower(dis, 0.5);
return vehicleid;
}
return INVALID_VEHICLE_ID;
}
if ( (newkeys & KEY_SECONDARY_ATTACK) && IsPlayerInAnyVehicle(playerid) )
{
new nearest = GetNearestVehicle(playerid, 5.0);
PutPlayerInVehicle(playerid, nearest, GetPlayerSeat(playerid));
}
// 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;
}
// 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;
}