Respawn Vehicle - Admin Level - Please help
#1

hello
i have problem.
my admin level 3. but not use command.
Код:
CMD:rv(playerid,params[])
{
    if(PInfo[playerid][Level] >= 3)
    {
        for(new i = 0; i < MAX_VEHICLES; i++)
        {
            for(new x = 0; x < MAX_PLAYERS; x++)
            {
                if(!IsPlayerInAnyVehicle(x))
                {
                    SetVehicleToRespawn(i);
                }
            }
        }
        SendClientMessageToAll(0xFFFFFFFF,"{FF0000}Administrator  Respawn Vehicle!!!");
        SendClientMessage(playerid,0xFFFFFFFF,"{FF9900}You Respawn Vehicle!!!!");
    }
    else
    {
    SendClientMessage(playerid,-4,"{FF9900}Only Admin Level 3 To Use Command!!!");
    }
    return 1;
}
When the admin wants to use the rv command.
Text: Only Admin Level 3 To Use Command!!!
Please Help.
------------------------
sorry. my bad english
Reply
#2

pawn Код:
stock IsVehicleOccupied(vehicleid)
{
    for(new i =0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInVehicle(i,vehicleid))
        {
            return 1;
        }
    }
    return 0;
}

CMD:rv(playerid,params[])
{
    if(PInfo[playerid][Level] < 3) return SendClientMessage(playerid,-4,"{FF9900}Only Admin Level 3 To Use Command!!!");
       
    for(new i = 0; i < MAX_VEHICLES; i++)
    {
        if(!IsVehicleOccupied(i))
        {
            SetVehicleToRespawn(GetPlayerVehicleID(i));
        }
    }
       
    SendClientMessageToAll(0xFFFFFFFF,"{FF0000}Administrator  Respawn Vehicle!!!");
    SendClientMessage(playerid,0xFFFFFFFF,"{FF9900}You Respawn Vehicle!!!!");
    return 1;
}
EDIT 2: My bad, thought you were trying to respawn them if someone was in them, I'll change the code above. UPDATED
Try that code. It will work if the admin level is 3 or above, and will only respawn unoccupied vehicles.
Reply
#3

PHP код:
 if(PInfo[playerid][Level] <= 3

if I helped rep me
Reply
#4

It's obvious the admin level for that player is not 3 or greater.

By the way your code is really bad. If a vehicle is not occupied, it will keep respawning as many times as the MAX_PLAYERS is.

pawn Код:
// in the command:
for(new v = 1; v != MAX_VEHICLES; ++v)
{
    if (!IsVehicleOccupied(v)) SetVehicleToRespawn(v);
}
and
pawn Код:
IsVehicleOccupied(vehicleid)
{
    foreach(new i : Player) if (IsPlayerInVehicle(i,vehicleid)) return 1;
    return 0;
}
I used foreach because it loops through connected players only; therebefore it's faster!
Reply
#5

Thanks For Help
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)