Post your modding questions here

Godo
Member
 
Posts: 17
Joined: Mon May 02, 2016 06:41
In-game: Godo

Inventory works all right

by Godo » Sat May 21, 2016 12:39

Thank you very much, it works all right with version 0.4.14 (I thought it was only a developer's version, so I had not tried it).
 

Thegameboy
New member
 
Posts: 2
Joined: Sun May 22, 2016 00:15

Re: Post your modding questions here

by Thegameboy » Sun May 22, 2016 00:27

Topic: Is there any update function?
Reason: Update function to place code in that updates every tick/frame, to continually check certain conditions? Also, for something like...
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_joinplayer(function(player) --player object
  local pos = player:getpos()
  local y = pos.y
end)


...how do you get the local (or global, could be any kind really) variable outside of the function's local environment and into the script's? The script is loaded when the world starts up but the callback is executed at a later point in time...

More Info: I've checked for a bit for answers to these questions on the glossary for functions but couldn't find anything that applies.
 

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

Re: Post your modding questions here

by sofar » Sun May 22, 2016 03:58

Thegameboy wrote:Topic: Is there any update function?
Reason: Update function to place code in that updates every tick/frame, to continually check certain conditions? Also, for something like...
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_joinplayer(function(player) --player object
  local pos = player:getpos()
  local y = pos.y
end)


...how do you get the local (or global, could be any kind really) variable outside of the function's local environment and into the script's? The script is loaded when the world starts up but the callback is executed at a later point in time...

More Info: I've checked for a bit for answers to these questions on the glossary for functions but couldn't find anything that applies.


Short answer: make a persistent variable outside the `register_on_joinplayer()` 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

local storage = {}

minetest.register_on_joinplayer(function(player) --player object
  local pos = player:getpos()
  storage.y = pos.y
end)

 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Post your modding questions here

by rubenwardy » Sun May 22, 2016 11:33

sofar wrote:
Thegameboy wrote:Topic: Is there any update function?
Reason: Update function to place code in that updates every tick/frame, to continually check certain conditions? Also, for something like...
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_joinplayer(function(player) --player object
  local pos = player:getpos()
  local y = pos.y
end)


...how do you get the local (or global, could be any kind really) variable outside of the function's local environment and into the script's? The script is loaded when the world starts up but the callback is executed at a later point in time...

More Info: I've checked for a bit for answers to these questions on the glossary for functions but couldn't find anything that applies.


Short answer: make a persistent variable outside the `register_on_joinplayer()` 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

local storage = {}

minetest.register_on_joinplayer(function(player) --player object
  local pos = player:getpos()
  storage.y = pos.y
end)



That'll only work for a single player, much better 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
local storage = {}

minetest.register_on_joinplayer(function(player) --player object
  local pos = player:getpos()
  storage[player:get_player_name()] = {y = pos.y}
end)

minetest.register_on_leaveplayer(function(player)
  storage[player:get_player_name()] = nil
end)

local function checkSomething(player)
  local pos = storage[player:get_player_name()]
  print(pos.y)
end


to run code every X seconds, the best way is to use minetest.after:

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 function timerRun()
    -- code to run

    minetest.after(X, timerRun)
end

minetest.after(X, timerRun)


Replace X with a number, whole ones work best.

To run every X seconds on a node, use ABMs or a nodetimer.
 

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Re: Post your modding questions here

by TumeniNodes » Sun May 22, 2016 18:37

So, I am almost finished with my texture pack, and plan to make it available soon. (within about 2 weeks to a month)
But I have a roadblock to consider and resolve.
Some of the textures in the pack will rely upon some minor alterations to the default nodes lua (regarding default water source), and the default mapgen... How best to approach this?
Do I release the TP as mod, rather than simply a TP? And if so, what is the best way to do so?, as I will want the TP textures to over ride the default textures (which is simple in itself), but it also adds a few textures which then require my alterations to the default mapgen (where I added "Red_Desert" and "Red_Desert_Ocean" biomes)
Just looking for some input, thoughts & advice. Thank you

wow, feel like this got the cold shoulder... oh well 4 days later no response
Last edited by TumeniNodes on Thu May 26, 2016 05:13, edited 3 times in total.
Flick?... Flick who?
 

Thegameboy
New member
 
Posts: 2
Joined: Sun May 22, 2016 00:15

Re: Post your modding questions here

by Thegameboy » Sun May 22, 2016 18:59

rubenwardy wrote:
sofar wrote:
Thegameboy wrote: . . .


Short answer: make a persistent variable outside the `register_on_joinplayer()` 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

local storage = {}

minetest.register_on_joinplayer(function(player) --player object
  local pos = player:getpos()
  storage.y = pos.y
end)



That'll only work for a single player, much better 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
local storage = {}

minetest.register_on_joinplayer(function(player) --player object
  local pos = player:getpos()
  storage[player:get_player_name()] = {y = pos.y}
end)

minetest.register_on_leaveplayer(function(player)
  storage[player:get_player_name()] = nil
end)

local function checkSomething(player)
  local pos = storage[player:get_player_name()]
  print(pos.y)
end


to run code every X seconds, the best way is to use minetest.after:

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 function timerRun()
    -- code to run

    minetest.after(X, timerRun)
end

minetest.after(X, timerRun)


Replace X with a number, whole ones work best.

To run every X seconds on a node, use ABMs or a nodetimer.



Thanks a lot, guys!
 

User avatar
pithy
Member
 
Posts: 252
Joined: Wed Apr 13, 2016 17:34
GitHub: pithydon

Re: Post your modding questions here

by pithy » Mon May 23, 2016 16:19

How do I count how many nodes are near a node?
 

User avatar
pithy
Member
 
Posts: 252
Joined: Wed Apr 13, 2016 17:34
GitHub: pithydon

Re: Post your modding questions here

by pithy » Mon May 23, 2016 16:52

and can I make an ABM do one action on all loaded nodes, and then the other action?
 

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

Re: Post your modding questions here

by sofar » Mon May 23, 2016 22:15

pithy wrote:How do I count how many nodes are near a node?


Ambiguous, even "air" is a node, so you need to be more specific.

If you want to count specific nodes, you can use e.g.

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

the return value is an array, so you can count the items in it with #arrayname.
 

User avatar
AnxiousInfusion
Member
 
Posts: 146
Joined: Sun Aug 02, 2015 05:43
GitHub: AnxiousInfusion[GitLab]
IRC: AnxiousInfusion
In-game: AnxiousInfusion

Re: Post your modding questions here

by AnxiousInfusion » Tue May 24, 2016 04:00

rubenwardy wrote:to run code every X seconds, the best way is to use minetest.after:

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 function timerRun()
    -- code to run

    minetest.after(X, timerRun)
end

minetest.after(X, timerRun)


Replace X with a number, whole ones work best.


Interesting, in making my first timer I wanted to use minetest.after in that way but I was afraid it would hit a recursion limit after continuously calling the function from within itself for long enough. Does lua not suffer from this problem? Regardless, I ended up using minetest.register_globalstep to serve that purpose.
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: Post your modding questions here

by kaeza » Tue May 24, 2016 06:34

AnxiousInfusion wrote:Interesting, in making my first timer I wanted to use minetest.after in that way but I was afraid it would hit a recursion limit after continuously calling the function from within itself for long enough. Does lua not suffer from this problem? Regardless, I ended up using minetest.register_globalstep to serve that purpose.

It isn't a recursive call. You just "push" or "queue" a function to be called later. At the time the next call to your function actually happens, the original call to your function already returned (regardless of the `after` timeout).
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

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

Re: Post your modding questions here

by sofar » Tue May 24, 2016 07:06

AnxiousInfusion wrote:
rubenwardy wrote:to run code every X seconds, the best way is to use minetest.after:

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 function timerRun()
    -- code to run

    minetest.after(X, timerRun)
end

minetest.after(X, timerRun)


Replace X with a number, whole ones work best.


Interesting, in making my first timer I wanted to use minetest.after in that way but I was afraid it would hit a recursion limit after continuously calling the function from within itself for long enough. Does lua not suffer from this problem? Regardless, I ended up using minetest.register_globalstep to serve that purpose.


This is safe.

Timers that are inserted during the execution of timers are not executed until the next global step ever.

This is done explicitly to allow this usage and to make it safe.

The way it works in detail is that if timers are added to the list of timers, they will never be processed in the current timer execution cycle, because the timer execution code goes from the BACK of the table to the front, and so it will not see new timers until it runs again at a later time.

Please use this minetest.after() "recursion" instead of globalstep if you don't need to be running every globalstep!
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Post your modding questions here

by rubenwardy » Tue May 24, 2016 11:38

It doesn't call itself from within itself. It adds the function onto a priority queue to be run again
 

User avatar
pithy
Member
 
Posts: 252
Joined: Wed Apr 13, 2016 17:34
GitHub: pithydon

Re: Post your modding questions here

by pithy » Tue May 24, 2016 15:15

How do I search for a node in all loaded blocks?
 

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

by Hybrid Dog » Tue May 24, 2016 19:57

pithy wrote:How do I search for a node in all loaded blocks?

You could use lbm to catch specific nodes when they get loaded.
 

User avatar
Sirmentio
Member
 
Posts: 18
Joined: Thu Apr 21, 2016 17:22
In-game: Sirmentio

Re: Post your modding questions here

by Sirmentio » Wed May 25, 2016 00:55

How do I make a sound play (with minetest.sound_play) for an entire multiplayer server?

My friend has been getting an error in the logs and were not sure if it's possible:
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
Undeclared global variable "playedmus" accessed at init.lua (Line 14)"
"Assignment to undeclared global "playedmus" inside a function at init.lua (Line 17)
 

User avatar
ErrorNull
Member
 
Posts: 94
Joined: Thu Mar 03, 2016 00:43

Re: Post your modding questions here

by ErrorNull » Wed May 25, 2016 04:19

hello everyone. i have two modding questions:

#1. how can i replicate the on-screen effect of flashing color when something happens to the player? ex. I've made a mod that incorporates player exhaustion states.. and would like the screen to flash different color like white when player is exhausted. would this be done via huds? if there is existing mod as an example, I'd be happy to learn from that.

I know that i can fake the effect by reducing the player's hp by 1 and giving it back. But i don't want to hinge my effect up the back of an existing (and important) mechanism like the player's health. Plus i want to control the color the of the flashing.

#2. i want to pretty particle effects shower over the player upon consumption of some magic potions... because, you know... all potions have to do that right?! can someone direct me to api or mod example on how to do this... or even some basics on how to call particles into minetest? thanks!
 

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

Re: Post your modding questions here

by sofar » Wed May 25, 2016 06:14

ErrorNull wrote:hello everyone. i have two modding questions:

#1. how can i replicate the on-screen effect of flashing color when something happens to the player? ex. I've made a mod that incorporates player exhaustion states.. and would like the screen to flash different color like white when player is exhausted. would this be done via huds? if there is existing mod as an example, I'd be happy to learn from that.

I know that i can fake the effect by reducing the player's hp by 1 and giving it back. But i don't want to hinge my effect up the back of an existing (and important) mechanism like the player's health. Plus i want to control the color the of the flashing.


Make a HUD element that is fullscreen and contains a semi-transparent texture.

ErrorNull wrote:#2. i want to pretty particle effects shower over the player upon consumption of some magic potions... because, you know... all potions have to do that right?! can someone direct me to api or mod example on how to do this... or even some basics on how to call particles into minetest? thanks!


read the entire section from here:

https://github.com/minetest/minetest/blob/master/doc/lua_api.txt#L2298
 

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

Re: Post your modding questions here

by sofar » Wed May 25, 2016 06:17

Sirmentio wrote:How do I make a sound play (with minetest.sound_play) for an entire multiplayer server?


For every player on the server, play a sound exclusively to that player.

Sirmentio wrote:My friend has been getting an error in the logs and were not sure if it's possible:
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
Undeclared global variable "playedmus" accessed at init.lua (Line 14)"
"Assignment to undeclared global "playedmus" inside a function at init.lua (Line 17)


put `local` in front of the place where `playedmus` is first defined or used.
 

User avatar
swordpaint12
Member
 
Posts: 187
Joined: Sat Aug 22, 2015 00:50
In-game: [swordpaint12][Belching_Balladeer]

Re: Post your modding questions here

by swordpaint12 » Thu May 26, 2016 00:43

A HUD question. Suppose I wanted to change the hud at certain times so that a certain picture would be on the screen for an amount of time. Kind of like the bubbles. How would I do that? Thanks!
Winter Cumicles
God's not dead; remember that!
Yay for MT! No MC here!
I am a human. I'm younger than 100 years old.
I've been playing Minetest since December 2014.
Fruit!

I'm amazed that I haven't been on here in so long! My latest minetest accomplishment was mining by hand (well, as close as you can get in a computer game) a circle 30 blocks in diameter. It took forever but it's pretty cool.
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: Post your modding questions here

by kaeza » Thu May 26, 2016 01:52

swordpaint12 wrote:A HUD question. Suppose I wanted to change the hud at certain times so that a certain picture would be on the screen for an amount of time. Kind of like the bubbles. How would I do that? Thanks!

The function `player:hud_add` returns the ID of the HUD item. Save that somewhere, then just call `player:hud_change(id, "someparam", somevalue)`. See the function's description in `lua_api.txt`.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
swordpaint12
Member
 
Posts: 187
Joined: Sat Aug 22, 2015 00:50
In-game: [swordpaint12][Belching_Balladeer]

Re: Post your modding questions here

by swordpaint12 » Thu May 26, 2016 20:15

Thank you!
Okay, new question. In the default mod in the minetest_game, which .lua file contains all the coding for the apple? I want to figure out how you put it down.
Winter Cumicles
God's not dead; remember that!
Yay for MT! No MC here!
I am a human. I'm younger than 100 years old.
I've been playing Minetest since December 2014.
Fruit!

I'm amazed that I haven't been on here in so long! My latest minetest accomplishment was mining by hand (well, as close as you can get in a computer game) a circle 30 blocks in diameter. It took forever but it's pretty cool.
 

KCoombes
Member
 
Posts: 278
Joined: Thu Jun 11, 2015 23:19
In-game: Knatt or Rudilyn

Re: Post your modding questions here

by KCoombes » Thu May 26, 2016 23:08

Hopefully a quick question:

I am trying to edit the default farming mod to add a new crop. I have register_plant and register_craftitem for the crop in the init file, and I can plant the seed and watch the crop grow - but there is no drop when I harvest it. According to the commented init file, the register_craftitem is for registering the harvest - so why is it not dropping the item?
 

User avatar
swordpaint12
Member
 
Posts: 187
Joined: Sat Aug 22, 2015 00:50
In-game: [swordpaint12][Belching_Balladeer]

Re: Post your modding questions here

by swordpaint12 » Thu May 26, 2016 23:23

KCoombes wrote:Hopefully a quick question:

I am trying to edit the default farming mod to add a new crop. I have register_plant and register_craftitem for the crop in the init file, and I can plant the seed and watch the crop grow - but there is no drop when I harvest it. According to the commented init file, the register_craftitem is for registering the harvest - so why is it not dropping the item?

Did you code the line that says drop item?
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
drop = "farming:example_food"

I don't know if that would help.
Winter Cumicles
God's not dead; remember that!
Yay for MT! No MC here!
I am a human. I'm younger than 100 years old.
I've been playing Minetest since December 2014.
Fruit!

I'm amazed that I haven't been on here in so long! My latest minetest accomplishment was mining by hand (well, as close as you can get in a computer game) a circle 30 blocks in diameter. It took forever but it's pretty cool.
 

User avatar
Sirmentio
Member
 
Posts: 18
Joined: Thu Apr 21, 2016 17:22
In-game: Sirmentio

Re: Post your modding questions here

by Sirmentio » Sat May 28, 2016 18:57

Hopefully this can be easy to understand:

on mobs redo, how could I m,ake an event/function occur upon the mob being punched? Aswell as this, how could I make an event occur when the mob spawns? Thank you in advance

Edit: one more thing (I PROMISE!) is it possible to do an event onjce the mob is down certain health?
 

User avatar
TenPlus1
Member
 
Posts: 1874
Joined: Mon Jul 29, 2013 13:38
GitHub: tenplus1

Re: Post your modding questions here

by TenPlus1 » Sat May 28, 2016 19:35

Using the do_custom function within the mob definition gives you a lot of freedom when creating customised features, e.g.

when Evil Bonny is spawned into the world it displays a message in chat only once:

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
do_custom = function(self)
   if not self.evil_bonny then
      minetest.chat_send_all(">>> Evil Bonny has been unleashed on this world <<<")
      self.evil_bonny = 1
   end
end,


...or... if health is at a certain level then it shows a message:

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
do_custom = function(self)
   if self.health <= 10 then
      minetest.chat_send_all("Mob health is kinda low, play nice now")
   end
end,
 

User avatar
Sirmentio
Member
 
Posts: 18
Joined: Thu Apr 21, 2016 17:22
In-game: Sirmentio

Re: Post your modding questions here

by Sirmentio » Sat May 28, 2016 20:02

Thanks! I'm very grateful, the context here is that I'm trying to create a boss event for a private server with my friends, now thinking ab out it, is it possible with this to get this theoretical evil bunny's position? Thank you in advance!
 

User avatar
pithy
Member
 
Posts: 252
Joined: Wed Apr 13, 2016 17:34
GitHub: pithydon

Re: Post your modding questions here

by pithy » Sun May 29, 2016 03:10

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_rightclick = function(pos, node, puncher)
      local nodes = {}
      do
         local start = minetest.find_nodes_in_area({x = pos.x - 1, y = pos.y - 1, z = pos.z - 1}, {x = pos.x + 1, y = pos.y + 1, z = pos.z + 1}, {"group:wireworld"})
         for k,v in pairs(start) do
            table.insert(nodes, v)
         end
      end
      local total = {}
      for k,v in pairs(nodes) do table.insert(total, v) end
      repeat
         local next = {}
         for k,v in pairs(nodes) do
            local find = minetest.find_nodes_in_area({x = v.x - 1, y = v.y - 1, z = v.z - 1}, {x = v.x + 1, y = v.y + 1, z = v.z + 1}, {"group:wireworld"})
            for k,v in pairs(find) do
          if not table.contains(total, v) then
                 local meta = minetest.get_meta(v)
                 table.insert(next, v)
          end
            end
         end
         local nodes = {}
         for k,v in pairs(next) do table.insert(nodes, v) end
         for k,v in pairs(nodes) do table.insert(total, v) end
         local count = 0
         for _ in pairs(nodes) do count = count + 1 end
      until count == 0
      for k,v in pairs(total) do
         local meta = minetest.get_meta(v)
         meta:set_string("wireworld", "stop")
      end
    minetest.swap_node(pos, {name = "wireworld:wireworld_off"})
   end,


This freezes the game every time and I don't know why.
My suspicion is count never reaches 0.
 

User avatar
pithy
Member
 
Posts: 252
Joined: Wed Apr 13, 2016 17:34
GitHub: pithydon

Re: Post your modding questions here

by pithy » Sun May 29, 2016 20:54

I simplified it to this but it still does the same thing
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_rightclick = function(pos, node, puncher)
      local nodes = minetest.find_nodes_in_area({x = pos.x - 1, y = pos.y - 1, z = pos.z - 1}, {x = pos.x + 1, y = pos.y + 1, z = pos.z + 1}, {"group:wireworld"})
      for i,v in ipairs(nodes) do
         local find = minetest.find_nodes_in_area({x = v.x - 1, y = v.y - 1, z = v.z - 1}, {x = v.x + 1, y = v.y + 1, z = v.z + 1}, {"group:wireworld"})
         for i,v in ipairs(find) do
        if not table.contains(nodes, v) then
              local meta = minetest.get_meta(v)
          meta:set_string("wireworld", "stop")
              nodes[#nodes+1] = v
        end
         end
      end
    minetest.swap_node(pos, {name = "wireworld:wireworld_off"})
   end,

and the table.contains function 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
function table.contains(table, element)
  for _, value in pairs(table) do
    if value == element then
      return true
    end
  end
  return false
end
 

User avatar
pithy
Member
 
Posts: 252
Joined: Wed Apr 13, 2016 17:34
GitHub: pithydon

Re: Post your modding questions here

by pithy » Sun May 29, 2016 21:27

to late my brain figured it out
 

PreviousNext

Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 6 guests

cron