LUA code questions

Comp52
Member
 
Posts: 56
Joined: Sun Oct 07, 2012 00:49

LUA code questions

by Comp52 » Fri Oct 12, 2012 13:35

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. :)
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Fri Oct 12, 2012 14:00

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
 

Comp52
Member
 
Posts: 56
Joined: Sun Oct 07, 2012 00:49

by Comp52 » Fri Oct 12, 2012 14:56

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?
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Fri Oct 12, 2012 15:14

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")
 

Comp52
Member
 
Posts: 56
Joined: Sun Oct 07, 2012 00:49

by Comp52 » Fri Oct 12, 2012 17:04

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?
 

cornernote
Member
 
Posts: 844
Joined: Wed Jul 11, 2012 15:02

by cornernote » Sat Oct 13, 2012 01:09

Comp52, the Minetest guide (aka GameWiki) does that:
http://guide.minetest.net/minetest/items.php
 

Comp52
Member
 
Posts: 56
Joined: Sun Oct 07, 2012 00:49

by Comp52 » Sat Oct 13, 2012 12:27

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.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Sat Oct 13, 2012 12:44

 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Mon Sep 09, 2013 07:08

how do i get a tool to place a node then disappear?
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Mon Sep 09, 2013 07:28

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
 

User avatar
Mossmanikin
Member
 
Posts: 599
Joined: Sun May 19, 2013 16:26

by Mossmanikin » Mon Sep 09, 2013 23:54

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,

Noob 4 life!
My stuff
 

User avatar
Chinchow
Member
 
Posts: 683
Joined: Tue Sep 18, 2012 21:37

by Chinchow » Mon Sep 09, 2013 23:58

PilzAdam wrote:42


That's no answer!
But then again he didn't know what his question was.
Sometimes, it's harder to think up a mod than it is to create it.
Mods: Orichalcum Stonebricks Extra Chests
 

User avatar
philipbenr
Member
 
Posts: 1665
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: WisdomFire or philipbenr

by philipbenr » Tue Sep 10, 2013 00:42

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.
"The Foot is down!"
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Tue Sep 10, 2013 15:14

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
Last edited by wcwyes on Tue Sep 10, 2013 15:23, edited 1 time in total.
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Tue Sep 10, 2013 15:41

is there a way I can hide my node from the recipe guide in unified inventory?
 

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

by jojoa1997 » Tue Sep 10, 2013 15:43

How would I make one item be replace with another item via commands.
Coding;
1X coding
3X debugging
12X tweaking to be just right
 

User avatar
LionsDen
Member
 
Posts: 525
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Tue Sep 10, 2013 19:33

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.
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Tue Sep 10, 2013 22:11

is there a way to convey(or apply) my nodes facedir function to the tool?
 

User avatar
LionsDen
Member
 
Posts: 525
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Wed Sep 11, 2013 02:43

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,
Last edited by LionsDen on Wed Sep 11, 2013 02:44, edited 1 time in total.
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Wed Sep 11, 2013 15:23

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,
 

User avatar
LionsDen
Member
 
Posts: 525
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Wed Sep 11, 2013 16:06

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.
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Wed Sep 11, 2013 22:18

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.
Last edited by wcwyes on Wed Sep 11, 2013 22:18, edited 1 time in total.
 

User avatar
LionsDen
Member
 
Posts: 525
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Wed Sep 11, 2013 22:52

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.
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Wed Sep 11, 2013 23:08

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.
Last edited by wcwyes on Wed Sep 11, 2013 23:18, edited 1 time in total.
 

User avatar
LionsDen
Member
 
Posts: 525
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Thu Sep 12, 2013 01:53

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.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Thu Sep 12, 2013 11:48

 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Fri Sep 13, 2013 11:56


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.
 

User avatar
LionsDen
Member
 
Posts: 525
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Fri Sep 13, 2013 16:35

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.
 

wcwyes
Member
 
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Sun Sep 15, 2013 10:46

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.
 

User avatar
LionsDen
Member
 
Posts: 525
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Sun Sep 15, 2013 18:28

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.
 

Next

Return to WIP Mods

Who is online

Users browsing this forum: Bing [Bot] and 10 guests

cron