Page 161 of 169

Re: Post your modding questions here

Posted: Sat Aug 05, 2017 08:10
by ABJ
How do I modify node properties while the node is in game?

Re: Post your modding questions here

Posted: Sat Aug 05, 2017 08:36
by ABJ
How do I get the time of day?

Re: Post your modding questions here

Posted: Sat Aug 05, 2017 10:03
by cx384
ABJ wrote:How do I modify node properties while the node is in game?
Not at all, but you can use ABMs, node callbacks, node timer, ... to change the meta (infotext, inventor,y ...), rotation, color palette, ... or replace the node with another node.
ABJ wrote:How do I get the time of day?
With minetest.get_timeofday().
https://github.com/minetest/minetest/bl ... .txt#L2458

Re: Post your modding questions here

Posted: Sat Aug 05, 2017 11:13
by ABJ
How do I change this colorpalette?

Re: Post your modding questions here

Posted: Sat Aug 05, 2017 11:21
by ABJ
How do I set the light level of a node?

Re: Post your modding questions here

Posted: Sat Aug 05, 2017 16:05
by cx384
ABJ, you can find the answers of this questions there. https://github.com/minetest/minetest/bl ... ua_api.txt

Re: Post your modding questions here

Posted: Sat Aug 05, 2017 17:21
by ABJ
Ooops! I meant position!

Re: Post your modding questions here

Posted: Sun Aug 06, 2017 23:52
by Nyarg
cx384 wrote: ... to change the meta (infotext, inventor,y ...), rotation, color palette, ...

oops "Myyy Precious"
What is MT version had implement palette ? It seems very profitable )

Re: Post your modding questions here

Posted: Mon Aug 07, 2017 09:17
by cx384
Nyarg wrote:What is MT version had implement palette ? It seems very profitable )
I think Minetest 0.4.16
The commit: https://github.com/minetest/minetest/co ... b81358a54e

Re: Post your modding questions here

Posted: Mon Aug 07, 2017 17:27
by sofar
ABJ wrote:Ooops! I meant position!
Nodes can't move.

A 'node' in minetest is defined by the following properties:

1) the position (immutable - you cannot change this)
2) the content type (a reference to what type of block this is)
3) param1/param2 values

and, secondary, there are, or may be one or more of the following `attached` to the node:

a) light levels (obtainable and changeable in limited ways on the server)
b) metadata
c) nodetimer
d) biome parameters and mapgen stuff (only obtainable or modifyable during mapgen)
e) other unspecified private node properties I forgot here.

As a consequence, if you wish to `move` a node from position A to B, you have to `change A to air` and `change B to the original block type`.

Re: Post your modding questions here

Posted: Mon Aug 07, 2017 20:33
by Lord_Vlad
What about a mod that makes the light level of (certain/all) light sources vary over time, randomly ?

Torches and fire aren't always perfectly the same brightness even if they stay lit, right ?

Re: Post your modding questions here

Posted: Mon Aug 07, 2017 20:50
by sofar
Lord_Vlad wrote:What about a mod that makes the light level of (certain/all) light sources vary over time, randomly ?

Torches and fire aren't always perfectly the same brightness even if they stay lit, right ?
Since you can not modify the light level in a node, you need to create multiple nodes that look the same and have different light levels, and then swap them.

Re: Post your modding questions here

Posted: Tue Aug 08, 2017 02:47
by christoferlevich
Lord_Vlad wrote:What about a mod that makes the light level of (certain/all) light sources vary over time, randomly ?

Torches and fire aren't always perfectly the same brightness even if they stay lit, right ?
There's a mod called morefire u might like. The torches do burn out. I don't think the light varies tho.

Re: Post your modding questions here

Posted: Tue Aug 08, 2017 11:32
by Linuxdirk
When having a node with paramtype2 = 'facedir' ... how can I properly determine left/right/front/back according to the node's orientation when placed?

Re: Post your modding questions here

Posted: Tue Aug 08, 2017 16:19
by BirgitLachner
I have a questions concerning a mod, that TalkLounge released on his homepage.

It offers an automatic spawner that drops items. Everthing is hardcoded, but as it is not used so often, this is okay.
Here I have my adopted code to spawn diamonds:

Code: Select all

minetest.register_node("spawn_item:diamantspawnerunten"--[[Das ist der Node, den man setzen muss]], {
description = "Spawn Diamant",
tiles = {"spawn_item_normal.png"},
sounds = default.node_sound_stone_defaults(),
light_source = 14})

minetest.register_node("spawn_item:diamantspawneroben"--[[Das ist ein Node, der nur für die Ausführung der Fuktion wichtig ist]], {
description = "Hilfsnode zum spawnen von Diamant",
light_source = 14,
tiles = {"spawn_item_normal.png"},
walkable = false,
pointable = false,
drawtype = "glasslike"})

minetest.register_abm({--[[Diese Funktion lässt den die obere Spawner-Node zwei Nodes über dem normal Node spawnen]]
nodenames = {"spawn_item:diamantspawnerunten"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
minetest.set_node({x = pos.x, y = pos.y +3, z = pos.z}, {name = "spawn_item:diamantspawneroben"})
end})

minetest.register_abm({--[[Diese Funktion lässt ein Item auf dem normal Node alle paar Sekunden spawnen. Es ist nicht möglich, direkt vom normal Node mehrere Items spawnen zu lassen]]
nodenames = {"spawn_item:diamantspawneroben"},
interval = 5--[[Diese Zahl gibt an, alle wie viele Sekunden ein Item spawnen soll]],
chance = 1--[[Diese Zahl gibt an, mit welcher Warscheinlichkeit ein Item spawnen soll]],
action = function(pos, node, active_object_count, active_object_count_wider)
if minetest.add_item({x = pos.x, y = pos.y - 1, z = pos.z}, "default:diamond"--[[Dieser Name gibt das Item an, das spawnen soll]])
then minetest.dig_node({x = pos.x, y = pos.y, z = pos.z})--[[Nachdem das Item gespawnt ist, wird der normal1 Node wieder entfernt und muss erneut vom normal Node erzeugt werden. Dieser Vorgang muss passieren, damit wenn man den normal Node abbaut, nicht weiter Items spawnen. Der Vorgang kann allerdings auch entfernt werden, dann muss man allerdings den normal1 Node per Worldedit entfernen. Wenn dieser Vorgang entfernt wird, dann führt es auch zu weniger Lags]]
end
end})
I don't know if there is a better possibility to do that, but it works ;-)

I want to hide the lower node that is build to drop items called "spawn_item:diamantspawnerunten" by, lets say, a block of dirt that I put on it, but surprisingly, the diamond falls down through the dirt and lands on the "spawn_item:diamantspawnerunten".
I want to understand, why this happens.

EDIT:
If I change the line
minetest.set_node({x = pos.x, y = pos.y +3, z = pos.z}, {name = "spawn_item:diamantspawneroben"})
to
minetest.set_node({x = pos.x, y = pos.y +5, z = pos.z}, {name = "spawn_item:diamantspawneroben"})
it works more or less. But water, that is flowing over ths dirt block, causes that the item goes through the water and dirt block under the water, too.

EDIT 2:
Well, what I said before is not always the same ... strange. Sometime gies through, sometimes not.

Re: Post your modding questions here

Posted: Tue Aug 08, 2017 17:10
by sofar
Linuxdirk wrote:When having a node with paramtype2 = 'facedir' ... how can I properly determine left/right/front/back according to the node's orientation when placed?
There are a few helper functions `dir_to_facedir` etc documented in lua_api.txt. For code examples, you probably want to look at things like minetest_game beds and doors, since they've got code handling orientation on placement and rotation. Screwdriver mod may also help to provide insights.

facedir is a bit funny in a way, since '0' means north (and not cartesian where it would be east) and if you place a furnace facing north, then the "front" of the furnace faces south, so effectively the "back" side of the furnace is where you put the fuel in. Highly confusing :)

Re: Post your modding questions here

Posted: Tue Aug 08, 2017 18:54
by Linuxdirk
Great :D I’ll check this out. Thanks.

Re: Post your modding questions here

Posted: Tue Aug 08, 2017 19:44
by BirgitLachner
Another question to the Spawn-Item-Mod ...

I want the items not to spawn in the same intervall but randomly ...

Code: Select all

minetest.register_abm({--[[Diese Funktion lässt ein Item auf dem normal Node alle paar Sekunden spawnen. Es ist nicht möglich, direkt vom normal Node mehrere Items spawnen zu lassen]]
nodenames = {"spawn_item:diamantspawneroben"},
interval = PseudoRandom(os.time()) --[[Diese Zahl gibt an, alle wie viele Sekunden ein Item spawnen soll]],
chance = 1--[[Diese Zahl gibt an, mit welcher Warscheinlichkeit ein Item spawnen soll]],
action = function(pos, node, active_object_count, active_object_count_wider)
if minetest.add_item({x = pos.x, y = pos.y - 1, z = pos.z}, "default:diamond"--[[Dieser Name gibt das Item an, das spawnen soll]])
then minetest.dig_node({x = pos.x, y = pos.y, z = pos.z})--[[Nachdem das Item gespawnt ist, wird der normal1 Node wieder entfernt und muss erneut vom normal Node erzeugt werden. Dieser Vorgang muss passieren, damit wenn man den normal Node abbaut, nicht weiter Items spawnen. Der Vorgang kann allerdings auch entfernt werden, dann muss man allerdings den normal1 Node per Worldedit entfernen. Wenn dieser Vorgang entfernt wird, dann führt es auch zu weniger Lags]]
end
end})
I searched around the Web how to use lua to get a random number ... it is not important if it is a number between 1 and 10 o a float(?) number between 0 and 1 ... I can handle both.

I found out that I need to start/initialisize the random generator. But even if I try it, I always get the same intervall.
math.randomseed(x)
is to start the generator and
math.random([m[,n]])
to get the number.

So can you help me please, who I need to change the code, to get random intervalls.

Re: Post your modding questions here

Posted: Tue Aug 08, 2017 20:10
by Lord_Vlad
christoferlevich wrote:
Lord_Vlad wrote:What about a mod that makes the light level of (certain/all) light sources vary over time, randomly ?

Torches and fire aren't always perfectly the same brightness even if they stay lit, right ?
There's a mod called morefire u might like. The torches do burn out. I don't think the light varies tho.
Not quite like what I was thinking about, besides, I know about that mod, there's even another one called "real torches" that make torches go out.

I don't want them to go out, I want them to vary in intensity.

It could be made to have a more "moving" fire, as well as, for example, horror-movie lightbulbs in abandonned buildings.

I can't mod yet, but I'll keep the idea to make it myself if it's never done by anyone else.

Re: Post your modding questions here

Posted: Tue Aug 08, 2017 21:32
by christoferlevich
It would seem plausible that it should be possible to make a random number generate but I'm still wrapping my head over basic things. Someday... Lol

Re: Post your modding questions here

Posted: Wed Aug 09, 2017 01:12
by zing269
BirgitLachner wrote:Another question to the Spawn-Item-Mod ...

I want the items not to spawn in the same intervall but randomly ...
It doesn't appear to be possible to change an abm once it's registered so I don't think you can change the interval. As an alternative, you could wrap the add_item if block with a check to see if a random number falls within a range. It's not an interval but you can tweak the comparison value get a close approximation.

Code: Select all

minetest.register_abm({--[[Diese Funktion lässt ein Item auf dem normal Node alle paar Sekunden spawnen. Es ist nicht möglich, direkt vom normal Node mehrere Items spawnen zu lassen]]
nodenames = {"spawn_item:diamantspawneroben"},

interval = 1 -- control the spawn rate using a random value in the function

chance = 1--[[Diese Zahl gibt an, mit welcher Warscheinlichkeit ein Item spawnen soll]],
action = function(pos, node, active_object_count, active_object_count_wider)

--Something like this
if math.random(0,1) > 0.4 then
if minetest.add_item({x = pos.x, y = pos.y - 1, z = pos.z}, "default:diamond"--[[Dieser Name gibt das Item an, das spawnen soll]])
then minetest.dig_node({x = pos.x, y = pos.y, z = pos.z})--[[Nachdem das Item gespawnt ist, wird der normal1 Node wieder entfernt und muss erneut vom normal Node erzeugt werden. Dieser Vorgang muss passieren, damit wenn man den normal Node abbaut, nicht weiter Items spawnen. Der Vorgang kann allerdings auch entfernt werden, dann muss man allerdings den normal1 Node per Worldedit entfernen. Wenn dieser Vorgang entfernt wird, dann führt es auch zu weniger Lags]]
end
end

end})
You can adjust the comparison value to suit.

Re: Post your modding questions here

Posted: Wed Aug 09, 2017 04:36
by hajo
christoferlevich wrote:it should be possible to make a random number generator
Go to https://www.lua.org/cgi-bin/demo and try this program:

Code: Select all

r=math.random()
print(r)

math.randomseed(6)
for i=1,7 do
  print( math.random(1,6) )
end
See also http://www.lua.org/manual/5.3/manual.ht ... ath.random

Re: Post your modding questions here

Posted: Wed Aug 09, 2017 05:37
by BirgitLachner
zing269 wrote:
It doesn't appear to be possible to change an abm once it's registered so I don't think you can change the interval.
Okay, if that is true I can't do it with random intervals. But while reading your comment, I realized that I can use the chance value to have a variable spawning. May be that's enough.

@hajo I tried all thoose things.

Re: Post your modding questions here

Posted: Thu Aug 10, 2017 16:08
by orwell
mezantrop wrote:topic: set_attach usage help.
reason: I want to attach and move two nodes together.
more info: Sorry for a dumb question, I'm newbie to minetest game as well as minetest development. Now trying to create two entities and make the second to repeat all moves of the first one. Have stuck at the early beginning with attaching the second entity to the first:

Code: Select all

    second = minetest.add_entity(pos_behind_first, "my_mod:second")
    second:set_attach(self.object, "", {x=0,y=0,z=0}, {x=0,y=0,z=0})
Couldn't someone explain me how to use it properly, as obviously, I'm doing it wrong.
P.S. what is the "bone" - the second argument of set_attach?

Thank you in advance.
1. set_attach means "attach this object (the object that the function is called on) to the specified one".
2. the attachment status is lost on unloading
So what you need to do is:
1. the first object needs to hold all relevant data
2. in the on_activate function of the first object, create the second object, give it a reference to the first object for data storage (if you need this) and call set_attach on the second object and give the first object as argument
3. "bone" just needs to be an empty string
4. the attachment position is the place where the second object is positioned relative to the first

Code: Select all

first's on_activate()
  local second=add_entity(...)
  local secondle=second:get_luaentity()
  secondle.first_reference=self
  second:set_attach(self.object, ...)
5. The second object needs to be non-persistant, it needs to delete itself when it gets unloaded. Else, you would have the world cluttered with "second" objects. Track the development status of this: https://github.com/minetest/minetest/pull/5112. Meanwhile, you need to use a hack:

Code: Select all

second's get_staticdata()
  return "blah"
end
second's on_activate(staticdata)
  if staticdata=="blah" then
    self.object:remove()
    return
  end
end
(Explanation:when the object gets created, it's staticdata is empty. when it was unloaded once, it has staticdata set to "blah", so it gets removed the next time it is loaded)

Re: Post your modding questions here

Posted: Thu Aug 10, 2017 16:28
by azekill_DIABLO

Code: Select all

ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'azewheel' in callback luaentity_Step(): ...ames\minetest-0.4.16-win64\bin\..\mods\azewheel/tank.lua:105: bad argument #1 to 'set_pos' (userdata expected, got table)
I have this error with that code, why? can you help me?

Code: Select all

function tank_turret.on_step(self) --tank_turret is an entity
	local turret = self.object
	local pos = {x=playerpos.x, y=playerpos.y, z=playerpos.z} --the position of player is correct
	turret.set_pos(pos) -- this line causes  the bug, but why?
end