How can I prevent this system from spawn many vehicles?

Started by Kid_Buu, Jun 06, 2018, 05:32 PM

Previous topic - Next topic

Kid_Buu

I have this function:
function onPlayerHealthChange( player, lastHP, newHP )
{
if ( lastHP > newHP )
{
if ( player.Pos.z <= GetWaterLevel() )
{
local vehicle = CreateVehicle( 6400, player.Pos, player.Angle, 1, 2);
player.Vehicle = vehicle;
return true;
}
}
}

Because this function spawn many vehicles. How to prevent this?

NicusorN5

Use an array.
swimming <- array(100,false)function onPlayerHealthChange( player, lastHP, newHP )
{
if ( lastHP > newHP )
{
if ( (player.Pos.z <= GetWaterLevel()) && (swimming[player.ID] == false))
{
local vehicle = CreateVehicle( 6400, player.Pos, player.Angle, 1, 2);
player.Vehicle = vehicle;
swimming[player.ID] = true
return true;
}
}
}


You will need to remove the vehicle when the players exits it.