CMD:kick not working properly, can't see anything wrong? (Newbie)
#1

So I am just editing a 'basic gamemode' that got released, MySQL based. I have been looking at this code for years, and still can't see what's wrong. I have edited, but it hasn't worked so I have absolutely no clue what's wrong here. I am a newbie scripter, do not expect that I know everything. I gave myself admin level 6, and then I should have rights to kick if you look, everyone with admin level 1 and above should be able to kick.

It always says "They aren't connected, or have a higher admin rank than you.", as it was a problem with the ID but there shouldn't be, because I got e.g a poke command that was in the script, with exact similar code (ofc a bit difference, but scripted in the same way) which worked, so it can't be anything wrong with the IDs as far as I know.

PHP код:
CMD:kick(playeridparams[])
{
    if(
pInfo[playerid][pAdmin] >= 1)
    {
        new 
giveplayeridreason[128], string[200];
        if(
sscanf(params"us[128]"giveplayeridreason)) return SendClientMessage(playeridCOLOR_WHITE"USAGE: /kick [playerid] [reason]");
        if(
IsPlayerConnected(giveplayerid) && pInfo[playerid][pAdmin] < pInfo[giveplayerid][pAdmin])
        {
            
format(stringsizeof(string), "AdmCmd: %s has been kicked from the server by Administrator %s, Reason: %s"GetName(giveplayerid), GetName(playerid), reason);
            
SendClientMessageToAll(COLOR_LIGHTREDstring);
            print(string);
            
format(stringsizeof(string), "SERVER: You have been kicked from the server by Admin %s, for: %s."GetName(playerid), reason);
            
SendClientMessage(giveplayeridCOLOR_LIGHTREDstring);
            
IsLoggedIn[giveplayerid] = 0;
            
LoginAttempts[giveplayerid] = 0;
            
SetTimerEx("KickPublic"1000false"i"playerid);
            return 
1;
        }
        else return 
SendClientMessage(playeridCOLOR_LIGHTRED"They aren't connected, or have a higher admin rank than you.");
    }
    else return 
SendClientMessage(playeridCOLOR_LIGHTRED"SERVER: You do not have permission to use this command.");

It's probably something very obvious that I have missed, but once again I am a newbie scripter.
Reply
#2

The first mistake was the sign between your admin level and your target's admin level. It should be "greater than", not "less than". The next thing i noticed is the kick timer which got "playerid" as parameter, so it would have kicked you if it worked. I replaced that with "giveplayerid". It should work now.
pawn Код:
CMD:kick(playerid, params[])
{
    if(pInfo[playerid][pAdmin] >= 1)
    {
        new giveplayerid, reason[128], string[200];
        if(sscanf(params, "us[128]", giveplayerid, reason)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /kick [playerid] [reason]");
        if(IsPlayerConnected(giveplayerid) && pInfo[playerid][pAdmin] > pInfo[giveplayerid][pAdmin])
        {
            format(string, sizeof(string), "AdmCmd: %s has been kicked from the server by Administrator %s, Reason: %s", GetName(giveplayerid), GetName(playerid), reason);
            SendClientMessageToAll(COLOR_LIGHTRED, string);
            print(string);
            format(string, sizeof(string), "SERVER: You have been kicked from the server by Admin %s, for: %s.", GetName(playerid), reason);
            SendClientMessage(giveplayerid, COLOR_LIGHTRED, string);
            IsLoggedIn[giveplayerid] = 0;
            LoginAttempts[giveplayerid] = 0;
            SetTimerEx("KickPublic", 1000, false, "i", giveplayerid);
            return 1;
        }
        else return SendClientMessage(playerid, COLOR_LIGHTRED, "They aren't connected, or have a higher admin rank than you.");
    }
    else return SendClientMessage(playerid, COLOR_LIGHTRED, "SERVER: You do not have permission to use this command.");
}
Reply
#3

Quote:
Originally Posted by HazardouS
Посмотреть сообщение
The first mistake was the sign between your admin level and your target's admin level. It should be "greater than", not "less than". The next thing i noticed is the kick timer which got "playerid" as parameter, so it would have kicked you if it worked. I replaced that with "giveplayerid". It should work now.
pawn Код:
CMD:kick(playerid, params[])
{
    if(pInfo[playerid][pAdmin] >= 1)
    {
        new giveplayerid, reason[128], string[200];
        if(sscanf(params, "us[128]", giveplayerid, reason)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /kick [playerid] [reason]");
        if(IsPlayerConnected(giveplayerid) && pInfo[playerid][pAdmin] > pInfo[giveplayerid][pAdmin])
        {
            format(string, sizeof(string), "AdmCmd: %s has been kicked from the server by Administrator %s, Reason: %s", GetName(giveplayerid), GetName(playerid), reason);
            SendClientMessageToAll(COLOR_LIGHTRED, string);
            print(string);
            format(string, sizeof(string), "SERVER: You have been kicked from the server by Admin %s, for: %s.", GetName(playerid), reason);
            SendClientMessage(giveplayerid, COLOR_LIGHTRED, string);
            IsLoggedIn[giveplayerid] = 0;
            LoginAttempts[giveplayerid] = 0;
            SetTimerEx("KickPublic", 1000, false, "i", giveplayerid);
            return 1;
        }
        else return SendClientMessage(playerid, COLOR_LIGHTRED, "They aren't connected, or have a higher admin rank than you.");
    }
    else return SendClientMessage(playerid, COLOR_LIGHTRED, "SERVER: You do not have permission to use this command.");
}
Oh man, thank you so much. It works perfectly, will try to remember that mistake so it won't happen again
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)