RespawnCars and Trailers
#1

Hi all again, im having a problem with respawncars and trailers. I set a timer for respawning all cars every 5 minutes, and the problem is, when a player have a trailer attached to his truck, the trailer is respawning.

My code is:

pawn Code:
forward VehicleOccupied(vehicleid);
public VehicleOccupied(vehicleid)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInVehicle(i,vehicleid))
        return 1;
    }
    return 0;
}


forward RespawnCars();
public RespawnCars()
{
    for(new c = 0; c < MAX_VEHICLES; c++)
    {
        if(!VehicleOccupied(c))
        {
            SetVehicleToRespawn(c);
        }
    }
   
}
Can someone help?
Reply
#2

pawn Code:
public RespawnCars()
{
    for(new c = 0; c < MAX_VEHICLES; c++)
    {
        if(!VehicleOccupied(c))
        {
            SetVehicleToRespawn(c);
            if(IsTrailerAttachedToVehicle(c)) return 0;
        }      
    }
   
}
try This XD
Reply
#3

Not working dude.
Reply
#4

pawn Code:
forward RespawnCars();
public RespawnCars()
{
    new bool:VehUsed[MAX_VEHICLES],vehID;

    for(new playerid,g = GetMaxPlayers(); playerid != g; playerid++)
        if(IsPlayerConnected(playerid))
        {
            vehID = GetPlayerVehicleID(playerid);
            if(vehID > 0)
            {
                VehUsed[vehID] = true;
                new vehMod = GetVehicleModel(vehID);
                if(vehMod == 403 || vehMod == 514 || vehMod == 515 || vehMod == 525 || vehMod == 531 || vehMod == 572 || vehMod == 583) // Linerunner,Tanker,Roadtrain,Towtruck,Tractor,Mower,Tug
                {
                    vehID = GetVehicleTrailer(vehID);
                    if(vehID > 0)
                        VehUsed[vehID] = true;
                }
            }
        }

    for(new vehicleid = 1; vehicleid != MAX_VEHICLES; vehicleid++)
        if(!VehUsed[vehicleid] && IsValidVehicle(vehicleid))
            SetVehicleToRespawn(vehicleid);

    return;
}
https://sampwiki.blast.hk/wiki/IsValidVehicle
Reply
#5

Thanks man, you rock! Repped!
Reply
#6

EDIT: Im getting a bug, when i add this:

pawn Code:
for(new i = 0; i < MAX_PLAYERS; i++)
{
    if(!IsPlayerInAnyVehicle(i))
    {
        DestroyVehicle(curveh[i]);
    }
}
When it destroys the car after the respawning, then i cant spawn another car, it automaticly respawn it, before it spawns. Any idea?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)