pawn-lang / YSI-Includes

Just the YSI include files, none of the extra stuff.
208 stars 106 forks source link

y_hooks order *again*... #467

Closed tr1xy closed 3 years ago

tr1xy commented 3 years ago
#include <PawnPlus>
#include <YSI_Coding\y_hooks>

// Player Data container
new List: PlayerData[MAX_PLAYERS];

// MUST be INCLUDED FIRST!!!
enum
{
    EXAMPLE_1 = 0,
    EXAMPLE_2,
    // ...
    EXAMPLE_50
};

hook OnPlayerConnect(playerid)
{
    if(PlayerData[playerid] != List: 0)
    {
        PlayerData[playerid] = list_new();
        list_resize(PlayerData[playerid], 50);
    }
    return Y_HOOKS_CONTINUE_RETURN_1;
}

// MUST be executed last!!!
hook OnPlayerDisconnect(playerid, reason)
{
    list_clear_deep(PlayerData[playerid]);
    return Y_HOOKS_CONTINUE_RETURN_1;
}

Is there a way to call this OnPlayerDisconnect last even if it is hooked first?

I cannot change the API include order because of the enum...

@Y-Less please xP

tr1xy commented 3 years ago

I added CallLocalFunction just before list_clear_deep but I'll keep the issue open in case there is better solution...

Y-Less commented 3 years ago
hook OnPlayerDisconnect@999()
{
}

But note that the very last hook function will still be called before the first ALS hook.