Can I create NPC users in Zone Extension's init() method?

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

KrinalDhaduk
Posts: 13
Joined: 12 Nov 2019, 06:50
Location: Surat,Gujarat

Can I create NPC users in Zone Extension's init() method?

Postby KrinalDhaduk » 15 Jan 2020, 13:08

I have been trying to create NPC Users initially in extension init() and getting Null Ref. I have posted server trace below that includes logs as well.
It looks like SmartFoxServer instance is null somehow





18:35:06,457 INFO [main] v2.SmartFoxServer - Boot sequence starts...
18:35:06,779 INFO [main] core.SFSEventManager - AnonymousService-1 initialized
18:35:06,794 INFO [main] impl.DefaultFileReplicator - Using "C:\Users\KRINAL~1.DHA\AppData\Local\Temp\vfs_cache" as temporary files store.
18:35:06,836 INFO [main] v2.SmartFoxServer - License loaded:

==========================================
LICENSE DETAILS
------------------------------------------
Type : Community Edition
Max users : 100
==========================================

18:35:06,837 INFO [main] managers.SFSBannedUserStorage - BanUserStorage initialized
18:35:06,846 INFO [main] managers.SFSBannedUserManager - BanUser data loaded: 0 records.
18:35:06,850 INFO [main] v2.SmartFoxServer - Protocol Type is: BINARY
18:35:06,853 INFO [main] config.DefaultConfigLoader - Loading: zones\BasicExamples.zone.xml
18:35:06,871 INFO [main] config.DefaultConfigLoader - Loading: zones\Ludo.zone.xml
18:35:06,883 INFO [main] config.DefaultConfigLoader - Loading: zones\MPLSFS2X.zone.xml
18:35:06,892 INFO [main] managers.SFSZoneManager -

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
>> Zone: MPLSFS2X
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

18:35:06,938 INFO [main] Extensions - {IndianRummy}: IndianRummyExtension:: IndianRummy game Extension for SFS2X started.
smartFoxServer.getZoneManager().getZoneList()={ Zone: MPLSFS2X }
18:35:06,940 INFO [main] Extensions - {IndianRummy}: IndianRummyExtension:: IndianRummy Extension Match Making Initialized!
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
com.smartfoxserver.v2.SmartFoxServer@5d0bf09b
com.smartfoxserver.v2.api.SFSApi@793f29ff
{ Zone: MPLSFS2X }
1
java.lang.NullPointerException
at com.smartfoxserver.v2.api.SFSApi.createNPC(SFSApi.java:688)
at com.artoon.core.MatchMakingUtility.createNPCUsers(MatchMakingUtility.java:977)
at sfs2x.extensions.IndianRummy.IndianRummyExtension.init(IndianRummyExtension.java:95)
at com.smartfoxserver.v2.entities.managers.SFSExtensionManager.createExtension(SFSExtensionManager.java:303)
at com.smartfoxserver.v2.entities.managers.SFSZoneManager.createZone(SFSZoneManager.java:426)
at com.smartfoxserver.v2.entities.managers.SFSZoneManager.initializeZones(SFSZoneManager.java:239)
at com.smartfoxserver.v2.SmartFoxServer.start(SmartFoxServer.java:292)
at com.smartfoxserver.v2.Main.main(Main.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.exe4j.runtime.LauncherEngine.launch(Unknown Source)
at com.exe4j.runtime.WinLauncher.main(Unknown Source)
at com.install4j.runtime.launcher.WinLauncher.main(Unknown Source)
18:35:06,965 INFO [main] managers.SFSRoomManager - Room created: { Zone: --=={{{ AdminZone }}}==-- }, [ Room: AdminRoom, Id: 1, Group: default, isGame: false ], type = SFSRoom
18:35:06,995 INFO [main] core.AdminToolService - AdminTool Service started
18:35:07,102 INFO [SFSWorker:Sys:1] v2.SmartFoxServer - Listening Sockets: { 0.0.0.0:9933, (Tcp) } { 127.0.0.1:9933, (Udp) }
18:35:07,103 INFO [SFSWorker:Sys:1] v2.SmartFoxServer -
_____ _____ _____ ___ __ __
| __| __| __| |_ | | |
|__ | __|__ | | _|- -|
|_____|__| |_____| |___|__|__|
_____ _____ _____ ____ __ __
| __ | __| _ | \| | |
| -| __| | | |_ _|
|__|__|_____|__|__|____/ |_|
[ 2.13.0 ]

18:35:07,103 INFO [SFSWorker:Sys:1] v2.SmartFoxServer - SmartFoxServer 2X (2.13.0) READY!
18:35:08,420 INFO [main] v3.SessionFilter - BlueBox-2X Service (3.1.0) READY.


User avatar
Lapo
Site Admin
Posts: 21217
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Can I create NPC users in Zone Extension's init() method?

Postby Lapo » 15 Jan 2020, 14:36

Hi,
it's not possible to create Users (such as NPCs) in the init() method because Zones are created before the server is completely started up.

To accomplish what you're trying to do you need to add a server side listener for the SERVER_READY event and execute the code that creates the NPCs there.

A quick way to do it would be this:

Code: Select all

@Override
public void init()
{
   addEventHandler
   (
      SFSEventType.SERVER_READY,
      new BaseServerEventHandler()
      {
         @Override
         public void handleServerEvent(ISFSEvent event) throws SFSException
         {
            // NPC code goes here
         }
      }
   );
}


Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 18 guests