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

FCNPC_OnCreate isn't getting called. (Under OnGameModeInit) #200

Closed
CantBeKarma opened this issue Sep 26, 2019 · 6 comments
Closed

FCNPC_OnCreate isn't getting called. (Under OnGameModeInit) #200

CantBeKarma opened this issue Sep 26, 2019 · 6 comments

Comments

@CantBeKarma
Copy link

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.

@WoutProvost
Copy link
Contributor

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

WoutProvost commented Sep 27, 2019

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.

@CantBeKarma CantBeKarma changed the title FCNPC_OnCreate isn't getting called. FCNPC_OnCreate isn't getting called. (Under OnGameModeInit) Nov 5, 2019
@Fairuz-Afdhal
Copy link
Contributor

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

@0Z0SK0
Copy link

0Z0SK0 commented Feb 22, 2023

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

@0Z0SK0
Copy link

0Z0SK0 commented Feb 25, 2023

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

@ziggi
Copy link
Owner

ziggi commented Aug 26, 2023

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

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

5 participants