All vehicles Respawn
#2

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (!strcmp(cmdtext, "/respawnall", true))
    {
        if (!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You need to be RCON admin to use this command.");
        for (new v = 1; v != MAX_VEHICLES; ++v)
        {
            if (!GetVehicleModel(v)) continue; // vehicle doesn't exist, skip it..
            if (!IsVehicleOccupied(v)) SetVehicleToRespawn(v); // vehicle is not occupied, respawn it..
        }
        return 1;
    }
    return 0;
}

IsVehicleOccupied(vehicleid)
{
    foreach(new i : Player)
    {
        if (IsPlayerInVehicle(i, vehicleid) return 1;
    }
    return 0;
}
I used foreach because it's faster since it loops through connected players only.
I'm going to say this - you shouldn't be using strcmp for commands but ZCMD or y_commands because they're faster.

Last, getting warnings about loosing indentation does not mean the code is wrong. All you have to do is indent the code properly: https://sampwiki.blast.hk/wiki/Errors_Li...se_indentation
Reply


Messages In This Thread
All vehicles Respawn - by Sting. - 06.06.2014, 19:37
Re: All vehicles Respawn - by Konstantinos - 06.06.2014, 20:03
Re: All vehicles Respawn - by Sting. - 06.06.2014, 20:23
AW: All vehicles Respawn - by Nero_3D - 06.06.2014, 20:31
Re: All vehicles Respawn - by Konstantinos - 06.06.2014, 20:49

Forum Jump:


Users browsing this thread: 1 Guest(s)