Help OnPlayerExitVehicle [REPS+]
#1

Hello, iv this function
Код:
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;
}
Which destroy the vehicle after 1 min from leave, anyway many people saied that this will cause a lagg when i v more players , any good ideas how to destroy vehicle after 1 min ? , i was thinking to make a timer in GameModeInit that check if the player in vehicle if not destroy the vehicle but i think isnt good idea :S
Reply
#2

We have this beautiful function, that allows you to set a respawn delay.
https://sampwiki.blast.hk/wiki/AddStaticVehicleEx
Timer = bad.
Reply
#3

Quote:
Originally Posted by Manyula
Посмотреть сообщение
We have this beautiful function, that allows you to set a respawn delay.
https://sampwiki.blast.hk/wiki/AddStaticVehicleEx
Timer = bad.
Dude , i just want to destroy playerid car with out after 1 min to avoid spam cars.
Reply
#4

Yeah, so what is the problem then? You get the player's position and let him spawn a car. As soon as he leaves it, the respawn delay is called. As far as I can tell, that's exactly what you have tried to do with your code above.
Reply
#5

Isn't that make lags for server? thats my question if yes how to make another code with same functions
Reply
#6

A Timer would cause intense lags.
Take a look at the wiki page I've sent you. I'm not going to code anything since in this case you just have to fill in the desired params in AddStaticVehicleEx or CreateVehicle. If you have problems with your code, I'll be glad to correct it.
Reply
#7

Quote:
Originally Posted by Mahde
Посмотреть сообщение
Isn't that make lags for server? thats my question if yes how to make another code with same functions
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.
That doesn't cause lag.
Reply
#8

Quote:
Originally Posted by Hostskool
Посмотреть сообщение
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.
That doesn't cause lag.
That what i doing now bro !! thanks but what if player pick uped a car
Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
	if (pickupid == NRG3)
	{
	    CreateVehicleEx(playerid,522, X,Y,Z+1, Angle, random(126), random(126), -1);
	}
.
.
.
.
}
CreateVehicleEx is working also same?

CreateVehicleEX Define:
Код:
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;
    }
Reply
#9

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);
Instead of using that big code to respawn vehicles.. you can simply use CreateVehicle function.
Reply
#10

Quote:
Originally Posted by Hostskool
Посмотреть сообщение
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);
Instead of using that big code to respawn vehicles.. you can simply use CreateVehicle function.
Well this is helped but dont forget iv /cars command which is spawn a car for player so when player left car i need to delete it how ??
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)