Can't edit a variable for disconnected players
#1

Hi , I wanted to create /accountban [PLAYERNAME] [REASON] command but don't know how to ,
this is the /cban (to ban connected players ) to check the variables & way i'm working with.
pawn Code:
dcmd_cban(playerid, params[])
{
    if (AdminLevel[playerid] < 3 ) {
        SendClientMessage(playerid, COLOR_GREY, "You must be admin to use this command.");
    }
    else {
        if (AdminLevel[playerid] >= 3) {
            if(strlen(params) > 40) return SendClientMessage(playerid, COLOR_CERVENA, " Reason too long.");
            new pos;
            new string[150];
            if(!params[0] || !(pos = chrfind(' ', params) + 1) || !params[pos]) return SendClientMessage(playerid, COLOR_GREY, "Usage: /cban [Playerid] [Reason]");

            new CMD_ID = strval(params);
            if(!IsPlayerConnected(CMD_ID)) return SendClientMessage(playerid, COLOR_CERVENA, "This player is not connected");
            if(IsPlayerNPC(CMD_ID)) return SendClientMessage(playerid, COLOR_CERVENA, "You can't ban an NPC!");
            new Admintext[128];
            if(AdminLevel[playerid] >= 3) { Admintext = "[Administrator]"; }
            format(string, sizeof(string), "[SERVER] : %s is account-banned by %s %s [Reason : %s]", PlayerName(CMD_ID),Admintext,PlayerName(playerid),params[pos]);
            SendClientMessageToAll(COLOR_ORANGE, string);
            format(string, sizeof(string), "[%s] %s has banned %s[Reason:%s]", Admintext,PlayerName(playerid), PlayerName(CMD_ID),params[pos]);
            Banned[CMD_ID] = 1;
            CodeUnban[CMD_ID] = 1648945654897 + random(900000000000000);
            dini_Set(file[CMD_ID], "BanReason", params[pos]);
            dini_Set(file[CMD_ID], "BanAdmin", PlayerName(playerid));
            Kick(CMD_ID);
        }
    }
    return 1;
}
Is there any way to change Banned variable for the 'PlayerName' to 1? like /accountban [Playername] [Reason] (for disconnected players)
Reply
#2

No because if you use 1 as the default value for offline players, you won't ever be able to ban ID 1 from the server.

What you could do, though, is make it -1 or something. Obviously -1 == INVALID_PLAYER_ID but then you could do something like this:

pawn Code:
if(playername == INVALID_PLAYER_ID)
{
    // check if the account name is online
        // if not, check if the account name exists
            // if it does, set the 'banned variable' to banned
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)