ziggi / FCNPC

FCNPC - Fully Controllable NPC
Apache License 2.0
137 stars 31 forks source link

Callbacks not being called on filterscripts #318

Closed enzogsierra closed 5 months ago

enzogsierra commented 5 months ago

So I've this gamemode code:

public FCNPC_OnInit()
{
    // Connect all npcs
    for(new i = 0; i < MAX_NPC; i++)
    {
        new name[MAX_PLAYER_NAME];
        format(name, sizeof(name), "npc_%i", MAX_PLAYERS - 1 - i);
        FCNPC_Create(name);
    }
}

public FCNPC_OnCreate(npcid)
{
    FCNPC_SetHealth(npcid, 100.0);
    FCNPC_Spawn(npcid, 3, 0.0, 0.0, 3.0);
    return 1;
}

And this filterscript code:

public OnFilterScriptInit()
{
    for(new i = MAX_PLAYERS - MAX_NPC; i < MAX_PLAYERS; i++)
    {
        FCNPC_Respawn(i);
    }
    return 1;
}

public FCNPC_OnRespawn(npcid) // Its never called
{
    print("Respawn");
    return 1;
}

For some reason, FCNPC_OnRespawn is not being called in my filterscript. I've to mention that I load it 1s after OnGameModeInit, at that point NPCs are created and first spawned. FCNPC_OnRespawn works fine in gamemode tho

enzogsierra commented 5 months ago

I just fixed it by defering bot spawn

public OnFilterScriptInit()
{
    SetTimer("FCNPC_RespawnAll", 1000, false);
    return 1;
}

forward FCNPC_RespawnAll();
public FCNPC_RespawnAll() 
{
    for(new i = MAX_PLAYERS - MAX_NPC; i < MAX_PLAYERS; i++)
    {
        FCNPC_Respawn(i);
    }
    return 1;
}

Now FCNPC_OnRespawn is being called normally

ziggi commented 5 months ago

You should use FCNPC_OnInit instead of OnFilterScriptInit in filterscripts too.

enzogsierra commented 5 months ago

You should use FCNPC_OnInit instead of OnFilterScriptInit in filterscripts too.

I thought FCNPC_OnInit was called only once (after plugin load). It works fine now, thanks!