/respawnallcars
#1

I need some help of that command beacause I don't really understand it.

I wanna make a command like when u /respawnallcars all the cars getting respawned, but if someone is in it, it won't respawn that car.

Could someone give me some help with that, or just the code?
Reply
#2

pawn Код:
stock IsVehicleOccupied(vehicleid)
{
    for(new i; i < GetMaxPlayers(); i++)
    {
        if(IsPlayerConnected(i)) continue;
        if(GetPlayerVehicleID(i) == vehicleid) return 1;
    }
    return 0;
}

CMD:respawnvehicles(playerid, params[])
{
    #pragma unused params
    for(new i; i < MAX_VEHICLES; i++) if(!IsVehicleOccupied(i)) SetVehicleToRespawn(i);
    return 1;
}
Had this lying around. Hope it helps!
Reply
#3

pawn Код:
// Top of script
forward PlayerInCar(vehicleid);

// ZCMD command, anywhere in the script not under a function or callback
CMD:respawnvehicles(playerid,params[])
{
        vehicles<MAX_VEHICLES; vehicles++)
        {
            if(!PlayerInCar(vehicles))
            {
                SetVehicleToRespawn(vehicles);
            }
        }
        return 1;
    }
    else return 0;
}
// Bottom of the script
public PlayerInCar(vehicleid)
{
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        if(IsPlayerInVehicle(i,vehicleid)) return 1;
    }
    return 0;
}
EDIT: funky was very fast. I recommend using his code rather than mine.
Reply
#4

@ funky code is kinda messed up, if I type /respawnvehicles it also respawn the cars with persons in it.

I guess the script code mistake has been placed here:
pawn Код:
for(new i; i < MAX_VEHICLES; i++) if(!IsVehicleOccupied(i)) SetVehicleToRespawn(i);
Could u fix it couse I really don't understand it.
Reply
#5

pawn Код:
CMD:vrespawn(playerid, params[])
{
    new sec,string[128];
    if(sscanf(params,"i",sec)) return SendClientMessage(playerid, red, "USAGE:/vrespawn [seconds]");
    SetTimer("vrespawn", sec*1000, false);
    format(string, sizeof(string), "~All currently unoccupied vehicles will respawn in %d seconds.",sec);
    SendClientMessageToAll(COLOR_ORANGE, string);
    return 1;
}

forward vrespawn();
public vrespawn()
{
    new u[MAX_VEHICLES];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInAnyVehicle(i)) u[GetPlayerVehicleID(i)]=1;
    }
    for(new i;i<MAX_VEHICLES;i++)
    {
        if(u[i] != 1) SetVehicleToRespawn(i); else continue;
    }
    SendClientMessageToAll(COLOR_ORANGE, "~All vehicles have been respawned.");
    return 1;
}
respawn with timer
Reply
#6

pawn Код:
stock IsVehicleOccupied(vehicleid)
{
    for(new i; i < GetMaxPlayers(); i++)
    {
        if(IsPlayerConnected(i)) continue;
        if(GetPlayerVehicleID(i) == vehicleid) return 1;
    }
    return 0;
}

CMD:respawnvehicles(playerid, params[])
{
    #pragma unused params
    for(new i; i < MAX_VEHICLES; i++)
    {
        if(!IsVehicleOccupied(i)) SetVehicleToRespawn(i);
    }
    return 1;
}
I'm not in a position to test at the moment, but try that.
Reply
#7

Not working though, still re-spawning cars when players are in it.
Reply
#8

pawn Код:
dcmd_respawncars(playerid,params[])
{
    {
        SendClientMessage(playerid, green, "Your have Successfully Respawned all Vehicles!");
       
        for(new cars=0; cars<MAX_VEHICLES; cars++)
        {
            if(!VehicleOccupied(cars))
            {
                SetVehicleToRespawn(cars);
            }
        }
        return 1;
    }
    else return ErrorMessages(playerid, 1);
}
Reply
#9

pawn Код:
// At The Top
new bool:IsVehicleOccupied[MAX_VEHICLES];
// Somewhere In Your Script
CMD:respawnallcars(playerid, params[])
{
    if(IsPlayerConnected(playerid)) {
        if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You cannot use this command.");
        for(new x = 0; x < MAX_VEHICLES; x++) {
            if(IsVehicleEmpty(x)) {
                SetVehicleToRespawn(x);
            }
        }
        SendClientMessage(playerid, -1, "Vehicles Respawned!");
    }
    return 1;
}
// At The Bottom
stock IsVehicleEmpty(vehicleid)
{
    if(IsVehicleOccupied[vehicleid])return 0;
    else return 1;
}
Reply
#10

Quote:
Originally Posted by SomebodyAndMe
Посмотреть сообщение
Nope, still respawning cars when a guy is inside it. Damn thing.
Quote:
Originally Posted by suhrab_mujeeb
Посмотреть сообщение
pawn Код:
// Top of script
forward PlayerInCar(vehicleid);

// ZCMD command, anywhere in the script not under a function or callback
CMD:respawnvehicles(playerid,params[])
{
        vehicles<MAX_VEHICLES; vehicles++)
        {
            if(!PlayerInCar(vehicles))
            {
                SetVehicleToRespawn(vehicles);
            }
        }
        return 1;
    }
    else return 0;
}
// Bottom of the script
public PlayerInCar(vehicleid)
{
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        if(IsPlayerInVehicle(i,vehicleid)) return 1;
    }
    return 0;
}
EDIT: funky was very fast. I recommend using his code rather than mine.
Have you tried this?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)