How to force bot to join a room after log in zone

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

Persy
Posts: 9
Joined: 20 Sep 2021, 18:52

How to force bot to join a room after log in zone

Postby Persy » 21 Sep 2021, 04:59

I'm trying to create a bot as a real user

using:

Code: Select all

_server.createNPC("robot", "127.0.0.1", 9339, "test")


The bot login to the zone but I can't find him as it didn't join to room

it's only in appear in the zone but not in any room !

how can I make him join to specfic room?

should I add anything ?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to force bot to join a room after log in zone

Postby Lapo » 23 Sep 2021, 08:01

The createNPC(...) method connects and logs the NPC in the server's Zone. It returns the User object (just like any other connected User) and you can then use that object to join the NPC using the _server.joinRoom(...) method.

https://www.smartfoxserver.com/docs/1x/ ... /index.htm

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
Persy
Posts: 9
Joined: 20 Sep 2021, 18:52

Re: How to force bot to join a room after log in zone

Postby Persy » 23 Sep 2021, 14:26

Oh now I understand

Another question please

Code: Select all

_server.joinRoom(userObj, currId, true, newId)


To get the useObj of the Npc

Do I get it by :
getUserById(NpcId)?

And for currId it will be -1 because it didn't join any room yet righy?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to force bot to join a room after log in zone

Postby Lapo » 23 Sep 2021, 14:29

The User object is returned by the _server.createNPC() function

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
Persy
Posts: 9
Joined: 20 Sep 2021, 18:52

Re: How to force bot to join a room after log in zone

Postby Persy » 08 Oct 2021, 12:06

Persy wrote:I'm trying to create a bot as a real user

using:

Code: Select all

_server.createNPC("robot", "127.0.0.1", 9339, "test")


The bot login to the zone but I can't find him as it didn't join to room

it's only in appear in the zone but not in any room !

how can I make him join to specfic room?

should I add anything ?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to force bot to join a room after log in zone

Postby Lapo » 09 Oct 2021, 10:18

As I said in my previous post the User object is returned by the createNpc() function.
Once you have the User object you can proceed to join the NPC in its Room via the joinRoom function.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 28 guests