Post your modding questions here

ABJ
Member
Posts: 3015
Joined: Sun Jan 18, 2015 13:02
GitHub: ABJ-MV
In-game: ABJ
Location: In Earth orbit, with a perigee of 1048 km and an apogee of 1337 km and an inclination of 69 degrees.

Re: Post your modding questions here

by ABJ » Post

How do I modify node properties while the node is in game?

ABJ
Member
Posts: 3015
Joined: Sun Jan 18, 2015 13:02
GitHub: ABJ-MV
In-game: ABJ
Location: In Earth orbit, with a perigee of 1048 km and an apogee of 1337 km and an inclination of 69 degrees.

Re: Post your modding questions here

by ABJ » Post

How do I get the time of day?

User avatar
cx384
Member
Posts: 653
Joined: Wed Apr 23, 2014 09:38
GitHub: cx384
IRC: cx384

Re: Post your modding questions here

by cx384 » Post

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
Can your read this?

ABJ
Member
Posts: 3015
Joined: Sun Jan 18, 2015 13:02
GitHub: ABJ-MV
In-game: ABJ
Location: In Earth orbit, with a perigee of 1048 km and an apogee of 1337 km and an inclination of 69 degrees.

Re: Post your modding questions here

by ABJ » Post

How do I change this colorpalette?

ABJ
Member
Posts: 3015
Joined: Sun Jan 18, 2015 13:02
GitHub: ABJ-MV
In-game: ABJ
Location: In Earth orbit, with a perigee of 1048 km and an apogee of 1337 km and an inclination of 69 degrees.

Re: Post your modding questions here

by ABJ » Post

How do I set the light level of a node?

User avatar
cx384
Member
Posts: 653
Joined: Wed Apr 23, 2014 09:38
GitHub: cx384
IRC: cx384

Re: Post your modding questions here

by cx384 » Post

ABJ, you can find the answers of this questions there. https://github.com/minetest/minetest/bl ... ua_api.txt
Can your read this?

ABJ
Member
Posts: 3015
Joined: Sun Jan 18, 2015 13:02
GitHub: ABJ-MV
In-game: ABJ
Location: In Earth orbit, with a perigee of 1048 km and an apogee of 1337 km and an inclination of 69 degrees.

Re: Post your modding questions here

by ABJ » Post

Ooops! I meant position!

Nyarg
Member
Posts: 276
Joined: Sun May 15, 2016 04:32

Re: Post your modding questions here

by Nyarg » Post

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 )
I am a noob. still yet. Not so noob ) [vml] WIP and a little proof for fun PlantedTorch )))
MT Strike 78a36b468554d101e0be3b0d1f587a555f396452 Great! Somebody have found it )
"My english isn't well" I know. I'm sorry )

User avatar
cx384
Member
Posts: 653
Joined: Wed Apr 23, 2014 09:38
GitHub: cx384
IRC: cx384

Re: Post your modding questions here

by cx384 » Post

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
Can your read this?

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: Post your modding questions here

by sofar » Post

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`.

User avatar
Lord_Vlad
Member
Posts: 112
Joined: Thu Jul 20, 2017 07:58

Re: Post your modding questions here

by Lord_Vlad » Post

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 ?

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: Post your modding questions here

by sofar » Post

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.

User avatar
christoferlevich
Member
Posts: 325
Joined: Thu Dec 01, 2016 23:44
GitHub: ChristoferL
Location: Athol, Massachusetts

Re: Post your modding questions here

by christoferlevich » Post

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.
everything can be a learning experience...

User avatar
Linuxdirk
Member
Posts: 3217
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: Post your modding questions here

by Linuxdirk » Post

When having a node with paramtype2 = 'facedir' ... how can I properly determine left/right/front/back according to the node's orientation when placed?

User avatar
BirgitLachner
Member
Posts: 393
Joined: Thu May 05, 2016 10:18
In-game: Bibs

Re: Post your modding questions here

by BirgitLachner » Post

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.
Last edited by BirgitLachner on Tue Aug 08, 2017 19:38, edited 2 times in total.

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: Post your modding questions here

by sofar » Post

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

User avatar
Linuxdirk
Member
Posts: 3217
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: Post your modding questions here

by Linuxdirk » Post

Great :D I’ll check this out. Thanks.

User avatar
BirgitLachner
Member
Posts: 393
Joined: Thu May 05, 2016 10:18
In-game: Bibs

Re: Post your modding questions here

by BirgitLachner » Post

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.

User avatar
Lord_Vlad
Member
Posts: 112
Joined: Thu Jul 20, 2017 07:58

Re: Post your modding questions here

by Lord_Vlad » Post

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.

User avatar
christoferlevich
Member
Posts: 325
Joined: Thu Dec 01, 2016 23:44
GitHub: ChristoferL
Location: Athol, Massachusetts

Re: Post your modding questions here

by christoferlevich » Post

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
everything can be a learning experience...

zing269
Member
Posts: 109
Joined: Sat Apr 30, 2016 19:10

Re: Post your modding questions here

by zing269 » Post

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.

hajo
Member
Posts: 606
Joined: Thu Oct 13, 2016 10:45
Location: DE
Contact:

Re: Post your modding questions here

by hajo » Post

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

User avatar
BirgitLachner
Member
Posts: 393
Joined: Thu May 05, 2016 10:18
In-game: Bibs

Re: Post your modding questions here

by BirgitLachner » Post

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.

User avatar
orwell
Member
Posts: 958
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
IRC: orwell96_mt
In-game: orwell
Location: Raxacoricofallapatorius

Re: Post your modding questions here

by orwell » Post

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)
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...

User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: Post your modding questions here

by azekill_DIABLO » Post

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
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

Locked

Who is online

Users browsing this forum: No registered users and 6 guests