{NEW} Npc Extension Example

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

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

{NEW} Npc Extension Example

Postby Lapo » 09 Nov 2008, 15:51

Hello everyone,
by popular demand here is a quick example of NPC usage :D

The example extension uses the AvatarChat client and adds a new room with an NPC that moves around and sends public messages to the people in that same room.

The extension is written in Java, it is very simple and fully commented.

How to test it:
Unzip the archive and copy the it.gotoandplay.extensions.examples.npc package to the javaExtensions/ folder.

Open your config.xml, locate the simpleChat Zone and add the extension like this:

Code: Select all

<Extensions>   
   <extension name="npcExt" className="it.gotoandplay.extensions.examples.npc.NpcAvatarExample" type="java" />
</Extensions>


Make sure you also add this tag in the general server configuration:

Code: Select all

<EnableNPC>true</EnableNPC>


Finally restart the SmartFoxServer and launch the provided client example (04_avatarChat folder). You will find a new room with a user already inside that interacts with the other real users.

Image

-> Download here
Last edited by Lapo on 02 Feb 2009, 19:40, edited 1 time in total.
Lapo
--
gotoAndPlay()
...addicted to flash games
amenthes
Posts: 35
Joined: 22 Oct 2008, 11:55

Postby amenthes » 11 Nov 2008, 16:41

Just in time! Thanks Lapo!
laxersaz
Posts: 50
Joined: 30 Nov 2009, 16:19
Contact:

Postby laxersaz » 08 Dec 2009, 17:12

Hi Lapo,

I tried using the NPC example and I double checked every step. But my server log tells me this:
---
Zone: simpleChat

The Hall (id: 1, max: 50, pass:N)
The Kitchen (id: 2, max: 50, pass:N)
The Garden (id: 3, max: 50, pass:N)
The Bathroom (id: 4, max: 50, pass:N)
The Garage (id: 5, max: 50, pass:N)
The Living Room (id: 6, max: 50, pass:Y)
18:07:57.332 - [ WARNING ] > Problems loading extension called: it.gotoandplay.extensions.examples.npc.NpcAvatarExample2, Error: java.lang.ClassNotFoundException: it.gotoandplay.extensions.examples.npc.NpcAvatarExample2
18:07:57.757 - [ INFO ] > Zone Extension [ json ] created, for zone:simpleChat
[jsonSample.as]: JSON Example initialized
---

You see, the NPC-Example java class is not found even though it is located inside the javaExtensions folder. My folder structure is this:

javaExtensions/it/gotoandplay/extensions/examples/npc/NpcAvatarExample2.java

Is there anything I did wrong?

Thanks in advance,
Benjamin
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 08 Dec 2009, 17:26

Probably the javaExtension/ folder is not included in your classpath.
Try checking that.
Lapo

--

gotoAndPlay()

...addicted to flash games
laxersaz
Posts: 50
Joined: 30 Nov 2009, 16:19
Contact:

Postby laxersaz » 08 Dec 2009, 17:50

Oh yeah, that might be it!
Do you have a hint where/how I can do that on a Mac?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 08 Dec 2009, 18:03

It depends on how you run the server.
If you do it via the SmartFoxServer.app then you should check the classpath in {your-sfs-folder}/Server/start.sh

If you use version 1.6.6 or higher it is likely that the javaExtensions/ folder is not included in the classpath. This is because with this setting you can use the auto-reloading feature for java extensions.

If you are interested in learning more about this check the documentation here: http://www.smartfoxserver.com/docs/docP ... ons.htm#9a
Lapo

--

gotoAndPlay()

...addicted to flash games
laxersaz
Posts: 50
Joined: 30 Nov 2009, 16:19
Contact:

Postby laxersaz » 09 Dec 2009, 10:17

Alright, the npc example extension loads up now - thanks for your hints.

I'm getting a lot of java errors, though, at the end of the server log:

-----> SERVER READY <-----
[ it.gotoandplay.extensions.examples.npc.NpcAvatarExample2 ]: NpcRoom created.
Exception in thread "SystemHandler-1" java.lang.NoClassDefFoundError: it/gotoandplay/extensions/examples/npc/NpcAvatarExample2$1
at it.gotoandplay.extensions.examples.npc.NpcAvatarExample2.initNpcUsers(NpcAvatarExample2.java:119)
at it.gotoandplay.extensions.examples.npc.NpcAvatarExample2.prepareNpcs(NpcAvatarExample2.java:65)
at it.gotoandplay.extensions.examples.npc.NpcAvatarExample2.handleInternalEvent(NpcAvatarExample2.java:184)
at it.gotoandplay.smartfoxserver.controllers.MessageHandler.dispatchEvent(MessageHandler.java:147)
at it.gotoandplay.smartfoxserver.controllers.SystemHandler.processEvent(SystemHandler.java:188)
at it.gotoandplay.smartfoxserver.controllers.SystemHandler.run(SystemHandler.java:146)
at java.lang.Thread.run(Thread.java:637)
Caused by: java.lang.ClassNotFoundException: it.gotoandplay.extensions.examples.npc.NpcAvatarExample2$1
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
at java.lang.ClassLoader.loadClass(ClassLoader.java:254)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:399)
... 7 more

Do you have another tip for me on this issue?

Thanks!
Benjamin
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 10 Dec 2009, 09:19

Hi,
it looks to me as if the classpath is broken.
Can you show the full classpath you are using here?
Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
Aiidenb
Posts: 263
Joined: 16 Aug 2010, 22:08
Location: England
Contact:

Re: {NEW} Npc Extension Example

Postby Aiidenb » 20 Jan 2015, 16:49

Hello!

Although this is an old topic, how can I edit the NpcAvatarExample2.class file?

I want it to join a current room instead of creating one.

Thanks, Aiden.
Quackbay - The online virtual world for kids!

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 32 guests