pawn-lang / YSI-Includes

Just the YSI include files, none of the extra stuff.
210 stars 107 forks source link

Command return SERVER: Unknown command in case of COMMAND_SILENT #641

Open xs1vr opened 1 year ago

xs1vr commented 1 year ago

My code:

hook OnGameModeInit()
{
    Command_SetUnknownReturn(true);
    Command_SetDeniedReturn(true);

    return Y_HOOKS_CONTINUE_RETURN_1;
}

public e_COMMAND_ERRORS:OnPlayerCommandReceived(playerid, cmdtext[], e_COMMAND_ERRORS:success)
{
    SendClientMessage(playerid, -1, "Recv=%d", success);
    switch (success) {
        case COMMAND_UNDEFINED: {
            SendErrorMessage(playerid, "Ova komanda (%s) ne postoji.", cmdtext);
        }
        case COMMAND_DENIED: {
            SendErrorMessage(playerid, "Komanda (%s) zahteva dodatne dozvole ili vise nemate mogucnosti da ju koristite.", cmdtext);
        }
    }
    return success;
}

public e_COMMAND_ERRORS:OnPlayerCommandPerformed(playerid, cmdtext[], e_COMMAND_ERRORS:success)
{
    SendClientMessage(playerid, -1, "Perf=%d", success);
    switch(success) {
        case COMMAND_ZERO_RET: { // Added this as a temporal fix as the message is gone then
            return COMMAND_OK;
        }
        case COMMAND_DENIED: {
            SendErrorMessage(playerid, "Komanda (%s) zahteva dodatne dozvole ili vise nemate mogucnost da je koristite.", cmdtext);
        }
        case COMMAND_INVALID_INPUT: {
            SendErrorMessage(playerid, "Ova komanda zahteva argumente. Za vise detalja /help <komanda>.");
        }
    }
    return success;
}

@cmd(.alts = {"h", "pomoc"}) help(playerid, params[], help)
{
    if (help) {
        SendUsageMessage(playerid, "Koristite /help <komanda> da dobijete informacije o komandi.");
        return COMMAND_ZERO_RET; // SERVER: Unknown command
    }

    if (isnull(params)) {
        return COMMAND_ZERO_RET; // SERVER: Unkown command
    }

    Command_ReProcess(playerid, params, true);
    return COMMAND_OK;
}

Either a bad design or a bug

xs1vr commented 1 year ago

Figured it out on Discord, tldr use COMMAND_SILENT paired with Command_SetSilentReturn(true)

xs1vr commented 1 year ago

Apparently COMMAND_SILENT returns SERVER: Unknown message even with Command_SetSilentReturn set to true, however it did not when I used the /help command so that's why I assumed it initially worked..

Doing

case COMMAND_SILENT: {
    success = COMMAND_OK;
}

under the ..OnPerformed callback naturally "fixes" the issue.