Page 1 of 2
NPCs
Posted: 06 Jan 2011, 20:07
by GRIM2594
Does anyone have any experience, or sample code, with creating/using NPCs (serverside) with Smartfox 2x?
I would like to be able to create NPCs server side, that will hold data such as health, location, transform, ect and send it to the clients. I am unsure how to do this, as I only know how to create 1-execution extentions.
This is my theory, on how to set it up: (I am using Unity3d FYI)
- Server create/load NPC's from database on server start IF players are in that room/zone ELSE wait till players connect.
- Client checks to see if player location is within range, if so spawn NPC
- Server checks to see if NPC is aggressive, if so check to see if player is within range, if so send attack command
- Client deals with physics, checkLOS, ect and sends data to server
- Server decides best choices for tracking player from data sent by client
- Server sends choices to client, such as current position, transform ect
- Client deals with sending data to server if player does attack to target (not worried about aimbots or anything against NPCs)
- Server adjusts NPC health and checks if death, if NPC = dead send death packet to clients ect
I know how to do most of that, except store the data. I could probably figure it out, and store each NPC in an array, if I knew how to hold an instance open.
Anyone have any idea how I could do it? I read some about "createNPC", but not sure how that works either. There are almost no search results, even on Google, towards it.
Posted: 07 Jan 2011, 02:38
by tchen
I wouldn't use the createNPC in SFS2X. It eats up a CCU despite it being connectionless. It's good for testing user-related stuff without having to go through the action of booting up a client.
That said, NPCs' are just like any other object you'd hold in your Room extension's world model. I find it easier to treat it as a logical entity and distribute the actual storage across all the services it uses (eg: location, inventory, etc).
Posted: 07 Jan 2011, 03:00
by GRIM2594
tchen wrote:I wouldn't use the createNPC in SFS2X. It eats up a CCU despite it being connectionless. It's good for testing user-related stuff without having to go through the action of booting up a client.
That said, NPCs' are just like any other object you'd hold in your Room extension's world model. I find it easier to treat it as a logical entity and distribute the actual storage across all the services it uses (eg: location, inventory, etc).
Yeah, I was reading about some of the drawbacks of using the createNPC function.
Do you know if there are any examples of that being used, on the internet that I can view? (The Room extension's world model to store such data.) I haven't needed to create anything like this before for SmartFox's extenstions, so I find it a bit confusing.
After I study an example, it opens up more doors for my mind to create logic for it, but without any I am kind of stuck (lol).
Thanks for the comments.
Posted: 07 Jan 2011, 07:47
by Robbilie
U want to use them in unity right?
I use the fps demo extension, created a class like the itemclass and created all for mobs/npcs what was there for the items and aded some features like own lvl,own health, attack radius, attack system and many more things (stuck on the attacking part...)
u can do it this way...
Maybe want to join my team ( its only me atm xD)
im doin a mmorpg with unity client, if ur interested pm me

Posted: 07 Jan 2011, 09:26
by Lapo
http://docs2x.smartfoxserver.com/api-do ... FSApi.html
See
createNPC(...)
NPCs work like any other User in the system, once created.
The only difference is that there is no "real client" on the other side receiving any events, and the reason is obvious.
Suppose I create an NPC:
1- create the NPC
2- login the NPC via SFSApi.login(...)
3- join the NPC in the "Lobby Room" via SFSApi.joinRoom(...)
I don't need any events to be fired back at me saying that the user was logged in or joined. As soon as the command is executed the operation is complete.
In other words this is perfectly synchronous programming, no events to wait for.
Another problem might be a real User, connected via the internet, that sends a message to the NPC. How to know that?
Well it's quite simple you can either use a specific extension call to handle this case (recommended) or intercept the PUBLIC_MESSAGE event on the server side, check who is the recipient of the message and if it is the NPC apply the custom NPC logic.
Hope it helps
Posted: 07 Jan 2011, 23:12
by GRIM2594
Robbilie wrote:U want to use them in unity right?
Yes, I am using Unity3D.
I use the fps demo extension, created a class like the itemclass and created all for mobs/npcs what was there for the items and aded some features like own lvl,own health, attack radius, attack system and many more things (stuck on the attacking part...)
u can do it this way...
So will this hold open an instance of the extension, store the NPC's health, and return values upon client request? I need it to hold the data, indefinably, as well as hold any changes that may be made by clients (instead of running one time and exiting).
Maybe want to join my team ( its only me atm xD)
im doin a mmorpg with unity client, if ur interested pm me

Thank you for the interest, but I already have about 60% completed, of source code for the base features, for my title and would not be able to dedicate to any other project.
Posted: 07 Jan 2011, 23:16
by GRIM2594
Lapo wrote:Hope it helps
Thank you for the comments, Lapo.
Would you happen to know of any sample code, in maybe one of the cookbooks, for something like you suggest? I will give it some testing either way, but something visual would really help.
Also, does creating the NPC's like this use a lot of system resources? I intend for the system to be able to control thousands of NPC's simultaneously. What about CCU's, does it use up those as well?
Posted: 08 Jan 2011, 08:38
by Lapo
NPC use few resources as opposed to the previous SmartFox 1.x
And yes they are seen by the system as regular Users so they affect CCU
Posted: 08 Jan 2011, 16:12
by GRIM2594
Lapo wrote:NPC use few resources as opposed to the previous SmartFox 1.x
And yes they are seen by the system as regular Users so they affect CCU
Thanks for the response, Lapo. Unfortunately, I wont even be able to test using them because of the usage of CCU. I had planned on using the 2,000 user capped CCU license (per server), after I finish and run the game through testing phases... That wouldn't work, as there will be more NPC's than that; let alone player count.
I will figure something else out, no problem. Thank you for your time.
Posted: 08 Jan 2011, 16:39
by Lapo
Hi,
I will talk with my colleagues and discuss this issue. It's actually not entirely clear to me if the NPC affect the license limits or not.
Will give you an update as soon as it is sorted out.
Posted: 08 Jan 2011, 20:09
by Robbilie
shit i knew that i forgot something....
Tomorrow ill post my code k?
U dont need npcs in anyway the just make it more complicated than it is possible...
Posted: 08 Jan 2011, 20:50
by ThomasLund
Yeah - you can easily create NPC functionality without needed a new connection. Would obviously not work 100% similar to a real client, but you can simply have a code object in your world simulation that is updated periodically.
/T
Posted: 08 Jan 2011, 23:05
by tchen
Lapo wrote:Hi,
I will talk with my colleagues and discuss this issue. It's actually not entirely clear to me if the NPC affect the license limits or not.
Will give you an update as soon as it is sorted out.
Just for giggles, I had tried creating 100+ NPCs on the community edition and got locked out of logging into the admin console

Posted: 08 Jan 2011, 23:34
by GRIM2594
Lapo wrote:Hi,
I will talk with my colleagues and discuss this issue. It's actually not entirely clear to me if the NPC affect the license limits or not.
Will give you an update as soon as it is sorted out.
Thanks Lapo. I am sure you understand what an issue this could be, even with a small scale MMO (which I am aiming for).
My plans for population limiting was going to be based on the 2,000 CCU limit license, as I do not really want more than that on each server (due to game size, and compacting a lot of players in a small space). Paying 2x as much, just to use a built in feature, simply doesn't seem necessary. (I am in no way complaining either, just expressing my view.) I plan to launch the game with a single server, with 2k population limit; then increase the number of servers. (Instead of just increasing the population limit.)
Posted: 08 Jan 2011, 23:43
by GRIM2594
ThomasLund wrote:Yeah - you can easily create NPC functionality without needed a new connection. Would obviously not work 100% similar to a real client, but you can simply have a code object in your world simulation that is updated periodically.
/T
That is almost what I am after. The ability to store data via server-side, for each NPC.
Obviously I can create an extension for each NPC, but that is simply unrealistic as I will have thousands of NPC's.
At the moment, I have almost everything loaded through an external MySQL database. The server boots up, and loads data to the client upon request. This is how NPC's are loaded too, but right now I only have the data stored client-side (which is too easily able to cheat). The client determines everything, which works fine... but does not prevent cheating.
I want the server to do all of the health, damage, and other statistic calculations - instead of the client.
I am under the impression that I could do this with createNPC, but it uses a CCU which would then go against the CCU Limit per license.
I know there has to be another way, I just don't know of it yet. I am hoping someone will mention something, and it just "click". A lot of logic has came from something totally non-related, that I have sought after. (lol)