Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callbacks not being called on filterscripts #318

Closed
enzogsierra opened this issue May 6, 2024 · 3 comments
Closed

Callbacks not being called on filterscripts #318

enzogsierra opened this issue May 6, 2024 · 3 comments

Comments

@enzogsierra
Copy link

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
Copy link
Author

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
Copy link
Owner

ziggi commented May 7, 2024

You should use FCNPC_OnInit instead of OnFilterScriptInit in filterscripts too.

@enzogsierra
Copy link
Author

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!

@ziggi ziggi closed this as completed May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants