alliedmodders / sourcemod

SourceMod - Source Engine Scripting and Administration
http://www.sourcemod.net/
991 stars 427 forks source link

Less spam please (for example, IsPlayerAlive) #1909

Closed wS-SM closed 1 year ago

wS-SM commented 1 year ago

https://github.com/alliedmodders/sourcemod/blob/b77e8c50ac01e5f2dcb60b689ba7eabc986bb8ed/core/smn_halflife.cpp#L454

Why not do so?

static cell_t smn_IsPlayerAlive(IPluginContext *pContext, const cell_t *params)
{
    CPlayer *player = g_Players.GetPlayerByIndex(params[1]);
    if (player && player->IsInGame())
    {
        switch (player->GetLifeState())
        {
            case PLAYER_LIFE_ALIVE: {
                return 1;
            }
            case PLAYER_LIFE_UNKNOWN: {
                pContext->ThrowNativeError("\"IsPlayerAlive\" not supported by this mod");
            }
        }
    }
    return 0;
}

return pContext->ThrowNativeError("Invalid client index %d", params[1]); If the correctness of the index is important to the scripter, he will write his own function. An incorrect index cannot harm the server. ThrowNativeError = spam.

return pContext->ThrowNativeError("Client %d is not in game", params[1]); You have already checked if the player is in the game and you are forcing the scripter to do the exact same check by making an extra call to IsClientInGame. ThrowNativeError = spam.

pContext->ThrowNativeError("\"IsPlayerAlive\" not supported by this mod"); Only this makes any sense.


There are many such functions and it is very annoying, because extra calls are bad.

psychonic commented 1 year ago

These kinds of exceptions are intentional.