Page 121 of 125

Re: Post your modding questions here

PostPosted: Fri Feb 24, 2017 20:30
by burli
yzelast wrote:Hey guys, i have a little question: There's a way to get how the node is rotated?

What a want to do is basically:
  • get node's rotation
  • set the pos with air
  • placa another node with the same rotation

What you want is param2. Take a look in the stairs mod.

or try swap_node()

https://github.com/minetest/minetest/bl ... .txt#L2188

And you don't need to set air first

Re: Post your modding questions here

PostPosted: Fri Feb 24, 2017 21:40
by yzelast
burli wrote:
yzelast wrote:Hey guys, i have a little question: There's a way to get how the node is rotated?

What a want to do is basically:
  • get node's rotation
  • set the pos with air
  • placa another node with the same rotation

What you want is param2. Take a look in the stairs mod.

or try swap_node()

https://github.com/minetest/minetest/bl ... .txt#L2188

And you don't need to set air first


Thanks, it'll help a lot. But the function didn't kept the rotation. I Had to get the param2 manually and set it on the table to work.

I tested with this abm:
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.register_abm {
   nodenames = {"real_trees:wide_leaves"},
   interval = 1,
   chance = 1,
   action = function(pos)
      local node = minetest.get_node(pos)
      minetest.swap_node(pos,{name = "real_trees:wide_acacia_leaves",param1 = light,param2 = node.param2})
   end,
}

Re: Post your modding questions here

PostPosted: Sat Feb 25, 2017 03:50
by hlah_
How to change how nodes are dig?

I want to create a mod that adds a strength level to each player, so a player with more strength would dig some nodes faster. I took some look on the modding reference but could not find clearly how I could do this.

Could you help me on how I can implement this, such as what function or variable I should override/change?

Re: Post your modding questions here

PostPosted: Sat Feb 25, 2017 09:44
by ABJ
EthanD57 wrote:I managed to make the player invisible but along with my other questions (see post above) I have a new one: How would I give a player "night vision", allowing them to see everything as if in daylight?

As far as I know, that is not possible at the moment.

Re: Post your modding questions here

PostPosted: Sat Feb 25, 2017 11:23
by DS-minetest
yzelast wrote:Hey guys, i have a little question: There's a way to get how the node is rotated?

What a want to do is basically:
  • get node's rotation
  • set the pos with air
  • placa another node with the same rotation

You can easily get param1 and param2 and paramtype1 and paramtype2. This should be enough.

Re: Post your modding questions here

PostPosted: Sat Feb 25, 2017 11:50
by orwell
The rotation of a node is stored in 'param2'
local node=minetest.get_node(pos)
local param2=node.param2
--set node
minetest.set_node(pos, {name="whatever", param2=param2})

Re: Post your modding questions here

PostPosted: Sat Feb 25, 2017 14:49
by burli
Is it possible to make recipes with tools which will not be consumed? For example make a dough for a cake in a mixing bowl.

Add the bowl, flor, water and maybe salt to the crafting field to get the dough, but the mixing bowl remains in the crafting field.

Is that possible?

Re: Post your modding questions here

PostPosted: Sat Feb 25, 2017 15:35
by ABJ
It's been done - with repairing tools feature.

Re: Post your modding questions here

PostPosted: Sat Feb 25, 2017 16:02
by burli
ABJ wrote:It's been done - with repairing tools feature.

???

With tool repair nothing stays in the crafting field. I can put two stone axes in the field and get one in the output

http://wiki.minetest.net/Repairing

Or is there another method?

Re: Post your modding questions here

PostPosted: Sat Feb 25, 2017 17:44
by orwell
Replacements in crafting recipe definition. Look in lua_api.txt

Re: Post your modding questions here

PostPosted: Sat Feb 25, 2017 18:46
by burli
orwell wrote:Replacements in crafting recipe definition. Look in lua_api.txt

Didn't know that, thanks

Re: Post your modding questions here

PostPosted: Sun Feb 26, 2017 21:21
by burli
Have a question about ABM times.

The mushroom spread and death ABM has an interval of 11 seconds and a chance of 50. Does that mean each mushroom will spread/die in an average time of 550 seconds?

The flowers spread ABM has an interval of 13 and a chance of 96. That would mean an average of 1248 seconds or over 20 minutes. Is that correct?

Of course it can be much faster or slower, it is just the statistical average

Re: Post your modding questions here

PostPosted: Sun Feb 26, 2017 22:37
by sofar
burli wrote:The mushroom spread and death ABM has an interval of 11 seconds and a chance of 50. Does that mean each mushroom will spread/die in an average time of 550 seconds?


no, it means that ever 11 seconds, 1 in 50 mushrooms will spread/die.

So logically, this means that after 22 seconds, there will be a small chance that the same mushroom will spread again if it didn't die, but most likely one of the other mushrooms gets picked (49 out of 50 chance).

So after 33 seconds, most likely (48/50) it's a different mushroom, and 2/50 chance it's a previous mushroom.

But since some of them may have died, the chance fluctuates

And so on. The chance is really hard to predict. This is the problem with trying to estimate binomial distributions.

Let's take a simpler example:

100 leaves. every 1 second there's a 1/2 chance the leaf decays.

after 1 second you have probably 50 leaves left
after 2 seconds you have probably 25 leaves left
after 3 seconds you have probably 13 leaves left
after 4 seconds you have probably 7 leaves left
after 5 seconds you have probably 4 leaves left
after 6 seconds you have probably 2 leaves left
after 7 seconds you have probably 1 leaves left

how many leaves do you have left after 8 seconds? Could be 0, could be 1. You don't know.

Now let's look at the average number calculation:

average = 50 * 1 + 25 * 2 + 13 * 3 + 7 * 4 + 4 * 5 + 2 * 6 + 7 + 9 / 100 (assuming the last one took 2 tries)

average = 2.15

Now, this is just pure luck that it pans out this way. If I redo the experiment 10 more times, I might get answers that wildly vary, since the chance that at the first second exactly 50 decay is common, but not that common. It's highly likely that the number varies quite a bit.

TL:DR; You can't just multiply the numbers, lots of factors account and may influence the result. Conduct experiments multiple times to get an idea how the numbers work out in reality instead.

Re: Post your modding questions here

PostPosted: Fri Mar 03, 2017 09:32
by burli
Hmm, ok, thanks sofar.

Another question: is it possible to display infotext for any node, also map generated nodes like dirt? I assume it is not possible

Re: Post your modding questions here

PostPosted: Fri Mar 03, 2017 14:24
by admicos
Is there a way to "ignore" chat messages?

For example, when a player says "i am new", i want the message to stop getting sent, and instead send my custom message, like "player is new to this server!"

I am currently using register_on_chat_message and everything i want to do is ready, except the old message still sends.

Re: Post your modding questions here

PostPosted: Fri Mar 03, 2017 14:37
by Hybrid Dog
burli, yes, you can set infotext to every node, try the pencil: https://github.com/HybridDog/technic_ex ... t.lua#L284
You can even set infotext of ignore outside the walkable map boundaries.

admicos, the lua api is not up to date. Before that bad chat prediction was removed, changing the message did not work for the player who wrote it but only for the other ones. This also disallows colouring chat messages.

Re: Post your modding questions here

PostPosted: Fri Mar 03, 2017 14:57
by burli
HybridDog sorry, that's a misunderstanding. I want to set infotext at registration. I want to have infotext at all nodes, even mapgen generated nodes.

PostPosted: Fri Mar 03, 2017 17:31
by Hybrid Dog
You can set the infotext in the on_construct function in the nodedef. on_construct is executed when the node is set with minetest.set_node (or add_node), mapgen (core or vmanip) doesn't care for such a function, it would have a severe impact on performance. So you need to set the infotext manually to each node in the mapchunk with register_on_generated.
You could also change the source code to display infotext if it's not preset in meta.

Re: Post your modding questions here

PostPosted: Fri Mar 03, 2017 19:07
by Byakuren
Infotext is in node metadata, so I would expect adding infotext to every node will greatly inflate map size and map updates sent to players. You are better off waiting for client-side modding support, which is making progress and is no longer a meme.

Re: Post your modding questions here

PostPosted: Fri Mar 03, 2017 19:19
by kaeza
admicos wrote:Is there a way to "ignore" chat messages?

For example, when a player says "i am new", i want the message to stop getting sent, and instead send my custom message, like "player is new to this server!"

I am currently using register_on_chat_message and everything i want to do is ready, except the old message still sends.

Have you tried returning `true` from your chat message handler?

lua_api.txt wrote:* `minetest.register_on_chat_message(func(name, message))`
* Called always when a player says something
* Return `true` to mark the message as handled, which means that it will not be sent to other players

Re: Post your modding questions here

PostPosted: Fri Mar 03, 2017 20:05
by Hybrid Dog
Does node metadata become compressed?

Re: Post your modding questions here

PostPosted: Fri Mar 03, 2017 20:20
by admicos
kaeza wrote:
admicos wrote:Is there a way to "ignore" chat messages?

For example, when a player says "i am new", i want the message to stop getting sent, and instead send my custom message, like "player is new to this server!"

I am currently using register_on_chat_message and everything i want to do is ready, except the old message still sends.

Have you tried returning `true` from your chat message handler?

lua_api.txt wrote:* `minetest.register_on_chat_message(func(name, message))`
* Called always when a player says something
* Return `true` to mark the message as handled, which means that it will not be sent to other players


My current code is:
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.register_on_chat_message(function(name, message)
    -- my stuff bla bla bla
    minetest.chat_send_all(myMessage)
    return true
end)


but it still shows the old message as being sent. I am currently only testing on singleplayer right now, so that might be a issue.

Re: Post your modding questions here

PostPosted: Fri Mar 03, 2017 20:37
by kaeza
Ah. If you're using stable 0.4.15, you will see your own message but other players shouldn't.

There's this commit which will be available in 0.4.16.

Re: Post your modding questions here

PostPosted: Fri Mar 03, 2017 20:57
by burli
Byakuren wrote:Infotext is in node metadata, so I would expect adding infotext to every node will greatly inflate map size and map updates sent to players. You are better off waiting for client-side modding support, which is making progress and is no longer a meme.

Ok, so infotext is not a node description like the name. It is an individual text for each single node in the map. Then I agree that it doesn't make sense

Re: Post your modding questions here

PostPosted: Sat Mar 04, 2017 04:43
by yzelast
Hey guys, today i have another small question: I'm not able to concatenate 2 strings...

The function:
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
realtrees.dry = function(pos1,pos2,chance)
local leaves = minetest.find_nodes_in_area(pos1,pos2,{"group:leaves"})
   for key,value in pairs(leaves) do
      if math.random(1,chance) == 1 then
         local node = minetest.get_node(value)
            node.name = node.name .. "_dry"
            minetest.swap_node(value,node})
      end
   end
end


Changing the name to any other itemstring works fine but the concatenation doesn't

Re: Post your modding questions here

PostPosted: Sat Mar 04, 2017 05:05
by Byakuren
yzelast wrote:Hey guys, today i have another small question: I'm not able to concatenate 2 strings...

The function:
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
realtrees.dry = function(pos1,pos2,chance)
local leaves = minetest.find_nodes_in_area(pos1,pos2,{"group:leaves"})
   for key,value in pairs(leaves) do
      if math.random(1,chance) == 1 then
         local node = minetest.get_node(value)
            node.name = node.name .. "_dry"
            minetest.swap_node(value,node})
      end
   end
end


Changing the name to any other itemstring works fine but the concatenation doesn't

What do you mean? Is there an error when you try to concatenate?

Re: Post your modding questions here

PostPosted: Sat Mar 04, 2017 06:02
by yzelast
Byakuren wrote:What do you mean? Is there an error when you try to concatenate?


(that alone bracket on swap node function didn't matter)

The following error appear on chat:
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
2017-03-04 02:00:42: ERROR[Server]: Map::setNode(): Not allowing to place CONTENT_IGNORE while trying to replace "default:leaves" at (99,28,103) (block (6,1,6))

Re: Post your modding questions here

PostPosted: Sat Mar 04, 2017 06:08
by kaeza
It means the node you are trying to place doesn't exist.

Re: Post your modding questions here

PostPosted: Sat Mar 04, 2017 06:22
by yzelast
Thinking about it, i forgot the default modname at the beginning...it's sad...well, sorry for the time wasted here, i will think more next time.

Re: Post your modding questions here

PostPosted: Sat Mar 04, 2017 06:31
by kaeza
No, that should be part of the name already.

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 node = minetest.get_node(value) --> node.name == "default:leaves"
node.name = node.name .. "_dry" --> "default:leaves_dry"

I don't think that node exists.