CMD:v(playerid, params[])
{
if ( GetPlayerState( playerid ) == PLAYER_STATE_DRIVER )
{
#if !defined IGNORE_VEHICLE_ACTIVATION
ShowPlayerDefaultDialog( playerid );
return 1;
#endif
}
if ( GetPlayerState( playerid ) != PLAYER_STATE_PASSENGER ) ShowPlayerDefaultDialog( playerid );
return 1;
}
CreatePlayerVehicle( playerid, modelid )
{
new
vehicle,
Float:x,
Float:y,
Float:z,
Float:angle;
if ( GetPlayerState( playerid ) == PLAYER_STATE_DRIVER )
{
vehicle = GetPlayerVehicleID( playerid );
GetVehiclePos( vehicle, x, y, z );
GetVehicleZAngle( vehicle, angle );
DestroyVehicle( vehicle );
}
else
{
GetPlayerPos( playerid, x, y, z );
GetPlayerFacingAngle( playerid, angle );
}
vehicle = CreateVehicle( modelid, x, y, ( z + 1 ), angle, -1, -1, DEFAULT_RESPAWN_TIME );
LinkVehicleToInterior( vehicle, GetPlayerInterior( playerid ) );
#if !defined IGNORE_VIRTUAL_WORLDS
SetVehicleVirtualWorld( vehicle, GetPlayerVirtualWorld( playerid ) );
#endif
#if !defined IGNORE_WARP_INTO_VEHICLE
PutPlayerInVehicle( playerid, vehicle, 0 );
#endif
#if !defined IGNORE_VEHICLE_DELETION
gDialogCreated[ vehicle ] = true;
#endif
return 1;
}
new timer_id[MAX_PLAYERS char];
j_Destroy(playerid);
public j_Destroy(playerid)
{
DestroyVehicle(GetPVarInt(playerid, "carId"));
SetPVarInt(playerid, "carId", -1);
return 1;
}
//This command spawns a NRG-500 on player position
//and put the player on vehicle.
CMD:v(playerid, params[])
{
new Float:x, Float:y, Float:z, Float:a;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
new veh = CreateVehicle(522, x, y, z, a, -1, -1, cellmax);
PutPlayerInVehicle(playerid, veh, 0);
//Here you sets the carId to a player variable
//to use in future verifications.
SetPVarInt(playerid, "carId", veh);
return 1;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
//Here you verified if the player entered on his vehicle
//until the time of 3 minutes.
if (ispassenger == 0 && GetPVarInt(playerid, "carId") == vehicleid)
{
//destroying the timer before delete the vehicle(3 minutes).
KillTimer(timer_id{playerid});
}
//codes
//---------
//return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
//Here you verified if the vehicle the player was get out is the same
//vehicle he has spawned, so, starts the timer.
if (GetPVarInt(playerid, "carId") == vehicleid)
{
timer_id{playerid} = SetTimerEx("j_Destroy", 3000 * 60, false, "i", playerid);
}
//codes
//---------
//return 1;
}
new bool:vInfo[MAX_VEHICLES char];
if(vInfo[GetPlayerVehicleID( playerid )])
{
// destroy
vInfo[GetPlayerVehicleID( playerid )] = false;
}
vehicle = CreateVehicle( modelid, x, y, ( z + 1 ), angle, -1, -1, DEFAULT_RESPAWN_TIME );
vInfo[vehicle] = true;
if(vInfo[vehicleid])
{
// destroy
vInfo[vehicleid] = false;
}
|
top
pawn Код:
pawn Код:
pawn Код:
|
if(vInfo[vehicleid])
{
// destroy vehicle
}
vInfo[vehicleid] = false;
|
Instead of using array for checking if the vehicle is valid or not, why don't you just use IsValidVehicle?
|
|
I have a vehicle command which spawn a vehicle but I want to add if a player spawned a vehicle and he leave it empty after 3 minutes then delete the vehicle. You know just to prevent vehicle flood in server.
|