SA-MP Forums Archive
RespawnCars and Trailers - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: RespawnCars and Trailers (/showthread.php?tid=420526)



RespawnCars and Trailers - ]Rafaellos[ - 05.03.2013

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?


Re: RespawnCars and Trailers - Windrush - 05.03.2013

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


Re: RespawnCars and Trailers - ]Rafaellos[ - 05.03.2013

Not working dude.


Re: RespawnCars and Trailers - Jefff - 05.03.2013

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


Re: RespawnCars and Trailers - ]Rafaellos[ - 05.03.2013

Thanks man, you rock! Repped!


Re: RespawnCars and Trailers - ]Rafaellos[ - 05.03.2013

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?