Page 1 of 3

LUA code questions

PostPosted: Fri Oct 12, 2012 13:35
by Comp52
This thread is for asking anything you need to ask about writing the code for a mod in Lua. Feel free to post your questions and answer other people's questions.

Here are my questions:

1:what is "full_punch_interval" and what does it do?
2:what is "max_drop_level" and what does it do?
3:what do "uses" and "max level" do?
4:there is no question number four, but everyone asks 3 questions so I wanted a fourth. :)

PostPosted: Fri Oct 12, 2012 14:00
by PilzAdam
Comp52 wrote:1:what is "full_punch_interval" and what does it do?

When you hit a object the item has a "cooldown" time. After 1/2 of the "cooldown" it do 1/2 damage (1/3 time = 1/3 damage...). full_punch_interval is the "cooldown" or "reload" time. After this time the tool does max damage.
Comp52 wrote:2:what is "max_drop_level" and what does it do?

It has no effect in the engine but other mods can use it to check what the digged node should drop.
Comp52 wrote:3:what do "uses" and "max level" do?

Uses is the number of nodes the tool can dig in this group.
Every node can define a level in the groups field. If the level is equal to max_level in tooldef then the digging times and uses are equal to the params in the groupcaps field.
If the level of the node is above max_level the tool cant dig the node.
If the level is below max_level the tool is faster and has more uses.
Read this for more information about that: https://github.com/celeron55/minetest/blob/master/doc/lua_api.txt#L549
Comp52 wrote:4:there is no question number four, but everyone asks 3 questions so I wanted a fourth. :)

42

PostPosted: Fri Oct 12, 2012 14:56
by Comp52
That definitely helps a lot; thanks, PilzAdam!

Another question; is there a way to find out the level of a node(like the level of dirt, tree, stone, etc)? is there a list of that somewhere?

PostPosted: Fri Oct 12, 2012 15:14
by PilzAdam
Comp52 wrote:That definitely helps a lot; thanks, PilzAdam!

Another question; is there a way to find out the level of a node(like the level of dirt, tree, stone, etc)? is there a list of that somewhere?

You can get the definition table of a node via minetest.registered_nodes[nodename].
Example:
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
minetest.registered_nodes["default:dirt"].groups.level

Better way to get it:
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
minetest.get_item_group("default:dirt", "level")

PostPosted: Fri Oct 12, 2012 17:04
by Comp52
um, that's not really what I meant. What I meant was, is there some sort of "cheat sheet" that lists all the info on the different nodes?

PostPosted: Sat Oct 13, 2012 01:09
by cornernote
Comp52, the Minetest guide (aka GameWiki) does that:
http://guide.minetest.net/minetest/items.php

PostPosted: Sat Oct 13, 2012 12:27
by Comp52
thanks, this helps some. Unfortunately, it doesn't list all the info(e.g. doesn't list whether most of the items are cracky, crumbly or snappy, which is what I'm looking for). Thanks for the help, tho.

PostPosted: Sat Oct 13, 2012 12:44
by PilzAdam

PostPosted: Mon Sep 09, 2013 07:08
by wcwyes
how do i get a tool to place a node then disappear?

PostPosted: Mon Sep 09, 2013 07:28
by wcwyes
I'm thinking something along the lines of
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
on_use = minetest.env:set_node(special:myblock})
            end
self.object:remove()
                        end

PostPosted: Mon Sep 09, 2013 23:54
by Mossmanikin
wcwyes wrote:how do i get a tool to place a node then disappear?


I'd do it like this:
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
on_place = function(itemstack, placer, pointed_thing)
    local pt = pointed_thing
    minetest.set_node({x=pt.under.x, y=pt.under.y+1, z=pt.under.z}, {name="special:myblock"})
    itemstack:take_item()
    return itemstack
end,

PostPosted: Mon Sep 09, 2013 23:58
by Chinchow
PilzAdam wrote:42


That's no answer!
But then again he didn't know what his question was.

PostPosted: Tue Sep 10, 2013 00:42
by philipbenr
PilzAdam wrote:
Comp52 wrote:4:there is no question number four, but everyone asks 3 questions so I wanted a fourth. :)

42


hahahahahahaha lol :) love it and the book it came from.

PostPosted: Tue Sep 10, 2013 15:14
by wcwyes
Mossmanikin wrote:
wcwyes wrote:how do i get a tool to place a node then disappear?


I'd do it like this:
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
on_place = function(itemstack, placer, pointed_thing)
    local pt = pointed_thing
    minetest.set_node({x=pt.under.x, y=pt.under.y+1, z=pt.under.z}, {name="special:myblock"})
    itemstack:take_item()
    return itemstack
end,

thanks

PostPosted: Tue Sep 10, 2013 15:41
by wcwyes
is there a way I can hide my node from the recipe guide in unified inventory?

PostPosted: Tue Sep 10, 2013 15:43
by jojoa1997
How would I make one item be replace with another item via commands.

PostPosted: Tue Sep 10, 2013 19:33
by LionsDen
wcwyes wrote:is there a way I can hide my node from the recipe guide in unified inventory?


Yes, just add not_in_creative_inventory=1 to the groups part of your node definition.

PostPosted: Tue Sep 10, 2013 22:11
by wcwyes
is there a way to convey(or apply) my nodes facedir function to the tool?

PostPosted: Wed Sep 11, 2013 02:43
by LionsDen
When the tool is used, I think that below will work. If not exactly then something close. I haven't tested this code but I did adapt it from some code that I wrote that did something a little different. Because I haven't tested it, you might want to.
This goes into the node definition 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
     on_use = function(itemstack, user, pointed_thing)
          --   pointed_thing.under is the object itself, can be nil.
          --   pointed_thing.above is the object above the pointed thing, can be nil.
          --   pointed_thing.type is nil if nothing is there, node if it is a node and
          --        object if it is an object.
          if pointed_thing.under then
               local dir = pointed_thing.under.param2
               --   Whatever you want to happen here.
          end
     end,

PostPosted: Wed Sep 11, 2013 15:23
by wcwyes
not exactly sure of the argument that facedir is doing in paramtype2 to be able to fill in the blanks
sorry I'm kind of new at lua
LionsDen wrote:When the tool is used, I think that below will work. If not exactly then something close. I haven't tested this code but I did adapt it from some code that I wrote that did something a little different. Because I haven't tested it, you might want to.
This goes into the node definition 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
     on_use = function(itemstack, user, pointed_thing)
          --   pointed_thing.under is the object itself, can be nil.
          --   pointed_thing.above is the object above the pointed thing, can be nil.
          --   pointed_thing.type is nil if nothing is there, node if it is a node and
          --        object if it is an object.
          if pointed_thing.under then
               local dir = pointed_thing.under.param2
               --   Whatever you want to happen here.
          end
     end,

PostPosted: Wed Sep 11, 2013 16:06
by LionsDen
wcwyes wrote:not exactly sure of the argument that facedir is doing in paramtype2 to be able to fill in the blanks
sorry I'm kind of new at lua


The param2 is the node's facedir. So whatever you want to do with it is what you must do. Since I have no idea what you meant by applying it to the tool I can't really help any further than that.

PostPosted: Wed Sep 11, 2013 22:18
by wcwyes
in my earlier posts I've been working on a tool/node an object that is is a tool and a node at the same time. I place the tool it turns into a node. I mine the node and it drops the tool. I tried applying param2=facedir to the tool so when I use onplace it faces me but that didn't work.
LionsDen wrote:
wcwyes wrote:not exactly sure of the argument that facedir is doing in paramtype2 to be able to fill in the blanks
sorry I'm kind of new at lua


The param2 is the node's facedir. So whatever you want to do with it is what you must do. Since I have no idea what you meant by applying it to the tool I can't really help any further than that.

PostPosted: Wed Sep 11, 2013 22:52
by LionsDen
Did you make sure that you used a node type that uses the param2 as a facedir? If you look at the docs, it shouldn't be too hard to figure out what ones you can use.

PostPosted: Wed Sep 11, 2013 23:08
by wcwyes
Yes my node does use facedir and it works on the node, I just need it to work when the tool places the node
I'm sure I could figure it out if I looked at the screwdriver mod but when I downloaded it and installed it I got an eof error.
I would rather be looking at working files.
....docs???
LionsDen wrote:Did you make sure that you used a node type that uses the param2 as a facedir? If you look at the docs, it shouldn't be too hard to figure out what ones you can use.

PostPosted: Thu Sep 12, 2013 01:53
by LionsDen
wcwyes wrote:Yes my node does use facedir and it works on the node, I just need it to work when the tool places the node
I'm sure I could figure it out if I looked at the screwdriver mod but when I downloaded it and installed it I got an eof error.
I would rather be looking at working files.
....docs???


Here are a few webpages that can help you with modding minetest.


https://github.com/celeron55/minetest/blob/master/doc/lua_api.txt

http://dev.minetest.net/Main_Page

http://sfan5.duckdns.org/minetest-modding-tutorial/html/englishEN.html


There are many more from not very useful to little tidbits of information.

Also, the screwdriver is now a part of the minetest_game. Just go into the games directory and then the minetest_games directory then the mods directory and finally the screwdriver directory. There is the init.lua for the screwdriver. Technic has a screwdriver as well but it is a sonic screwdriver. Hope these help you out with your modding.

PostPosted: Thu Sep 12, 2013 11:48
by PilzAdam

PostPosted: Fri Sep 13, 2013 11:56
by wcwyes

this was quite useful in where I'm trying to go with this mod but doesn't seem to help with the specific question I asked.

PostPosted: Fri Sep 13, 2013 16:35
by LionsDen
wcwyes wrote:this was quite useful in where I'm trying to go with this mod but doesn't seem to help with the specific question I asked.


Did you see where I mentioned that the screwdriver mod was a part of the minetest_game now. And also the part where I mentioned that Technic has a Sonic Screwdriver in it. Since I don't know where you want to go with this mod that is all the help I can give because you mentioned that you wanted to look at the code for the screwdriver.

PostPosted: Sun Sep 15, 2013 10:46
by wcwyes
LionsDen wrote:
wcwyes wrote:this was quite useful in where I'm trying to go with this mod but doesn't seem to help with the specific question I asked.


Did you see where I mentioned that the screwdriver mod was a part of the minetest_game now. And also the part where I mentioned that Technic has a Sonic Screwdriver in it. Since I don't know where you want to go with this mod that is all the help I can give because you mentioned that you wanted to look at the code for the screwdriver.

I've been looking at the screwdriver for it's rotating function ability I want to emulate it with different functions. It's a little harder than expected but I'm slowly progressing.

PostPosted: Sun Sep 15, 2013 18:28
by LionsDen
wcwyes wrote:
LionsDen wrote:
wcwyes wrote:this was quite useful in where I'm trying to go with this mod but doesn't seem to help with the specific question I asked.


Did you see where I mentioned that the screwdriver mod was a part of the minetest_game now. And also the part where I mentioned that Technic has a Sonic Screwdriver in it. Since I don't know where you want to go with this mod that is all the help I can give because you mentioned that you wanted to look at the code for the screwdriver.

I've been looking at the screwdriver for it's rotating function ability I want to emulate it with different functions. It's a little harder than expected but I'm slowly progressing.


Well good luck to you. The indev version can use the old way of facedir but has a newer way as well. If you add ,true after the argument in facedir it will return the new style values. You should be able to find mention of this elsewhere using google.