/setadmin command.
#1

Hi, I need some help with this admin command I made.

When I set myself like level 3, the server.exe stops working, anyone that can fix this for me?

pawn Код:
CMD:setadmin(playerid, params[])
{
    if(PlayerInfo[playerid][pAdminLevel] == 4)
    {
        new id, level;
        if(sscanf(params, "ui", id, level)) return SendClientMessage(playerid, COLOR_WHITE, "[USAGE]: /setadmin <id> <level>");
        if(level > 4) return SendClientMessage(playerid, COLOR_RED, "[SERVER]: Levels Available: 1-4!");
        new file[64];
        dini_IntSet(file, "Admin Level", PlayerInfo[id][pAdminLevel] = level);
        SendClientMessage(id, COLOR_YELLOW, "[SERVER]: You have been promoted to Administrator - Ask your Owner about your level!");
        SendClientMessage(playerid, COLOR_LIME, "[SERVER]: You have succesfully promoted %s to Administrator!");
    }
    else if(!IsPlayerConnected(playerid))
    {
        SendClientMessage(playerid, COLOR_RED, "[SERVER]: That player is not connected!");
    }
    else if(PlayerInfo[playerid][pAdminLevel] <= 4)
    {
        SendClientMessage(playerid, COLOR_RED, "[SERVER]: You are not an Administrator or not high enough to perform this command!");
    }
    return 1;
}
Reply
#2

You never check if the id is a valid player and that can cause runtime errors (Index out of bounds).

If the samp-server.exe stops working (probably a crash), then you will need to load crashdetect plugin.

https://github.com/Zeex/samp-plugin-...ases/tag/v4.12

And post what it printed in the console/server log the next time that will happen.
Reply
#3

do it directly from scriptfiles, isn't it?
Reply
#4

You haven't define the path of the file.
Reply
#5

It should be !IsPlayerConnected(id)) since you are checking if the id, the id that the admin entered is not connected.

Also, add PlayerInfo[id][pAdminLevel] = level; and then dini_IntSet(file, "Admin level", level);
Reply
#6

Quote:
Originally Posted by J4mmyHD
Посмотреть сообщение
You haven't define the path of the file.
Nice catch!

pawn Код:
new file[64];
dini_IntSet(file, "Admin Level", PlayerInfo[id][pAdminLevel] = level);
file is NULL.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)