[Mod] Stationary NPCs [stationary_npc] [1]

kpo
Member
 
Posts: 38
Joined: Sun Mar 31, 2013 19:01

[Mod] Stationary NPCs [stationary_npc] [1]

by kpo » Sun Mar 31, 2013 22:40

This mod adds very peaceful NPCs which do not move around with configurability.
I based it off jojoa1997's peaceful_npc mod and did some optimizations the original mod could use in regards to global variables and the very busy on_step() function.
The idea here is to enable a lot of NPCs without killing the server.

Anyway the idea is to have NPCs standing/sitting/lying/waving/walking in place around villages, hanging in cages etc. etc.

First the summoner is built, and the NPC placed.
Textures can be changed by sneaking and punching the NPC.
Stances can be changed by sneaking and right clicking the NPC.
The NPC is removed by punching it to death (it has 10HP)

Players need the "stationarynpc" priviledge.

Like the peaceful_npc mod the NPCs will turn towards the player if it is close. Sitting and laying NPCs will stay put of course.

Try it here and tell me if this is useful/what enhancements could be interesting:
http://ompldr.org/vaHk1ZA/stationary_npc.zip

Requires 0.44 server (developed on 0.45 daily-build)
BR/kpo
Last edited by kpo on Sun Mar 31, 2013 22:41, edited 1 time in total.
 

markveidemanis
Member
 
Posts: 211
Joined: Thu Sep 27, 2012 15:41

by markveidemanis » Mon Apr 01, 2013 12:00

Can you make me a version of the mod where there is 1 skin, 1 init.lua file and make the npc spawning an admin feature, shorten the nodenames to npc:npc
BitCoin: 1Eq4arvykGNa1YC2DbJpWcwGfMvtFGjAoR
 

User avatar
jojoa1997
Member
 
Posts: 2890
Joined: Thu Dec 13, 2012 05:11

by jojoa1997 » Mon Apr 01, 2013 12:26

Why it is nice to have multiple skins. If it is OK with you I want to add a version of this into my mod but things will be changed. I will give credit of course
Coding;
1X coding
3X debugging
12X tweaking to be just right
 

kpo
Member
 
Posts: 38
Joined: Sun Mar 31, 2013 19:01

by kpo » Mon Apr 01, 2013 14:36

jojoa1997 wrote:Why it is nice to have multiple skins. If it is OK with you I want to add a version of this into my mod but things will be changed. I will give credit of course


By all means go ahead :-) This is pretty much your own code, textures etc. I just made all variables local and removed the three types of summoner because I can change the texture and stance by hitting the poor NPCs ;-)

In the on_step() function you will notice that I moved things around to try to let the function exit as fast as possible.
All the mob/cart mods have the very same issue of causing serious lagging when many entities are instanced because really long on_step() functions are run for each and every one of them.

Also I found from reading on the Lua language, that using "local" as much as possible is a performance booster outside of leaving the global namespace clean for better mod compatibility.
It is even suggested that this is the best code:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local my_var = {...}
local myfunc = function()
  local my_var = my_var

  <do sth. with my_var>
end


The idea is that the engine needs only search the closest scope(s) which is faster than getting everything from the global scope.

I'll look forward to seeing what you can do with my mod incorporated into the peaceful_npc mod (which I like but needed the NPCs to stay put :-) )
 

Sokomine
Member
 
Posts: 2980
Joined: Sun Sep 09, 2012 17:31

by Sokomine » Tue Apr 02, 2013 17:10

I've worked on something similar based on mobf because I like the behaviour of the peaceful_npc but want the functionality of the mobf framework. The trader-mobs can now sit on suitable furniture (bench, chair, armchair, toilet) and "sleep" in a bed (several types of beds supported). They only do so when they are two or less blocks away from a furniture node when they randomly enter the appropriate state.
When sitting on something, the mob looks in the appropriate direction. The mob also comment a lot on what they do and send chat messages to singleplayer. This is mostly for debugging but may lead to some more "life" later on.
A list of my mods can be found here.
 

kpo
Member
 
Posts: 38
Joined: Sun Mar 31, 2013 19:01

by kpo » Tue Apr 02, 2013 20:15

Sokomine wrote:I've worked on something similar based on mobf because I like the behaviour of the peaceful_npc but want the functionality of the mobf framework. The trader-mobs can now sit on suitable furniture (bench, chair, armchair, toilet) and "sleep" in a bed (several types of beds supported). They only do so when they are two or less blocks away from a furniture node when they randomly enter the appropriate state.
When sitting on something, the mob looks in the appropriate direction. The mob also comment a lot on what they do and send chat messages to singleplayer. This is mostly for debugging but may lead to some more "life" later on.


It looks very nice and definitely has a purpose.
My thoughts while hacking up my first attempt on a mod here was that anything moving about is using the on_step() function which according to the API is called approximately every 0.05 seconds. Let's multiply this by say 40 mobs and some old hardware (or an Atom based server in my case) and we have 30% CPU utilisation with just a single player present. Add more players and the game will come to a grinding halt fast.
So. I think we need at least two types of "mob" mods:
1) One like mine here (likely not that one :-) but similar) that has a really fast or even non-existing on_step() function.
This would be used for bulk population like traders (not moving around but sensitive to clicks/punches), prisoners, people
in houses, standing around and providing missions and what not. We see those all over the place in other MMORPGs.
Key point: They are interactive but not moving around at all => low resource demand
2) Moving mobs like farm animals, predators, golems, robots (in a broad sense of programmable automation), and what not.
There will not be tons of these but we will still need highly optimised code.

Regarding 2) I was wondering if we are able to control ALL moving mobs in a single "master" on_step() call instead of having one defined for each and every entity. Sort of a "master controller" with a table of all mobs wading through the lot and adjusting all the parameters on all mobs at once.

Also another thing I am wondering about is the ability to simply disable a mob (freeze it) if no players are near. I mean, why move around if no-one is there to see it? I'd like code like "if distance_to_nearest_player() < 20 then <act> else return"
Trains could be different and always running but probably better implemented by using mesecons to "call" one to ride.

Does this make any sense?
 

Sokomine
Member
 
Posts: 2980
Joined: Sun Sep 09, 2012 17:31

by Sokomine » Wed Apr 03, 2013 10:24

Admittedly, an Atom might have trouble pretty soon. Your idea of mobs that are passive but react to e.g. clicking is not bad. The trader that comes with mobf does just that. Most trouble seems to have arisen from spawning mobs and handling collusion, but you better talk to sapier about that. Putting animals into a simple environment where they don't fall and don't have to jump might fascilitate the on_step handling considerably.

kpo wrote:Also another thing I am wondering about is the ability to simply disable a mob (freeze it) if no players are near. I mean, why move around if no-one is there to see it? I'd like code like "if distance_to_nearest_player() < 20 then <act> else return"
Trains could be different and always running but probably better implemented by using mesecons to "call" one to ride.

To my knowledge, this is already so. Entitys that are not within a certain range of players are deactivated. That's why they have an on_activate handler and why travelling trains without nearby players would never arrive at their destination.
A list of my mods can be found here.
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 6 guests

cron