Automatic respawn for unused vehicules.
#1

Hello there !

I got a problem :
I tried to look for something to help to respawn unused cars every X minuts (the player leave his car on the road, then after X minuts it respawn).

So I found this code by BenzoAMG :

pawn Код:
// Somewhere, like in a command
SetTimer( "RespawnVehicles", 5000, false ); // Change '5000' to make a different delay

// After main( )
forward RespawnVehicles( );
public RespawnVehicles( )
{
    new vehicles[ MAX_VEHICLES ];
    for( new i = 0; i < MAX_PLAYERS; i ++ )
    {
        if( IsPlayerInAnyVehicle( i ) )
        {
            vehicles[ GetPlayerVehicleID( i ) ] = 1;
        }
    }

    for( new v = 0; v < MAX_VEHICLES; v ++ )
    {
        if( vehicles[ v ] == 1 ) continue;
        SetVehicleToRespawn( v );
    }
    return 1;
}


So I putted
pawn Код:
SetTimer( "RespawnVehicles", 5000, false ); // Change '5000' to make a different delay
on public OnGameModeInit() but this isn't working at all, the vehicule that is unused doesn't respawn after 5 seconds.

Can you please tell me what is wrong here ? The SetTimer place ?
Reply
#2

change the statement from false to true..that might work
Reply
#3

From :-
SetTimer( "RespawnVehicles", 5000, false );
To :-
SetTimer( "RespawnVehicles", 5000, true );
Reply
#4

Timer should be repeat..

Replace your timer with this
pawn Код:
SetTimer( "RespawnVehicles", 5000, true);
Reply
#5

Well, the cars are now respawning every 5 seconds (this is normal, because I wanted to test), but even if the cars were not used before (they didn't moved from their park place), is there a way to fix this ? Like coding if vehicule isn't at it park place, then it respawns after X minuts ?
Reply
#6

Quote:
Originally Posted by Jewell
Посмотреть сообщение
Timer should be repeat..

Replace your timer with this
pawn Код:
SetTimer( "RespawnVehicles", 5000, true);
i said that allready bro
Reply
#7

Quote:
Originally Posted by _Mohit_
Посмотреть сообщение
i said that allready bro
yeah i see. you posted when i was typing. you were fast
Reply
#8

This should be works This only spawn used cars.
If you got errors. Then post here

pawn Код:
new setspawn[MAX_VEHICLES]; //on top

//OnGameModeInt
SetTimer( "RespawnVehicles", 5000, true); // Change '5000' to make a different delay

// After main( )
forward RespawnVehicles( );
public RespawnVehicles( )
{
    new vehicles[ MAX_VEHICLES ];
    for( new i = 0; i < MAX_PLAYERS; i ++ )
    {
        if( IsPlayerInAnyVehicle( i ) )
        {
            vehicles[ GetPlayerVehicleID( i ) ] = 1;
        }
    }

    for( new v = 0; v < MAX_VEHICLES; v ++ )
    {
        if( vehicles[ v ] == 1 && setspawn[v ] == 0 ) continue;
        SetVehicleToRespawn( v );
        setspawn[v ] = 0;
    }
    return 1;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    setspawn[vehicleid] = 1;
    return 1;
}
Reply
#9

Quote:
Originally Posted by Jewell
Посмотреть сообщение
This should be works This only spawn used cars.
If you got errors. Then post here

pawn Код:
new setspawn[MAX_VEHICLES]; //on top

//OnGameModeInt
SetTimer( "RespawnVehicles", 5000, true); // Change '5000' to make a different delay

// After main( )
forward RespawnVehicles( );
public RespawnVehicles( )
{
    new vehicles[ MAX_VEHICLES ];
    for( new i = 0; i < MAX_PLAYERS; i ++ )
    {
        if( IsPlayerInAnyVehicle( i ) )
        {
            vehicles[ GetPlayerVehicleID( i ) ] = 1;
        }
    }

    for( new v = 0; v < MAX_VEHICLES; v ++ )
    {
        if( vehicles[ v ] == 1 && setspawn[v ] == 0 ) continue;
        SetVehicleToRespawn( v );
        setspawn[v ] = 0;
    }
    return 1;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    setspawn[vehicleid] = 1;
    return 1;
}
Hello,

This code is bugged, I explain :
- Now every vehicle (even the used ones) respawn.
Reply
#10

He's trying to ask for a timer that will not respawn cars, if they have not moved. You could try using something like this I guess:

pawn Код:
enum Vehicledata
{
    Float:PosX,
    Float:PosY,
    Float:PosZ
}
new Vehicleinfo[MAX_VEHICLES][Vehicledata];

public OnVehicleSpawn(vehicleid)
{
    new Float:x, Float:y, Float:z;
    GetVehiclePos(vehicleid, x, y, z);
    Vehicleinfo[vehicleid][PosX] = x;
    Vehicleinfo[vehicleid][PosY] = y;
    Vehicleinfo[vehicleid][PosZ] = z;
    return 1;
}

forward RespawnVehicles( );
public RespawnVehicles( )
{
    new vehicles[ MAX_VEHICLES ];
    for( new i = 0; i < MAX_PLAYERS; i ++ )
    {
        if( IsPlayerInAnyVehicle( i ) )
        {
            vehicles[ GetPlayerVehicleID( i ) ] = 1;
        }
    }

    for( new v = 0; v < MAX_VEHICLES; v ++ )
    {
        if( vehicles[ v ] == 1) continue;
        if(GetVehicleDistanceFromPoint(v, Vehicleinfo[v][PosX], Vehicleinfo[v][PosY], Vehicleinfo[v][PosZ]) <= 3.0) continue; //Change 3.0 if you want, this is just a slightly more accurate float.
        SetVehicleToRespawn( v );
    }
    return 1;
}
Give it a shot, if it doesn't work on the first respawn, it will work for the rest.

EDIT: It's nice to see my name in a post

btw... this should be || not &&
pawn Код:
if( vehicles[ v ] == 1 || setspawn[v ] == 0 ) continue;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)