Respawn vehicles
#1

I am looking for a command, which respawns empty/unused cars and cars that are not at their default spawn position.

I have this at the moment:

pawn Код:
dcmd_rav(playerid,params[])
{
    if(PlayerInfo[playerid][Level] >= 3|| IsPlayerAdmin(playerid))
    {
        for(new i = 0; i < MAX_VEHICLES; i++)
        {
            for(new x = 0; x < MAX_PLAYERS; x++)
            {
                if(!IsPlayerInAnyVehicle(x))
                {
                    SetVehicleToRespawn(i);
                    SendClientMessageToAll(COLOR_GREEN,"All Vehicles Have Been Respawned To Their Default Spawn Positions By An Admin.");
                    SendClientMessage(playerid,COLOR_LIGHTBLUE,"You Respawned All The Vehicles.");
                }
            }
        }
    } else return SendClientMessage(playerid,red,"Invalid Command. Type   /cmds   For A List Of All Available Server Commands.");
}
But the problem is (I'm sure it's because of the loops) is that it spams the chat with the messages which is because for each car it respawns, it spams. It then lags my game and sometimes freezes the computer, which forces me to restart. Can someone edit this code or tell me what I've done wrong?

I want the empty cars that are not at their default spawn position to be spawned, not ones that are occupied.

Thanks.
Reply
#2

Код:
dcmd_rav(playerid,params[])
{
    if(PlayerInfo[playerid][Level] >= 3|| IsPlayerAdmin(playerid))
    {
        for(new i = 0; i < MAX_VEHICLES; i++)
        {
            for(new x = 0; x < MAX_PLAYERS; x++)
            {
                if(!IsPlayerInAnyVehicle(x))
                {
                    SetVehicleToRespawn(i);
                }
            }
        }
        SendClientMessageToAll(COLOR_GREEN,"All Vehicles Have Been Respawned To Their Default Spawn      Positions By An Admin.");
        SendClientMessage(playerid,COLOR_LIGHTBLUE,"You Respawned All The Vehicles.");
    } else return SendClientMessage(playerid,red,"Invalid Command. Type   /cmds   For A List Of All Available Server Commands.");
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)