Re: Post your modding questions here
Posted: Sat Aug 05, 2017 08:10
How do I modify node properties while the node is in game?
The official Minetest discussion board
https://forum.minetest.net/
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 modify node properties while the node is in game?
With minetest.get_timeofday().ABJ wrote:How do I get the time of day?
cx384 wrote: ... to change the meta (infotext, inventor,y ...), rotation, color palette, ...
I think Minetest 0.4.16Nyarg wrote:What is MT version had implement palette ? It seems very profitable )
Nodes can't move.ABJ wrote:Ooops! I meant position!
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.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.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 ?
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})
tominetest.set_node({x = pos.x, y = pos.y +3, 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.minetest.set_node({x = pos.x, y = pos.y +5, z = pos.z}, {name = "spawn_item:diamantspawneroben"})
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.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?
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})
is to start the generator andmath.randomseed(x)
to get the number.math.random([m[,n]])
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.christoferlevich wrote:There's a mod called morefire u might like. The torches do burn out. I don't think the light varies tho.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 ?
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.BirgitLachner wrote: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 = 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})
Go to https://www.lua.org/cgi-bin/demo and try this program:christoferlevich wrote:it should be possible to make a random number generator
Code: Select all
r=math.random()
print(r)
math.randomseed(6)
for i=1,7 do
print( math.random(1,6) )
end
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.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.
1. set_attach means "attach this object (the object that the function is called on) to the specified one".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:
Couldn't someone explain me how to use it properly, as obviously, I'm doing it wrong.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})
P.S. what is the "bone" - the second argument of set_attach?
Thank you in advance.
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, ...)
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
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)
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