How to listen for Extension Response that gets sent to NPC?

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

Moderators: Lapo, Bax

sorencoder
Posts: 7
Joined: 19 Jan 2019, 15:53

How to listen for Extension Response that gets sent to NPC?

Postby sorencoder » 23 Jan 2019, 15:26

In my game, when there is not enough player to start the game, server automatically fills the remaining space with bots/NPCs.

Here is the code that creates a NPC:

Code: Select all

           
            User npc = api.createNPC("npc-" + npcCount, zone, false);
            Player player = playerBuilder.build();
            npc.setVariable(UserHelper.createPlayerVariable(player));
            npc.setVariable(UserHelper.createNicknameVariable(player));
            npc.setVariable(UserHelper.createTrophiesVariable(player));
           


This fake player (NPC) will be added to the room.

The problem is when room extension tries to order players to make their moves. Each player will receive an Extension Response from room extension.

This line of code sends SwitchTurn command to all users. In client side, user will update their game and send their move if it's their turn:

Code: Select all


send("SwitchTurn", null, room.getUserList());



How can I check if "SwitchTurn" was sent to the NPC and respond back?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to listen for Extension Response that gets sent to NPC?

Postby Lapo » 23 Jan 2019, 16:26

Hi,
the Extension send() method only works for connected players, while NPC have no real connection, as they are fake Users existing purely on the server side.
We have a two part article/tutorial in our blog that describes strategies to integrate NPCs in your game logic. See here:
https://smartfoxserver.com/blog/ways-of ... -game-p-1/
https://smartfoxserver.com/blog/ways-of ... -game-p-2/

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

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Baidu [Spider] and 38 guests