YCMD OnPlayerCommandReceived causes flags to not work.
#1

Hello, I am making it so only admins can output certain commands anyway the flag system doesnt seem to be working for me.

Код:
public e_COMMAND_ERRORS:OnPlayerCommandReceived(playerid, cmdtext[], e_COMMAND_ERRORS:success)
{
    if(success != COMMAND_OK) {
        SendClientMessage(playerid, X11_RED, "Error: Unknown message!");
        return COMMAND_OK;        
    }
    return COMMAND_OK;
}
If I remove/comment the code above out, the system works perfectly fine however if I add it back in the commands perform normally when they aren't supposed to.

Код:
forward adminOnPlayerConnect(playerid);
public adminOnPlayerConnect(playerid) {
    unloadPlayerCmds(playerid);
}

adminOnPlayerLogin(playerid) {
    loadPlayerCmds(playerid);
    return 1;
}

isCmdAllowed(playerid, cmdid) {
    new AdminFlags:alevel = AdminFlags:Player[playerid][Admin];
    if(_:(alevel & acmds[cmdid][CmdAFlags]) != 0 && acmds[cmdid][CmdAFlags] != EAdminFlags_None) {
        return 1;
    }
    return COMMAND_UNDEFINED;
}

loadPlayerCmds(playerid) {
    for(new i=0;i<sizeof(acmds);i++) {
        printf("Is Allowed?: %d", isCmdAllowed(playerid, i));
        if(isCmdAllowed(playerid, i) == 1) {
            Command_SetPlayerNamed(acmds[i][ACMDName], playerid, true);
            print("Allowed");
        }
    }
}

unloadPlayerCmds(playerid) {
    for(new i=0;i<sizeof(acmds);i++) {
        Command_SetPlayerNamed(acmds[i][ACMDName], playerid, false);
        printf("CMDName Test: %s", acmds[i][ACMDName]);
    } 
}
Код:
public OnPlayerConnect(playerid) {
    adminOnPlayerConnect(playerid);
    return 1;
}
Код:
enum AdminFlags (<<= 1) {
    EAdminFlags_None = 0,
    EAdminFlags_Basic = 1, 
    EAdminFlags_Refund,
    EAdminFlags_Donations,
    EAdminFlags_ServerManager,
    EAdminFlags_All = -1
};
enum ACmds {
    ACMDName[32],
    AdminFlags:CmdAFlags
};
new acmds[][ACmds] = {
    {"test", EAdminFlags_All}
};

YCMD:test(playerid, params[], help) {
    SendClientMessage(playerid, X11_RED, "Test working, you are admin");
    return 1;
}
Even disabling the CMD with a command still doesnt work. The command will still send.

Код:
YCMD:disabletest(playerid, params[], help) {
    Command_SetPlayerNamed("test", playerid, false);
    SendClientMessage(playerid, X11_WHITE, "CMD:Test disabled");
    return 1;
}
Reply
#2

After doing some more debugging, I found out that my commands are being called when I use them as COMMAND_OK and not as COMMAND_DENIED. Even though the player should not have access to the commands. Alright so the problem now is, if I remove COMMAND_OK from the OnPlayerCommandRecieved it will not send the command, but if I add it back no matter what I do it will send it.

Код:
public e_COMMAND_ERRORS:OnPlayerCommandReceived(playerid, cmdtext[], e_COMMAND_ERRORS:success)
{
    switch(success) {
        case COMMAND_ZERO_RET: {
            print("Test1");
        }
        case COMMAND_OK: {
            print("Test2");
            return COMMAND_OK;
            
        }
        case COMMAND_UNDEFINED: {
            SendClientMessage(playerid, X11_RED, "Error: Unknown message!"); 
            print("Test3");
        }
        case COMMAND_DENIED: {
            SendClientMessage(playerid, X11_RED, "Error: Unknown message!");
            return COMMAND_DENIED;
        }
        case COMMAND_HIDDEN: {
            print("Test5");

        }
        case COMMAND_NO_PLAYER: {
            print("Test6");
            
        }
        case COMMAND_DISABLED: {
            print("Test7");

        }
        case COMMAND_BAD_PREFIX: {
            print("Test8");

        }
        case COMMAND_INVALID_INPUT: {
            print("Test9");
            
        }
    }
    return COMMAND_OK;
}
Reply
#3

See the problem is, is that I want to change the message I output when the command doesnt work or the person doesnt have permissions. But if I change the return to a failure the command doesnt work as planned however it outputs SAMP's default error message "SERVER: Unknown command." + my message.
Reply
#4

Yeah, except the COMMAND_HIDDEN still shows the default error message.

Код:
public e_COMMAND_ERRORS:OnPlayerCommandReceived(playerid, cmdtext[], e_COMMAND_ERRORS:success)
{
    switch(success) {
        case COMMAND_ZERO_RET: {
            print("Test1");
            SendClientMessage(playerid, X11_RED, "Error: Unknown message!"); 
            return COMMAND_ZERO_RET;
        }
        case COMMAND_OK: {
            print("Test2");
            return COMMAND_OK;
            
        }
        case COMMAND_UNDEFINED: {
            SendClientMessage(playerid, X11_RED, "Error: Unknown message!"); 
            print("Test3");
            return COMMAND_HIDDEN;
        }
        case COMMAND_DENIED: {
            SendClientMessage(playerid, X11_RED, "Error: Unknown message!");
            print("Test4");
            return COMMAND_HIDDEN;
        }
        case COMMAND_HIDDEN: {
            print("Test5");
            SendClientMessage(playerid, X11_RED, "Error: Unknown message!");
            return COMMAND_HIDDEN;

        }
        case COMMAND_NO_PLAYER: {
            print("Test6");
            SendClientMessage(playerid, X11_RED, "Error: Unknown message!"); 
            return COMMANDCOMMAND_NO_PLAYER_HIDDEN;
            
        }
        case COMMAND_DISABLED: {
            print("Test7");
            SendClientMessage(playerid, X11_RED, "Error: Unknown message!"); 
            return COMMAND_DISABLED;

        }
        case COMMAND_BAD_PREFIX: {
            print("Test8");
            SendClientMessage(playerid, X11_RED, "Error: Unknown message!"); 
            return COMMAND_BAD_PREFIX;

        }
        case COMMAND_INVALID_INPUT: {
            print("Test9");
            SendClientMessage(playerid, X11_RED, "Error: Unknown message!"); 
            return COMMAND_INVALID_INPUT;
            
        }
    }
    return COMMAND_OK;
}
I disable the commands they don't have access to so all the comamnds they type goes to COMMAND_DENIED, it shows my error message then when it returns COMMAND_HIDDEN it displays the default error message "SERVER: Unknown command.".
Reply
#5

Yeah that worked, thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)