public OnPlayerExitVehicle(playerid, vehicleid)
{
SetTimerEx("DesVeh", 60000, 0, "i", vehicleid);
return 1;
}
forward DesVeh(vehid);
public DesVeh(vehid)
{
for(new i;i<MAX_PLAYERS;i++)
{
if(IsPlayerConnected(i))
{
if(IsPlayerInVehicle(i, vehid)) return 1;
}
}
SetVehicleToRespawn(vehid);
return 1;
}
|
We have this beautiful function, that allows you to set a respawn delay.
https://sampwiki.blast.hk/wiki/AddStaticVehicleEx Timer = bad. |
|
Isn't that make lags for server? thats my question if yes how to make another code with same functions
|
EXAMPLE: AddStaticVehicleEx ( 520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60); // It will respawn the vehicle after 1 minute when a player exits the vehicle.
|
Use AddStaticVehicleEx - When a player exits the vehicle. It will respawn the vehicle after the defined time. ie. 60 sec, 120 sec, etc.
Код:
EXAMPLE: AddStaticVehicleEx ( 520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60); // It will respawn the vehicle after 1 minute when a player exits the vehicle. |
public OnPlayerPickUpPickup(playerid, pickupid)
{
if (pickupid == NRG3)
{
CreateVehicleEx(playerid,522, X,Y,Z+1, Angle, random(126), random(126), -1);
}
.
.
.
.
}
stock CreateVehicleEx(playerid, modelid, Float:posX, Float:posY, Float:posZ, Float:angle, Colour1, Colour2, respawn_delay)
{
new world = GetPlayerVirtualWorld(playerid);
new interior = GetPlayerInterior(playerid);
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
DestroyVehicle(GetPlayerVehicleID(playerid));
GetPlayerPos(playerid, posX, posY, posZ);
GetPlayerFacingAngle(playerid, angle);
if(CurrentSpawnedVehicle[playerid] != -1)
{
DestroyVehicle(CurrentSpawnedVehicle[playerid]);
}
CurrentSpawnedVehicle[playerid] = CreateVehicle(modelid, posX, posY, posZ, angle, Colour1, Colour2, respawn_delay);
LinkVehicleToInterior(CurrentSpawnedVehicle[playerid], interior);
SetVehicleVirtualWorld(CurrentSpawnedVehicle[playerid], world);
SetVehicleZAngle(CurrentSpawnedVehicle[playerid], angle);
PutPlayerInVehicle(playerid, CurrentSpawnedVehicle[playerid], 0);
SetPlayerInterior(playerid, interior);
}
if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
{
if(IsVehicleOccupied(CurrentSpawnedVehicle[playerid])) {} else DestroyVehicle(CurrentSpawnedVehicle[playerid]);
GetPlayerPos(playerid, posX, posY, posZ);
GetPlayerFacingAngle(playerid, angle);
if(CurrentSpawnedVehicle[playerid] != -1)
{
DestroyVehicle(CurrentSpawnedVehicle[playerid]);
}
CurrentSpawnedVehicle[playerid] = CreateVehicle(modelid, posX, posY, posZ, angle, Colour1, Colour2, respawn_delay);
LinkVehicleToInterior(CurrentSpawnedVehicle[playerid], interior);
SetVehicleVirtualWorld(CurrentSpawnedVehicle[playerid], world);
SetVehicleZAngle(CurrentSpawnedVehicle[playerid], angle);
PutPlayerInVehicle(playerid, CurrentSpawnedVehicle[playerid], 0);
SetPlayerInterior(playerid, interior);
}
return 1;
}
// Add a Hydra to the game with a respawn time of 60 seconds - When a driver exits the vehicle.
CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60);
|
Have you noticed there's also a respawn_delay option for CreateVehicle
https://sampwiki.blast.hk/wiki/CreateVehicle Код:
// Add a Hydra to the game with a respawn time of 60 seconds - When a driver exits the vehicle.
CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60);
|