I'm making a derby system so a player should be put in vehicle directly but this is not happening all the times help how to fix this:
There is no error but player is not getting inserted into vehicle when derby starts.
http://forum.vc-mp.org/?topic=1429.0 for more info
function derbyann()
{
/* I repeated these made times to prevent bugs*/
foreach(i, val in playerson ) {
FindPlayer( i ).Spawn();
FindPlayer( i ).Vehicle = FindVehicle( i );
FindPlayer( i ).IsFrozen = true;
}
NewTimer( "Ann", 2000, 1, "3" );
foreach(i, val in playerson ) {
FindPlayer( i ).Vehicle = FindVehicle( i );
FindPlayer( i ).IsFrozen = true;
}
NewTimer( "Ann", 4000, 1, "2" );
foreach(i, val in playerson ) {
FindPlayer( i ).Vehicle = FindVehicle( i );
FindPlayer( i ).IsFrozen = true;
}
NewTimer( "Ann", 6000, 1, "1" );
foreach(i, val in playerson ) {
FindPlayer( i ).Spawn();
FindPlayer( i ).Vehicle = FindVehicle( i );
FindPlayer( i ).IsFrozen = true;
}
}
function derbyann()
{
local i = 0;
foreach( dPlayer in playerson )
{
local iPlayer = FindPlayer( dPlayer );
if( !iPlayer ) return print( "Error occured: Player instance not available at turn: " + i );
if( !IsSpawned( iPlayer ) ) iPlayer.Spawn();
iPlayer.Vehicle = FindVehicle( i );
iPlayer.IsFrozen = true;
i++;
}
NewTimer( "Ann", 2000, 1, "3" );
NewTimer( "Ann", 4000, 1, "2" );
NewTimer( "Ann", 6000, 1, "1" );
}
@Doom_Killer i just came to know the problem
If a player spawns by himself then he is put into the vehicle directly but if he spawns by control of script then he is not put into vehicle
, your code and my code have that same bug
Well if you don't provide all the information related to the problem and code then you can't expect much, anyway hope you fixed it.
Update it is not working
I think showing this video could tell more about that bug
https://youtu.be/e0YCrgYJDIkt
Tested:
At the top of your script:
local putInVehicle = {};
Function & onPlayerSpawn
function derbyann()
{
local i = 1;
foreach( dPlayer in playerson )
{
local iPlayer = FindPlayer( dPlayer );
if( !iPlayer ) return print( "Error occured: Player instance not available at turn: " + i );
if( !iPlayer.IsSpawned )
{
putInVehicle.rawset(iPlayer.ID, i);
iPlayer.Spawn();
}
iPlayer.Vehicle = FindVehicle( i );
iPlayer.IsFrozen = true;
i++;
}
NewTimer( "Ann", 2000, 1, "3" );
NewTimer( "Ann", 4000, 1, "2" );
NewTimer( "Ann", 6000, 1, "1" );
}
function onPlayerSpawn( player )
{
if ( putInVehicle.rawin( player.ID ) )
{
local veh = FindVehicle( putInVehicle.rawdelete( player.ID ) );
if ( veh )
player.Vehicle = veh;
}
}
Thanks Thijn