NPC player

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

Moderators: Lapo, Bax

kayosys
Posts: 9
Joined: 19 Nov 2019, 05:55

NPC player

Postby kayosys » 19 Nov 2019, 06:09

Hi
i want to create NPC player for my game. i don't find any document where explained how i can deploy on server and how can i connect NPC player with server like zone and room level extension.can you explain which Api (.jar) i need for developing NPC player.
User avatar
Lapo
Site Admin
Posts: 21117
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NPC player

Postby Lapo » 19 Nov 2019, 09:05

Hi,
sure we have two articles dedicated to the topic of NPC creation and management:
1) https://smartfoxserver.com/blog/ways-of ... -game-p-1/
2) https://smartfoxserver.com/blog/ways-of ... -game-p-2/

If something is not clear let us know.
Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
kayosys
Posts: 9
Joined: 19 Nov 2019, 05:55

Re: NPC player

Postby kayosys » 19 Nov 2019, 09:17

Hi
Thanks for reply,
i already seen the document and i created NPC player according to document but i am stuck .How to NPC deploy on server ?
User avatar
Lapo
Site Admin
Posts: 21117
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NPC player

Postby Lapo » 19 Nov 2019, 09:34

The NPC is created on the server side. When it is created it is represented by a User object, just like any other connected player.
I don't understand what you mean by "deploy on server"? It is already on the server.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
kayosys
Posts: 9
Joined: 19 Nov 2019, 05:55

Re: NPC player

Postby kayosys » 19 Nov 2019, 09:48

I am getting this issue.When i am trying to execute main file.

Code: Select all

Exception in thread "main" java.io.FileNotFoundException: config.properties (The system cannot find the file specified)
   at java.io.FileInputStream.open0(Native Method)
   at java.io.FileInputStream.open(FileInputStream.java:195)
   at java.io.FileInputStream.<init>(FileInputStream.java:138)
   at java.io.FileInputStream.<init>(FileInputStream.java:93)
   at com.abc.npc.client.NPCManager.main(NPCManager.java:66)
User avatar
Lapo
Site Admin
Posts: 21117
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NPC player

Postby Lapo » 19 Nov 2019, 09:54

That's an issue in your code as per the stack trace:

Code: Select all

com.abc.npc.client.NPCManager.main(NPCManager.java:66)

In line 66 of your main() method you're trying to open a file that is not found at the location you've specified.
Lapo

--

gotoAndPlay()

...addicted to flash games
kayosys
Posts: 9
Joined: 19 Nov 2019, 05:55

Re: NPC player

Postby kayosys » 20 Nov 2019, 04:36

Hi
Thanks @Lapo Its working now . if there any issue,i will let you know.
kayosys
Posts: 9
Joined: 19 Nov 2019, 05:55

Re: NPC player

Postby kayosys » 23 Nov 2019, 05:52

Hi
i created npc player according this document https://smartfoxserver.com/blog/ways-of ... -game-p-2/ .
now how i can check difference between npc user and real user on zone.
User avatar
Lapo
Site Admin
Posts: 21117
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NPC player

Postby Lapo » 23 Nov 2019, 11:09

You can use User.isNpc() which returns true only when the player is not a connected user.
Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
kayosys
Posts: 9
Joined: 19 Nov 2019, 05:55

Re: NPC player

Postby kayosys » 26 Nov 2019, 04:42

Hi,
i am already used User.isNpc() .But it return always false.
User avatar
Lapo
Site Admin
Posts: 21117
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NPC player

Postby Lapo » 26 Nov 2019, 09:24

It should only return false when the User is not an NPC.

If you do this:

Code: Select all

User test = getApi().createNPC("TestNPC", getParentZone(), false);
trace("Is this an NPC?" + test.isNPC());

you will get true, 100% of the times.

I'd recommend reviewing your code and making sure everything is in order.
If you can't find the problem, give us more details.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
kayosys
Posts: 9
Joined: 19 Nov 2019, 05:55

Re: NPC player

Postby kayosys » 26 Nov 2019, 09:57

1.I have created npc player according to this document https://smartfoxserver.com/blog/ways-of ... -game-p-2/
2.Then Connected this player using main function.

Code: Select all

 public static void main(String[] args) throws Exception {
        Properties props = new Properties();
        String resourceName = "config.properties"; // could also be a constant
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        try(InputStream resourceStream = loader.getResourceAsStream(resourceName)) {
            props.load(resourceStream);
        }


        new NPCManager(props);
    }


3.After connected i trying to find user on zone level extenstion using this

Code: Select all

  for(User user:getZoneDetails().getUserList()){
     System.out.println("-------------"+user.getName());
  }


is this right process? If not right please correct me.

please tell me correct complete process if my process is wrong.
User avatar
Lapo
Site Admin
Posts: 21117
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NPC player

Postby Lapo » 26 Nov 2019, 14:41

I am confused as to what you're doing.
In your code I don't see a single reference to any object that is part of the SFS API. The client side code for example... where do you instantiate the client API? And where do you start the connection?

Are you trying to determine if a User is an NPC from the client side? If so, there is no such information on the client side, only server side.

Can you please clarify?
Lapo

--

gotoAndPlay()

...addicted to flash games
kayosys
Posts: 9
Joined: 19 Nov 2019, 05:55

Re: NPC player

Postby kayosys » 27 Nov 2019, 06:29

I am also confused. Actually I want to create a bot which perform as a normal player in a snake and ladder game. The basic functionality of the normal player are as follows:-
- Connect with the SFS Connect.
- Connect with the SFS Room.
- Handling game informations from the mysql database using APIs.
- Handling the cmd commands i.e. cmd for move, turn, dice etc
I need all these functionality with my bot as well.
So can you please help me out what will be the right way to handle these functionality with bot. Please explain for each steps.
User avatar
Lapo
Site Admin
Posts: 21117
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NPC player

Postby Lapo » 27 Nov 2019, 10:24

So you're creating a client-side NPC, one that doesn't run on the server side but rather is running as an external program, using the client API to connect to SFS.

In this case there is no way for the server to know wether or not a certain User is a "bot". You will need to flag it manually so that you can recognize it later. You could use a UserVariable for example.

As regards how to deploy the bot, you have multiple choices:
1) it could run on the server side and connect using "localhost", this way there is almost zero lag between client and server
2) it could run somewhere else (another server typically) and connect to SmartFox via it's IP address or domain name.

What to choose depends on your needs. If you're going to run many of these bots running all of them on the same server where SFS is running might use too many resources. A dedicated server for bots might be better in this case.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 18 guests