Client side NPC

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

densol
Posts: 14
Joined: 17 Feb 2023, 06:45

Client side NPC

Postby densol » 17 Feb 2023, 06:50

Hi all,

How to create and manage client side NPC user using JavaScript api

Can not find any informations here:
http://docs2x.smartfoxserver.com/api-docs/jsdoc/client/

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

Re: Client side NPC

Postby Lapo » 17 Feb 2023, 09:42

Hi,
NPCs are typically managed on the server side, rather than client side, because they are usually part of the game world and as such their state must be shared across all players. (Hence the need to simulate them on the server side)

Creating NPCs on the client side is no different from creating any other game entity in a single player game. The entity exists only on the player's client and it's not part of the multiplayer game world.

Which one are you trying to implement?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
densol
Posts: 14
Joined: 17 Feb 2023, 06:45

Re: Client side NPC

Postby densol » 17 Feb 2023, 10:37

Hi Lapo,

Thanks for fast reply

I need NPC client side only, please provide short example in js

Thank you
densol
Posts: 14
Joined: 17 Feb 2023, 06:45

Re: Client side NPC

Postby densol » 17 Feb 2023, 10:47

Also if client side NPC conned I want so room for 2 players shows as full for others
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client side NPC

Postby Lapo » 17 Feb 2023, 10:51

I don't have much to offer on this, sorry.
Client side NPC are not even related to SmartFoxServer. It's more of a generic game development question, which this forum is not about.

Generally speaking any enemy or interactible character in a game is an NPC. For example the ghosts in PacMan are NPCs.
You won't find a generic tutorial that will tell you how to do that, because specific NPC behavior is required for every differen game. I suggest you figure out exactly how these NPCs should work in your game and then spend some time trying to implement their basic behavior.

If you're entirely new to game development try asking on dedicated game development forums.

Good luck
Lapo

--

gotoAndPlay()

...addicted to flash games
densol
Posts: 14
Joined: 17 Feb 2023, 06:45

Re: Client side NPC

Postby densol » 17 Feb 2023, 12:01

I got this

And if I want to show that this client side NPC connected to the room I need to use server side SFS NPC implementation?

Maybe you have such example

I use JS for server extension too
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client side NPC

Postby Lapo » 17 Feb 2023, 16:43

Lapo

--

gotoAndPlay()

...addicted to flash games
densol
Posts: 14
Joined: 17 Feb 2023, 06:45

Re: Client side NPC

Postby densol » 22 Feb 2023, 11:26

Thank Lapo!

One more question out of this thread

Is there way to make chances in extension without reloading sfs server, for prompt development?
densol
Posts: 14
Joined: 17 Feb 2023, 06:45

Re: Client side NPC

Postby densol » 22 Feb 2023, 14:13

*changes in extension
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client side NPC

Postby Lapo » 22 Feb 2023, 15:09

Hi,
a restart is not needed.
By default every time you re-deploy an Extension (i.e. copy the jar file in its folder) it will be re-loaded by the server.

You can change this behavior from the AdminTool, in the Zone Configurator, but for your use case the default is what you need.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
densol
Posts: 14
Joined: 17 Feb 2023, 06:45

Re: Client side NPC

Postby densol » 29 Mar 2023, 08:09

Hi Lapo,

When I create NPC in the game extension and join it to game room other players do not see joined new player (NPC) in game lobby, but if reload the page, then new user appers.

What is the issue?

I use roomManager.getRoomList() to get roomlist on client side

And here code from extension:
bot = getApi().createNPC(botName, getParentZone(), false);
getApi().joinRoom(bot,getParentRoom());
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client side NPC

Postby Lapo » 29 Mar 2023, 08:42

Hi,
NPCs work exactly like any other User.
If the client app is listening for the SFSEvent.USER_ENTER_ROOM it will receive the event when the NPC joins the same Room(s)

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
densol
Posts: 14
Joined: 17 Feb 2023, 06:45

Re: Client side NPC

Postby densol » 31 Mar 2023, 06:15

yes, client app is listening for the SFSEvent.USER_ENTER_ROOM, but it do not fired on NPC entering the room

so, game room userCount not changed in sfs.roomManager.getRoomList()

but after logout and login I see changed user count

sfs.send(new SFS2X.LogoutRequest());
sfs.send(new SFS2X.LoginRequest(uName));
densol
Posts: 14
Joined: 17 Feb 2023, 06:45

Re: Client side NPC

Postby densol » 31 Mar 2023, 12:24

Lapo can you suggest please where is the issue?
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client side NPC

Postby Lapo » 31 Mar 2023, 13:44

I am sorry, I don't know.
The mechanism I have described works perfectly fine. We have tested and used a thousand times. There must be some other problem specific to your code but without more details I am not able to guess what might be going on.

Are you sure the NPC is actually cteated correctly? Check via the AdminTool. You can go in the Room where it is supposed to be joined and see if it's name appears.
If not, check the server logs ... there is probably an NPC creation error.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X HTML5 / JavaScript API”

Who is online

Users browsing this forum: No registered users and 15 guests