Post your modding questions here

User avatar
kaeza
Moderator
 
Posts: 2162
Joined: Thu Oct 18, 2012 05:00
Location: Montevideo, Uruguay
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
 

sofar
Developer
 
Posts: 2066
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:

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
Moderator
 
Posts: 5843
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
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: 251
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?
 

User avatar
Hybrid Dog
Member
 
Posts: 2718
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: 21
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:
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: 201
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
Developer
 
Posts: 2066
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
Developer
 
Posts: 2066
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:
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: 191
Joined: Sat Aug 22, 2015 00:50
Location: Foobass, isle of Atlantis, castle of Bardvendelle
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!
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.

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
Moderator
 
Posts: 2162
Joined: Thu Oct 18, 2012 05:00
Location: Montevideo, Uruguay
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
 

User avatar
swordpaint12
Member
 
Posts: 191
Joined: Sat Aug 22, 2015 00:50
Location: Foobass, isle of Atlantis, castle of Bardvendelle
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.
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.

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: 412
Joined: Thu Jun 11, 2015 23:19
Location: SW Florida, USA
In-game: Knatt

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: 191
Joined: Sat Aug 22, 2015 00:50
Location: Foobass, isle of Atlantis, castle of Bardvendelle
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?
Code: Select all
drop = "farming:example_food"

I don't know if that would help.
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.

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: 21
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: 2612
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:

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:

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: 21
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: 251
Joined: Wed Apr 13, 2016 17:34
GitHub: pithydon

Re: Post your modding questions here

by pithy » Sun May 29, 2016 03:10

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

vitalie
Member
 
Posts: 66
Joined: Wed Feb 24, 2016 07:38
GitHub: ciubotaru

Re: Post your modding questions here

by vitalie » Tue May 31, 2016 17:12

How should I register a node, so that it disappears on digging without appearing in player's inventory and without dropping anything?
 

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

Re: Post your modding questions here

by azekill_DIABLO » Tue May 31, 2016 17:48

Code: Select all
minetest.register_node("fruitgrow:apples", {
   description = "Apples",
   paramtype = "light",
   tiles = {"default_apple.png^default_leaves.png^default_torch_animated.png"},
   drawtype = "allfaces_optional",
   is_ground_content = false,
   groups = {dig_immediate=3, leafdecay=1, leaves=1},
   drop = {
      max_items = 0,
},
})


Here you go !
 

vitalie
Member
 
Posts: 66
Joined: Wed Feb 24, 2016 07:38
GitHub: ciubotaru

Re: Post your modding questions here

by vitalie » Tue May 31, 2016 18:41

azekill_DIABLO, thank you!

I wrote "drops = " instead of "drop = ", and couldn't understand why it doesn't work.
 

Soudon
Member
 
Posts: 167
Joined: Wed Apr 08, 2015 17:14
In-game: Soudon

init.lua error can't figure it out please help.

by Soudon » Fri Jun 03, 2016 02:36

Ok so I am attempting to make my own mod and it is one that is adding a few more "modern" weapons to the game. This is the error I get

init.lua:4: '<eof>' expected near 'end'

First my init.lua looks like this

Code: Select all
local modpath = minetest.get_modpath(minetest.get_current_modname())

dofile(modpath.."/guns.lua")
end


and I do have a separate lua called guns.lua and it looks like this

Code: Select all
modernguns:register_weapon("modernguns:mp5holo", {
   description = "MP5(ranged damage 3|max ammo 30)",
   inventory_image = "modernguns_mp5holo.png",
   rounds = 10,
   shots = 3,
   spec = {
      range = 285,
      step = 20,
      tool_caps = {full_punch_interval=0.125, damage_groups={fleshy=3}},
      groups = {snappy=3, fleshy=3, oddly_breakable_by_hand=3},
      sound = "modernguns_mp5",
      particle = "modernguns_bullet.png",
   },
})
 

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

Re: Post your modding questions here

by pithy » Fri Jun 03, 2016 02:44

Remove "end" in the first file.
 

PreviousNext

Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 3 guests