Post your modding questions here

Locked
tfranko
Member
Posts: 13
Joined: Mon Oct 06, 2014 22:34

Re: Post your modding questions here

by tfranko » Post

I'd like some help with entities and assigning static data to them and displaying this static data. I think this is what I want, anyway.

Ultimately, I'd like the player to be able to right click on an entity which will open a formspec and allow the user to enter a name for the entity. I'd like that name to then be displayed either above the entity all of the time or when the player hovers over the entity. Then, if the player wants to right click on the entity again in order to change the name, the formspec will open again and the player can change the name if desired.

I looked at the LUAEntitySAO page: http://dev.minetest.net/LuaEntitySAO and see the get_staticdata(self) function. I've also looked here: https://rubenwardy.github.io/minetest_d ... specs.html, but I'm so far unable to use these resources to put what I want together.

Let me know if I need to share any other info. Any help with this will be appreciated.

Thank you.

User avatar
TeTpaAka
Member
Posts: 141
Joined: Sat Dec 28, 2013 21:54

Re: Post your modding questions here

by TeTpaAka » Post

I'd like that name to then be displayed either above the entity all of the time or when the player hovers over the entity.
Take a look at this:
viewtopic.php?f=9&t=7321&hilit=npc
It uses textures for every char that is displayed.

tfranko
Member
Posts: 13
Joined: Mon Oct 06, 2014 22:34

Re: Post your modding questions here

by tfranko » Post

TeTpaAka wrote:
I'd like that name to then be displayed either above the entity all of the time or when the player hovers over the entity.
Take a look at this:
viewtopic.php?f=9&t=7321&hilit=npc
It uses textures for every char that is displayed.
Thank you! It looks complicated. Do you know of any easier way that doesn't use entities/textures for the lettering? I'd settle for displaying infotext about the entity when hovering the mouse over the entity (i.e. mouseover). I see that infotext is possible for nodes, but it doesn't appear to be possible for entities.

I'm using Carbone's mobs mod to create the entity, so I'm not sure how I would integrate the part of the code I want from the link you shared above with the mobs mod. I'll keep working on it though.

LonelyCrow
New member
Posts: 2
Joined: Sat Jan 10, 2015 16:17
In-game: Lonelycrow

Re: Post your modding questions here

by LonelyCrow » Post

Any Idea on how to access the World Directory? Sorry, I am rather new to modifying software and the lingo for that matter.

tfranko
Member
Posts: 13
Joined: Mon Oct 06, 2014 22:34

Re: Post your modding questions here

by tfranko » Post

tfranko wrote:I'm using Carbone's mobs mod to create the entity, so I'm not sure how I would integrate the part of the code I want from the link you shared above with the mobs mod. I'll keep working on it though.
I came up with the following relatively simple solution as an alternative. What do you think? Is there a better way to do this?

This is the function to manage the HUD text:

Code: Select all

local name_hud = nil

function display_mob_name(player_object, text)
-- Function to flash text near cursor.

    local player = player_object

    if name_hud == nil then

        name_hud = player:hud_add({
	    hud_elem_type = "text",
	    position = {x=.5, y=.5},
	    alignment = {x=-0, y=0},
	    offset = {x=0, y=-18},
	    text =  text,
	    number = 0xFFFF00, -- Color as 0xRRGGBB
	}) -- name_hud()

    else

        player:hud_change(name_hud, 'text', text)

    end -- if/then

    minetest.after(5, function()
        player:hud_remove(name_hud)
        name_hud = nil
    end) -- after()

end -- HUD function
Then, I call this function in the entity's on_rightclick() property:

Code: Select all

display_mob_name(clicker, self.mob_name)
The end result puts the entity name just above the crosshair for 5 seconds when the player right-clicks the entity.

This is better than nothing, but it's obviously not ideal. I'd rather have the HUD text follow the entity for five seconds, or permanently, if that wouldn't impact performance too much. Any ideas?

*edit: spelling correction.*

User avatar
Hybrid Dog
Member
Posts: 2774
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Post your modding questions here

by Hybrid Dog » Post

LonelyCrow wrote:Any Idea on how to access the World Directory? Sorry, I am rather new to modifying software and the lingo for that matter.
http://dev.minetest.net/minetest.get_worldpath

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

User avatar
CWz
Member
Posts: 197
Joined: Tue Dec 24, 2013 17:01
GitHub: chaoswormz
IRC: CWz
In-game: CWz
Location: Banana Land

Re: Post your modding questions here

by CWz » Post

how do I modify the bucket mod to check if a player has bucket priv before dumping out it contents? or have have it check if the player own the area before it dumps it's contents.

User avatar
ArguablySane
Member
Posts: 116
Joined: Sun Oct 12, 2014 21:29

Re: Post your modding questions here

by ArguablySane » Post

Is it safe to use the lua functions math.randomseed(seed) and math.random() to generate random numbers for each chunk during mapgen? I don't want it to behave differently on different computers.

Also, does anyone know of an elegant way to divide the world into Voroni cells (or similar) during mapgen? Subdividing any given chunk requires knowledge of the random points in adjacent chunks, but I see no way to get the random seed for adjacent chunks.
The above post and any ideas expressed therein are released to the public domain under a Creative Commons CC0 license.

User avatar
kaeza
Moderator
Posts: 2162
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza
Location: Montevideo, Uruguay
Contact:

Re: Post your modding questions here

by kaeza » Post

ArguablySane wrote:Is it safe to use the lua functions math.randomseed(seed) and math.random() to generate random numbers for each chunk during mapgen? I don't want it to behave differently on different computers.
`math.random` is a straightforward interface to C's stdlib `random` function. I'm not sure if every C lib out there uses the same algorithm. Minetest's `PseudoRandom` class is the same across all supported systems (albeit with some limitations), so you should probably use it to be sure.
ArguablySane wrote:Also, does anyone know of an elegant way to divide the world into Voroni cells (or similar) during mapgen? Subdividing any given chunk requires knowledge of the random points in adjacent chunks, but I see no way to get the random seed for adjacent chunks.
I recall someone making such a mapgen. Paramat could help you there.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal

User avatar
Kalabasa
Member
Posts: 37
Joined: Tue Jan 06, 2015 17:36
GitHub: Kalabasa
IRC: Kalabasa
In-game: Kalabasa

Re: Post your modding questions here

by Kalabasa » Post

Is there any way to change the length of a day? Change the speed of time of day.
insert signature here

User avatar
Hybrid Dog
Member
Posts: 2774
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Post your modding questions here

by Hybrid Dog » Post

kaeza wrote:
ArguablySane wrote:Is it safe to use the lua functions math.randomseed(seed) and math.random() to generate random numbers for each chunk during mapgen? I don't want it to behave differently on different computers.
`math.random` is a straightforward interface to C's stdlib `random` function. I'm not sure if every C lib out there uses the same algorithm. Minetest's `PseudoRandom` class is the same across all supported systems (albeit with some limitations), so you should probably use it to be sure.
And math.random is about 6 times faster than PseudoRandom, isn't it?
Kalabasa wrote:Is there any way to change the length of a day? Change the speed of time of day.
https://github.com/minetest/minetest/bl ... ample#L376
there are settings to configure it

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

User avatar
Don
Member
Posts: 1643
Joined: Sat May 17, 2014 18:40
GitHub: DonBatman
IRC: Batman
In-game: Batman

Re: Post your modding questions here

by Don » Post

Kalabasa wrote:Is there any way to change the length of a day? Change the speed of time of day.
Server commands are the easy way to change time. Go down to world manipulation.http://wiki.minetest.com/wiki/Server_commands
Many of my mods are now a part of Minetest-mods. A place where you know they are maintained!

A list of my mods can be found here

User avatar
ArguablySane
Member
Posts: 116
Joined: Sun Oct 12, 2014 21:29

Re: Post your modding questions here

by ArguablySane » Post

Regarding ABMs, is there any way to detect if a node is near the edge of the active region of the map? I'm trying to create more dynamic trees, but when the trunk lies just outside the active region the active leaves stop receiving their keep-alive messages and die. I could put the code to check if the tree is still intact in the leaf node ABMs, but that seems very inefficient since there are maybe 80 leaf nodes but only 1 root node per tree.

Regarding metadata, does it get erased if I use minetest.set_node to replace a node with a different one?
The above post and any ideas expressed therein are released to the public domain under a Creative Commons CC0 license.

User avatar
kaeza
Moderator
Posts: 2162
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza
Location: Montevideo, Uruguay
Contact:

Re: Post your modding questions here

by kaeza » Post

ArguablySane wrote:Regarding ABMs, is there any way to detect if a node is near the edge of the active region of the map? I'm trying to create more dynamic trees, but when the trunk lies just outside the active region the active leaves stop receiving their keep-alive messages and die. I could put the code to check if the tree is still intact in the leaf node ABMs, but that seems very inefficient since there are maybe 80 leaf nodes but only 1 root node per tree.
I'd suggest taking "ignore" (the name of the "unexisting node", i.e. parts of the map not loaded yet) as if it were part of the trunk. That way if the leaves are just on the border of the active map, they will take the unloaded map as if it were a tree.
ArguablySane wrote:Regarding metadata, does it get erased if I use minetest.set_node to replace a node with a different one?
Yes. You should use `minetest.swap_node` in that case.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal

User avatar
Merlin
Member
Posts: 63
Joined: Tue Dec 09, 2014 22:07
GitHub: sct-0
In-game: my
Location: germany

Re: Post your modding questions here

by Merlin » Post

What is a mesh node?

People name it everywhere, but I cannot find a definition of it(at least not one which seems to have anything to do with Minetest).

4aiman
Member
Posts: 1208
Joined: Mon Jul 30, 2012 05:47

Re: Post your modding questions here

by 4aiman » Post

A mesh node is a node with the "mesh" drawtype and a "mesh" field in definition filled with the name of the model file (*.obj is good enough).
No animations are supported for nodes as of yet.

User avatar
ExeterDad
Member
Posts: 1717
Joined: Sun Jun 01, 2014 20:00
In-game: ExeterDad
Location: New Hampshire U.S.A

Re: Post your modding questions here

by ExeterDad » Post

4aiman defined it well, but in laymen terms. Meshnode allow you to bring new shapes into Minetest that are not block-like. For example, a meshnode may be a sphere. A bunny or just about anything. These items as 4aiman stated can not move around. They are stationary as a regular block or decoration.

User avatar
Kalabasa
Member
Posts: 37
Joined: Tue Jan 06, 2015 17:36
GitHub: Kalabasa
IRC: Kalabasa
In-game: Kalabasa

Re: Post your modding questions here

by Kalabasa » Post

Is it possible to use an animated texture for a mesh entity?
insert signature here

4aiman
Member
Posts: 1208
Joined: Mon Jul 30, 2012 05:47

Re: Post your modding questions here

by 4aiman » Post

AFAIK, no (But that was suggested for Freeminer somewhere around 6 months ago).

For that one may use an entity. However, entities are not quite good for building and (what's more inconvenient) they don't provide a good collision mechanism.

Look at the chests in magichet or BFG - those are a_node+an_entity things - easy to dig & build and can be animated.
As one may notice, that all comes at a cost of higher CPU and network load...

User avatar
Merlin
Member
Posts: 63
Joined: Tue Dec 09, 2014 22:07
GitHub: sct-0
In-game: my
Location: germany

Re: Post your modding questions here

by Merlin » Post

How would one go about using a mesh for the character and mobs?

4aiman
Member
Posts: 1208
Joined: Mon Jul 30, 2012 05:47

Re: Post your modding questions here

by 4aiman » Post

First, you'll need to have a model in *.x or *.b3d format.
Note, that scaling a *.b3d is a bit different from scaling an *.x (see below).
Also, note that besides a model and the stuff described here, you'll need to write some AI which would control a mob.

Now, let's get down to business:

1. You HAVE to follow names conventions, e.g. you can't register any entity with a name that doesn't correspond to the name of your mod-to-be.
In this case, I have a mod called "adbs" (ADvanced moBS).

So, in general, registration works like this:

Code: Select all

adbs.register_mob("adbs:zombie", {DEFINITION OF YOUR MOB})
^ I've registered a mob with the name "zombie" within my "adbs" mod. While "zombie" may be substituted with almost whatever alphanumeric character (plus underscores), the "adbs" part can't.

2. The "DEFINITION OF YOUR MOB" may contain as many fields as you'd like it to contain. But, since you need a model, the smallest variant would look smth like the following:

Code: Select all

adbs.register_mob("adbs:zombie", {
    textures = {"adbs_zombie.png", "3d_armor_trans.png", "3d_armor_trans.png"},
    visual = "mesh",
    mesh = "adbs_skeleton.x",
    visual_size = {x=1,y=1,z=1},
    animation = {
        speed_normal    = 30,
        speed_run       = 40,
        stand_start     =  0,
        stand_end       = 79,
        walk_start      = 168,
        walk_end        = 187,
        run_start       = 230,
        run_end         = 245,
        punch_start     = 230,
        punch_end       = 230,
        jump_start      = 235,
        jump_end        = 235,
        mine_start      = 189,
        mine_end        = 198,
        walk_mine_start = 200,
        walk_mine_end   = 219,
        sit_start       =  81,
        sit_end         = 160,
    },
})
So, you'll need to:
- supply textures you would like to use for your model (you may change the default ones - those supplied with the model you're using);
- set "visual" property to "mesh";
- set "mesh " property to a string that has a name of your model ("adbs_skeleton.x" in this case);
- fill the "animation" property (you may call this one whatever you like - "animations" or "mob_anim" etc);
You may also be in a need to change the "visual_size" of a model if your one is too big or to small.

Note, that sub-fields in the "animation" property can be named whatever you'd like to as well.
The only thing you should be concerned is the right numbers of the starting and the ending frame of some animation. The names above were chosen to denote which action an entity performs. I mean, it would be easier to remember to use "run_start" and "run_end" should I want to make a mob look like it's running than trying to remember fields like "rs" and "re" (in the case I'd decided to abbreviate the names of fields).

3. Now, all what "register mob" does is setting a metatable for a mob definition and registering an entity:

Code: Select all

function adbs.register_mob(name, def)
    setmetatable (def,adbs.ad)
    minetest.register_entity(name, def)
end
The behaviour of the "register _entity" is described in lua_api.txt. Basically, it notifies the engine of your entity (a mob in our case). W/o calling this "register _entity" you won't be able to spawn your entities.

The "setmetatable" one, however is a part of Lua and one should read some lua manual to fully understand it. But in our case all you need to know is that setting a metatable is like setting a prototype for a mob.

You can define a table with all methods and properties you want to and then use that table as a base class for any mob.
Let's say you have defined a table which describes a cubic mob. You've implemented everything you want from it - it jumps, swims, follows the player but doesn't attack him. Kinda passive, right?
Then you just may have an idea of a similar mob but with some other model.

Should you describe his behavior once again?
Well, you CAN, but you should NOT really.

Instead use that passive mob table as a prototype for a new one by calling the "setmetatable".

In my case I have set an "adbs.ad" table as the prototype for the definition of my mob, stored in "def".
That means, that EVERY time MineTest won't find some field in my mob's definition It WILL search for it in the "adbs.ad" table and use it's methods and fields in case there are some.

So, for moving and following you may use adbs.ad methods, but to change the mob's model you should change the "mesh" property (and probably change the "contents" of the "animation" property).
Thus, instead of writing a new AI you'll use the same behaviour pattern and focus on making/searching for a new model!

4. I can't really post and explain the whole adbs.ad table, but you should know following: every entity has some special methods, just like nodes do.
For nodes there are "on_place", "after_dig" etc.
For entities there are "on_step", "on_activate", "on_punch" etc.
Those methods are described in the lua_api.txt.

Like I've said, the reason for having a prototype is to describe some general behaviour of ANY mob and then change it if you want in the definition of some particular mob.

You've asked about animations, so I'll describe that.

First, note that any entity prototype has the "self" property.
It helps to get and set values of the entity from within it's own functions.
If you dye you hair red, the code in Lua may be smth like:

Code: Select all

adbs.dd = {
dye_hair = function(color)
   self.hair_color = color
end,
}
Now, if you call

Code: Select all

self.dye_hair('red')
it would be the same as directly setting the "hair_color" property to "red".

The benefit of using a method, however, is that you can somehow manipulate the "color" value within a method prior to setting the actual color (or refuse to set it at all). For example, you may set color to "orange" instead "red" if your hair wasn't white, but "yellow".

The reason I've described prototyping and the "self" is that the only way to switch entity's animations is to call "set_animation" method of the object that was created when you've spawned an entity or a mob.

You see, every entity has a field "object" which controls the actual object in the Minetest world. Players are objects too.
So, every entity is also an object, but not every object is an entity (an object may well turned out to be a player).

Below you can see the call of "set_animation":

Code: Select all

self.object:set_animation({x=self.animation.stand_start,y=self.animation.stand_end},30, 0)
The code above does the following:
- looks for "anination" property inside your definition of an entity;
- tries to get sub-fields "stand_start" and "stand_end" from the "animation" field;
- makes a table {x,y} and make "x" be equal to the "animation.stand_start" and "y" to the "animation.stand_end";
- sets the second parameter to 30 which is the speed with which the animation is to be played.
(Remember me telling you may call the "animation" property whatever you'd like to?)

Now, if there were no errors and you have your "animation" (or whatever else named) property with properly set "stand_start" and "stand_end" sub-fields and the actual model file has the frames from "stand_start" to "stand_end" you'll successfully change your mob animation to an idle one.

But how should your mob react and change it's state and animations?

There's "on_step" property for this.
It's called every global_step (smth like 0.1 sec with mobs around).

But the animation have some duration too!
It can't be played within 0.1 second and you don't want it to be played so fast either.

Luckily, once set, the animation won't be stopped until you'd call yet another set_animation.
That means, you should check for any change of a state of your mob and switch animations only when it's necessary to do so.

But that's not all!
You don't want your currently set animation to be re-set to the first frame too.
So, you should always check whether you already has switched to some animation before switching to it.
For example, if you've set animation to "run" you don't need to do that again until your mob will stop and then will start to run again.

There are multiple ways to achieve full control over entities, but for that you should analyze some mods which add mobs. I assume an old copy of simple_mobs (currently knows as the "mobs" by PilzAdam will be enough.
I suggest an old copy, because it is "simpler" than the latest ones to understand the basics.

___________________

As for players, if you don't want to change the set of available animations, the only thing you'll need is to get a different model.

Regardless of whether you want to add animations or not, you should register your model within minetest:

Code: Select all

default.player_register_model("3d_armor_character.x", {
    animation_speed = 30,
    textures = {
        armor.default_skin,
        "3d_armor_trans.png",
        "3d_armor_trans.png",
    },
    animations = {
        stand = {x=0, y=79},
        lay = {x=162, y=166},
        walk = {x=168, y=187},
        mine = {x=189, y=198},
        walk_mine = {x=200, y=219},
        sit = {x=81, y=160},
    },
})
^ That's a part of the "3d_armour" mod. It registers a new model. Note the sub-fields in the "animation" property - all of those should exist. The numbers may differ, though. As with the entities, those numbers show the first and the last frame of animation used when player perform different actions.

You may want to have your own "register_model" function, but you don't need it really. Just go and toy with the default one and you'll agree with me.





Feel free to ask more if my explanation would seem too blurry and uncertain ;)

User avatar
ExeterDad
Member
Posts: 1717
Joined: Sun Jun 01, 2014 20:00
In-game: ExeterDad
Location: New Hampshire U.S.A

Re: Post your modding questions here

by ExeterDad » Post

@4aiman Wow! Now that's a nice reply.

User avatar
Don
Member
Posts: 1643
Joined: Sat May 17, 2014 18:40
GitHub: DonBatman
IRC: Batman
In-game: Batman

Re: Post your modding questions here

by Don » Post

I hope that reply is going in the wiki if it isn't there already.
Many of my mods are now a part of Minetest-mods. A place where you know they are maintained!

A list of my mods can be found here

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

Re: Post your modding questions here

by stu » Post

Could someone please explain to me the purpose of the [mask texture modifier, preferably with a quick use-case example.
I would also like to know the version number when [colorize was added, ie was it before or after the release of 0.4.11?

User avatar
Hybrid Dog
Member
Posts: 2774
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Post your modding questions here

by Hybrid Dog » Post

stu wrote:I would also like to know the version number when [colorize was added, ie was it before or after the release of 0.4.11?
https://github.com/minetest/minetest/co ... c/tile.cpp
ctrl+f can help you (if you use firefox)

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

Locked

Who is online

Users browsing this forum: No registered users and 2 guests