Respawn Vehicles?
#1

Hello,

Well I have been undergoing vehicles everywhere without respawning, So how do I make them all respawn?
I use CreateVehicleEx and AddStaticVehicleEx.

Thanks
Reply
#2

pawn Code:
for(new i = 0; i < MAX_VEHICLES; i++)
{
 if(i != INVALID_VEHICLE_ID)
 {
  SetVehicleToRespawn(i);
 }
}
Just incorporate that into a simple command like /respawnallcars
Reply
#3

If you mean by respawning with a command, something like this
pawn Code:
CMD:respawncars(playerid, params[])
{
    if(IsPlayerConnected(playerid)) {
        for(new x = 0; x < MAX_VEHICLES; x++) {
            if(IsVehicleEmpty(x)) {
                SetVehicleToRespawn(x);
            }
        }
        SendClientMessage(playerid, COLOR_ORANGE, "Vehicles Respawned!");
    }
    return 1;
}
pawn Code:
stock IsVehicleEmpty(vehicleid)
{
    if(IsVehicleOccupied[vehicleid])return 0;
    else return 1;
}
Reply
#4

I revised it a little - This will check through each vehicle and then check if any players are in it.
If it finds any, leaves the car alone
If it doesn't, respawns it

pawn Code:
CMD:respawncars(playerid, params[])
{
for(new i = 0; i < MAX_VEHICLES; i++)
{
    if(i != INVALID_VEHICLE_ID)
    {
        new IsVehicleEmpty = 0;
        for(new j=0; j<MAX_PLAYERS; j++)
        {
            if(GetPlayerVehicleID(j) != i)
            {
                IsVehicleEmpty = 1;
            }
            else
            {
                IsVehicleEmpty = 0;
            }
        }
        if(IsVehicleEmpty = 0)
        {
            SetVehicleToRespawn(i);
        }
        else
        {
            //If you need to perform an action on a used-car during the respawn, place it here
        }
        SendClientMessage(playerid, COLOR_ORANGE, "Vehicles Respawned!");
    }
}
return 1;
}
Reply
#5

Ok thankyou but,

warning 219: local variable "IsVehicleEmpty" shadows a variable at a preceding level
warning 211: possibly unintended assignment
warning 204: symbol is assigned a value that is never used: "IsVehicleEmpty"
Reply
#6

Try that

pawn Code:
CMD:respawncars(playerid, params[])
{
for(new i = 0; i < MAX_VEHICLES; i++)
{
    if(i != INVALID_VEHICLE_ID)
    {
        new bool: IsVehicleEmpty;
        for(new j=0; j<MAX_PLAYERS; j++)
        {
            if(GetPlayerVehicleID(j) != i)
            {
                IsVehicleEmpty = true;
            }
            else
            {
                IsVehicleEmpty = false;
            }
        }
        if(IsVehicleEmpty = true)
        {
            SetVehicleToRespawn(i);
        }
        else
        {
            //If you need to perform an action on a used-car during the respawn, place it here
        }
        SendClientMessage(playerid, COLOR_ORANGE, "Vehicles Respawned!");
    }
}
return 1;
}
Reply
#7

I still get them 3 warnings :S
Reply
#8

Did you try my way?
Reply
#9

@Kostas, you used
pawn Code:
if(IsVehicleOccupied[vehicleid])return 0;
How does that variable get it's value?

@Outlawz - Try running it, see if it works... I'll have another look, I don't really see why it's giving warnings at all
Reply
#10

Quote:
Originally Posted by Rob_Maate
View Post
@Kostas, you used
pawn Code:
if(IsVehicleOccupied[vehicleid])return 0;
How does that variable get it's value?
I have tested and it works. It respawns vehicles that are empty. If there is player inside nothing happens.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)