NPC system

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

Moderators: Lapo, Bax

Devops
Posts: 23
Joined: 27 May 2020, 15:23

NPC system

Postby Devops » 05 Jun 2020, 15:38

I am creating NPC(Bots) and adding them to room if players are not sufficient to start the game.

However, I have observed that bots with same name cannot exist and throws error.
The bots I would need is just room specific and those npc can be deleted once the match is complete.

- How to handle bots with same name? If that cannot be done how can I ensure unique names for bots while creating NPC?

- How to delete these NPC users once the game in room is complete?

- I did read that there is a limitation of 500 NPC. If every room in the game has 2 NPC then this limit will be reached on just 250 rooms created. How to deal with it?
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NPC system

Postby Lapo » 06 Jun 2020, 07:31

Devops wrote:However, I have observed that bots with same name cannot exist and throws error.

Yes, that's correct. NPCs are Users like any other (only they are not connected via the internet), so their user name must be unique as well.


- How to handle bots with same name? If that cannot be done how can I ensure unique names for bots while creating NPC?

Add a unique counter in front of the name of the NPC.
Such as NPC_1, NPC_2, ... NPC_432

- How to delete these NPC users once the game in room is complete?

Code: Select all

getApi().disconnectUser( npcUser );


- I did read that there is a limitation of 500 NPC. If every room in the game has 2 NPC then this limit will be reached on just 250 rooms created. How to deal with it?

There is no such limitation, you can create as many NPCs as you want,
Keep in mind that because NPCs are seen by the server as Users, they will count as Users for your license too. So if your license is limited to 1000 CCU, you can create a max of a 1000 NPCs.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
Devops
Posts: 23
Joined: 27 May 2020, 15:23

Re: NPC system

Postby Devops » 06 Jun 2020, 13:44

Add a unique counter in front of the name of the NPC.
Such as NPC_1, NPC_2, ... NPC_432


This sounds great but how can I get the count of NPC already created and increment it. NPC are created for each room at different times so how can I get this count. Is there any property to get the count of npc?

Code: Select all

getApi().disconnectUser( npcUser );

If I created an NPC with name NPC_1 and then disconnect it using above code.
Does this disconnect delete that NPC completely? So can I create a new NPC again(createNpc()) with same name as NPC_1 after doing disconnectUser?


if your license is limited to 1000 CCU, you can create a max of a 1000 NPCs.

Could you please suggest me an approach if there is any that could be used instead of NPC in my game.
In my game, NPC will be added when there are not enough players(4 - 6 players max) in the room and a real player will be hosting these NPC's(host player will send position events to smartfox that will broadcast to other players in room for syncing).
In the gameplay there is no heavy logic for NPC. It is just going to be position syncing of these NPC through smartfox events and also there are few details that needs to be stored about NPC like their weapons and outfit.
I did see MMOItems to be used in MMORooms for this purpose, but could not find any for normal rooms.
It would be really helpful if you could guide me through any other approach for Bot system in my game.

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

Re: NPC system

Postby Lapo » 06 Jun 2020, 16:15

Devops wrote:[
This sounds great but how can I get the count of NPC already created and increment it. NPC are created for each room at different times so how can I get this count. Is there any property to get the count of npc?

Keeping a counter seems like a good idea.

If I created an NPC with name NPC_1 and then disconnect it using above code.
Does this disconnect delete that NPC completely? So can I create a new NPC again(createNpc()) with same name as NPC_1 after doing disconnectUser?

Yes

Could you please suggest me an approach if there is any that could be used instead of NPC in my game.

NPCs are the most convenient way to create bots in your game.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 129 guests