FCNPC icon indicating copy to clipboard operation
FCNPC copied to clipboard

FCNPC_OnCreate isn't getting called. (Under OnGameModeInit)

Open CantBeKarma opened this issue 6 years ago • 3 comments

For some reason FCNPC_OnCreate isn't getting called at all after creating an NPC. I'm using the latest release as of making this (https://github.com/ziggi/FCNPC/releases/tag/v2.0.0-rc.7) specifically for 0.3.DL. I've also tried using the other 0.3.DL release and FCNPC_OnCreate isn't getting called. This is the test script:

#include <a_samp>
#include <FCNPC> 
#include <ColAndreas>

main()
{
    print("\n----------------------------------");
    print("  Blank Gamemode\n");
    print("----------------------------------\n");
}

public OnGameModeInit()
{
    FCNPC_Create("Test");
    return 1;
}

public FCNPC_OnCreate(npcid)
{
    printf("FCNPC_OnCreate: %i", npcid);
    return 1;
}

The results (server-log):


----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3.DL-R1, (C)2005-2018 SA-MP Team

[22:28:18] filterscripts = ""  (string)
[22:28:18] 
[22:28:18] Server Plugins
[22:28:18] --------------
[22:28:18]  Loading plugin: ColAndreas
[22:28:18] *********************
[22:28:18] ** Created By:     **
[22:28:18] ** [uL]Chris42O    **
[22:28:18] ** [uL]Slice       **
[22:28:18] ** [uL]Pottus      **
[22:28:18] *********************
[22:28:20] Loaded collision data.
[22:28:20] *********************
[22:28:20]   ColAndreas Loaded
[22:28:20]    v1.4.0
[22:28:20] *********************
[22:28:20]   Loaded.
[22:28:20]  Loading plugin: FCNPC-DL
[22:28:20] 
[22:28:20] -------------------------------------------------
[22:28:20]      FCNPC - Fully Controllable NPC v2.0.0
[22:28:20]             Windows SA-MP 0.3.DL R1
[22:28:20]            Jan  2 2019 at 23:09:26
[22:28:20] 
[22:28:20]   Author:       OrMisicL (2013 - 2015)
[22:28:20]   Continued by: ziggi    (2016 - present)
[22:28:20] 
[22:28:20]   See full credits in the README.md file
[22:28:20] -------------------------------------------------
[22:28:20] 
[22:28:20] Loading...
[22:28:20] 
[22:28:20] -------------------------------------------------
[22:28:20]    ColAndreasv1.4.0
[22:28:20] 
[22:28:20]    Created By:
[22:28:20]      [uL]Chris42O
[22:28:20]      [uL]Slice
[22:28:20]      [uL]Pottus
[22:28:20] -------------------------------------------------
[22:28:20] 
[22:28:20] Loading...
[22:28:20] ColAndreas v1.4.0 Loaded.
[22:28:20]   Loaded.
[22:28:20]  Loaded 2 plugins.

[22:28:20] [artwork:crc] lvpdpc2.dff CRC = 0xFBD1EA7C
[22:28:20] [artwork:crc] lvpdpc2.txd CRC = 0xDC92731E
[22:28:20] [artwork:crc] lapdpd2.dff CRC = 0xA558D422
[22:28:20] [artwork:crc] lapdpd2.txd CRC = 0xA442E2DA
[22:28:20] [artwork:crc] wallzzz.dff CRC = 0x4BC6EDFF
[22:28:20] [artwork:crc] wallzzz.txd CRC = 0x235E3EEB
[22:28:20] 
[22:28:20] Filterscripts
[22:28:20] ---------------
[22:28:20]   Loaded 0 filterscripts.

[22:28:24] Loaded collision data.
[22:28:24] [npc:join] Test has joined the server (999:127.0.0.1)
[22:28:24] 
----------------------------------
[22:28:24]   Blank Gamemode

[22:28:24] ----------------------------------

[22:28:24] Number of vehicle models: 0

It shows the NPC has connected, however it just doesn't call FCNPC_OnCreate, yeah. I've even tried printing within the include, specifically where it's hooking FCNPC_OnCreate and it doesn't print anything at all.

CantBeKarma avatar Sep 26 '19 02:09 CantBeKarma

One thing I can say is the following, which is also mentioned on the wiki: You also don't need to load the ColAndreas separately in server.cfg, since FCNPC loads this automatically!

Is it only FCNPC_OnCreate, or also other FCNPC callbacks?

WoutProvost avatar Sep 27 '19 20:09 WoutProvost

Just tested on my own.

It seems like FCNPC_OnCreate doesn't get called when you use FCNPC_Create under OnGameModeInit. I also tested FCNPC_Spawn and FCNPC_OnSpawn isn't getting called either. When I delay the creation of the NPC with a timer, the callback does get called. I also tested this on non-DL and the result is exactly the same.

It seems that it has something to do with when the server is starting.

EDIT: I did some further testing, to see if other plugins had the same problem. Turns out it's only FCNPC. I used the following minimal server.cfg:

maxnpc 10
rcon_password 1234
gamemode0 bare 1
plugins streamer FCNPC

and the following minimal gamemode:

#include <a_samp>
#include <streamer>
#include <FCNPC>

main() {}

public OnGameModeInit()
{
	new obj = CreateObject(1271, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
	MoveObject(obj, 0.1, 0.1, 0.1, 1);

	new obj2 = CreateDynamicObject(1271, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
	MoveDynamicObject(obj2, 0.1, 0.1, 0.1, 1);

	new npc = FCNPC_Create("testNPC");
	FCNPC_Spawn(npc, 0, 0.0, 0.0, 0.0);
	return 1;
}

public OnObjectMoved(objectid)
{
	print("MOVED");
	return 1;
}

public OnDynamicObjectMoved(STREAMER_TAG_OBJECT:objectid)
{
	print("DYN MOVED");
	return 1;
}

public FCNPC_OnCreate(npcid)
{
	print("NPC CREATE");
	return 1;
}

This is the output:

...
[npc:join] testNPC has joined the server (49:127.0.0.1)
Number of vehicle models: 0
MOVED
DYN MOVED

As you can see, both MOVED from the regular object and DYN MOVED from the streamer object are displayed as should be, but NPC CREATE isn't.

WoutProvost avatar Sep 27 '19 21:09 WoutProvost

I also encountered this problem, any fix other than using it outside gamemode or using timer?

Fairuz-Afdhal avatar Apr 02 '20 05:04 Fairuz-Afdhal

Wait 5 ticks for each FCNPC_Create. (with PawnPlus for example)

0z0sk0 avatar Feb 22 '23 08:02 0z0sk0

Or (BE CAREFUL!!!) call CallbackManager::Init inside OnSpawn or OnCreate callbacks, and recompile plugin.

0z0sk0 avatar Feb 25 '23 11:02 0z0sk0

This can be easily fixed by moving the CCallbackManager::Init(); call inside the AmxLoad function, but this will break compatibility with YSI (YSI breaks AMX addresses or something like that). Some people are using YSI, so I added the FCNPC_OnInit callback, so just put yours FCNPC_Create inside the callback and everything will work fine.

https://github.com/ziggi/FCNPC/releases

ziggi avatar Aug 26 '23 11:08 ziggi