Post your modding questions here

leeminer
Member
 
Posts: 90
Joined: Mon Aug 11, 2014 21:29

Re: Post your modding questions here

by leeminer » Wed Dec 31, 2014 18:04

Thanks HybridDog... This helps. I think the code I found was unfinished and confused me....

Anyway, one more question. The "name" variable. I assume this is a global variable. Is there a list of global variables that can be used with these anonymous functions?


*gonna try your suggestion when I get home. I'm working on a sound mod myself. The immersive sounds really inspired me.
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

Re: Post your modding questions here

by Krock » Wed Dec 31, 2014 19:51

leeminer wrote:The "name" variable. I assume this is a global variable.


leeminer wrote:
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_chatcommand("mvol", {
   params = "<mvol>",
   description = "set volume of music, default 1 normal volume.",
   privs = {server=true},
   func = function(name, param)


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
   func = function(name, param)

The function is called with those two variables.
Do with them what you want but they're not global.
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 

leeminer
Member
 
Posts: 90
Joined: Mon Aug 11, 2014 21:29

Re: Post your modding questions here

by leeminer » Wed Dec 31, 2014 20:38

HybridDog linked to this example

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_chatcommand("mvol", {
   params = "<mvol>",
   description = "set volume of music, default 1 normal volume.",
   privs = {server=true},
   func = function(name, param)
      MUSICVOLUME = param
      minetest.chat_send_player(name, "Music volume set.")
   end,
})



The name variable in the chat_send_player function, is not defined here. So I was wondering where there name is assigned. I assumed it was a global variable that holds the current users name.
 

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

Re: Post your modding questions here

by Hybrid Dog » Wed Dec 31, 2014 21:01

leeminer wrote:HybridDog linked to this example

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_chatcommand("mvol", {
   params = "<mvol>",
   description = "set volume of music, default 1 normal volume.",
   privs = {server=true},
   func = function(name, param)
      MUSICVOLUME = param
      minetest.chat_send_player(name, "Music volume set.")
   end,
})



The name variable in the chat_send_player function, is not defined here. So I was wondering where there name is assigned. I assumed it was a global variable that holds the current users name.

l think name comes from there, which uses minetest.register_on_chat_message
from https://github.com/minetest/minetest/bl ... .cpp#L2108
or https://github.com/minetest/minetest/bl ... r.cpp#L128
or https://github.com/minetest/minetest/bl ... r.cpp#L128

I think name is neither global, nor local
but it's more local than global
http://www.lua.org/pil/5.html
http://www.lua.org/pil/6.html
 

leeminer
Member
 
Posts: 90
Joined: Mon Aug 11, 2014 21:29

Re: Post your modding questions here

by leeminer » Wed Dec 31, 2014 23:02

Ok all, I think I'm getting somewhere with your help.

The chat command has a name of the command, name of the player and the parameter. In this case the parameter is the volume level.

So the variable "name" and "param" must be defined somewhere else in the code. The anonymous function uses the "name" and "param" variable and can be used for whatever purpose you want in the func = function (name, param) anonymous function.

Not sure if it is because I am new to Lua or what but that took some time ;)

Thanks guys and gals

**EDIT

Going to try this test of code out

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_chatcommand("noon", {

    params="",
    description="Sets time to noon",
    func=function(name, param)
      minetest.set_timeofday(.5)
   end,
}]
 

Kilarin
Member
 
Posts: 649
Joined: Mon Mar 10, 2014 00:36

Re: Post your modding questions here

by Kilarin » Fri Jan 02, 2015 16:19

Stupid lua question.

Suppose in a mod mymod in init.lua I have an array named mylist that is defined at the top level.
I also have a function called loadarray that loads that array (but does not return it)

I also have another lua within that mod folder called specialobj.
within specialobj I do:
mymod.loadarray()
so now the array should be loaded, but it's loaded inside mymod. How could I access the contents of that array? I assumed mymod.mylist[1] would return element 1 of the array, but instead I get errors saying that mylist is nil.
 

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

Re: Post your modding questions here

by TenPlus1 » Fri Jan 02, 2015 20:01

You would have to make a global value readable to any mod, like I do in mobs redo or farming redo:

farming.mod = "redo"
mobs.mod = "redo"
mymod.array = {} -- global value

you can call mymod.loadarray() and the above will be loaded for use for all mods that use it...
 

leeminer
Member
 
Posts: 90
Joined: Mon Aug 11, 2014 21:29

Need help adding a mob entity

by leeminer » Sat Jan 03, 2015 14:33

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_abm({
   nodenames = {"leemod:woodyblock"},
   
   interval = 10.0, -- Run every 10 seconds
   chance = 5, -- Select every 1 in 50 nodes
   action = function(pos, node)
      minetest.add_entity(pos,"mobs:cow")
      --minetest.remove_node(pos)
   end
})



When using the line, minetest.add_entity(pos,"mobs:cow"), I get an error that the mob:cow doesnt exist.
I have mobs enabled of course.

I know I must be missing something major but not sure what.
Do I have to use the dofile command to include the mobs mod in order to use those variables/entities????


Note that the ABM works fine with the remove node command just fine.

Help!
 

User avatar
HeroOfTheWinds
Member
 
Posts: 470
Joined: Wed Apr 23, 2014 23:16
GitHub: HeroOfTheWinds
IRC: WindHero

Re: Post your modding questions here

by HeroOfTheWinds » Sat Jan 03, 2015 19:41

Do you have mobs added to the dependencies.txt? That often causes trouble for mods that reference others, and it's easy to miss.
Nam ex spatio, omnes res venire possunt.
Why let the ground limit you when you can reach for the sky?
Back to college now, yay for sophomore year schedules. :P
 

leeminer
Member
 
Posts: 90
Joined: Mon Aug 11, 2014 21:29

Re: Post your modding questions here

by leeminer » Sat Jan 03, 2015 20:33

HeroOfTheWinds wrote:Do you have mobs added to the dependencies.txt? That often causes trouble for mods that reference others, and it's easy to miss.



DOH!!!

So thats what that is for lol.
 

User avatar
pandaro
Member
 
Posts: 266
Joined: Sun Jan 08, 2012 21:34
GitHub: pandaro

Re: Post your modding questions here

by pandaro » Wed Jan 07, 2015 19:21

In the definition of an ABM you can specify which neighboring nodes that trigger the action.
So, I need to know where it is that node that triggers the action.
Is there a way to know where is that node without having to call for example: "neighbor = 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}, "air")

i tried this stupid way, but dont work:
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_abm({
nodenames={"a:a"},
neighbors={'default:cobble'},
interval=1,
chance=1,

   action=function(pos, node, active_object_count, active_object_count_wider)
   print(tostring('neighbors: ')..dump(neighbors))
end,
})
 

User avatar
srifqi
Member
 
Posts: 508
Joined: Sat Jun 28, 2014 04:31
GitHub: srifqi
IRC: srifqi
In-game: srifqi

Re: Post your modding questions here

by srifqi » Wed Jan 07, 2015 19:28

^^^
@pandaro:
That code will not work, the 'neighbors' variable is not exist nor given, so you need to use minetest.find_nodes_in_area.
I'm from Indonesia! Saya dari Indonesia!
Terjemahkan Minetest!
Mods by me. Modifikasi oleh saya.

Pronounce my nick as in: es-rifqi (IPA: /es rifˈki/)
 

User avatar
pandaro
Member
 
Posts: 266
Joined: Sun Jan 08, 2012 21:34
GitHub: pandaro

Re: Post your modding questions here

by pandaro » Wed Jan 07, 2015 19:32

srifqi wrote:^^^
@pandaro:
That code will not work, the 'neighbors' variable is not exist nor given, so you need to use minetest.find_nodes_in_area.


ok thanks srifqi
 

User avatar
srifqi
Member
 
Posts: 508
Joined: Sat Jun 28, 2014 04:31
GitHub: srifqi
IRC: srifqi
In-game: srifqi

Re: Post your modding questions here

by srifqi » Wed Jan 07, 2015 19:33

You are welcome! Don't afraid to post your modding question here!
I'm from Indonesia! Saya dari Indonesia!
Terjemahkan Minetest!
Mods by me. Modifikasi oleh saya.

Pronounce my nick as in: es-rifqi (IPA: /es rifˈki/)
 

User avatar
Kalabasa
Member
 
Posts: 34
Joined: Tue Jan 06, 2015 17:36
GitHub: Kalabasa
IRC: Kalabasa
In-game: Kalabasa

Re: Post your modding questions here

by Kalabasa » Thu Jan 08, 2015 14:49

How can I override a registered ABM? I am trying to modify the behaviour of the default furnace node.
insert signature here
 

tfranko
Member
 
Posts: 12
Joined: Mon Oct 06, 2014 22:34

Re: Post your modding questions here

by tfranko » Thu Jan 08, 2015 19:55

I'd like some help with entities and assigning static data to them and displaying this static data. I think this is what I want, anyway.

Ultimately, I'd like the player to be able to right click on an entity which will open a formspec and allow the user to enter a name for the entity. I'd like that name to then be displayed either above the entity all of the time or when the player hovers over the entity. Then, if the player wants to right click on the entity again in order to change the name, the formspec will open again and the player can change the name if desired.

I looked at the LUAEntitySAO page: http://dev.minetest.net/LuaEntitySAO and see the get_staticdata(self) function. I've also looked here: https://rubenwardy.github.io/minetest_d ... specs.html, but I'm so far unable to use these resources to put what I want together.

Let me know if I need to share any other info. Any help with this will be appreciated.

Thank you.
 

TeTpaAka
Member
 
Posts: 131
Joined: Sat Dec 28, 2013 21:54

Re: Post your modding questions here

by TeTpaAka » Thu Jan 08, 2015 20:46

I'd like that name to then be displayed either above the entity all of the time or when the player hovers over the entity.


Take a look at this:
https://forum.minetest.net/viewtopic.php?f=9&t=7321&hilit=npc
It uses textures for every char that is displayed.
 

tfranko
Member
 
Posts: 12
Joined: Mon Oct 06, 2014 22:34

Re: Post your modding questions here

by tfranko » Sat Jan 10, 2015 02:59

TeTpaAka wrote:
I'd like that name to then be displayed either above the entity all of the time or when the player hovers over the entity.


Take a look at this:
https://forum.minetest.net/viewtopic.php?f=9&t=7321&hilit=npc
It uses textures for every char that is displayed.


Thank you! It looks complicated. Do you know of any easier way that doesn't use entities/textures for the lettering? I'd settle for displaying infotext about the entity when hovering the mouse over the entity (i.e. mouseover). I see that infotext is possible for nodes, but it doesn't appear to be possible for entities.

I'm using Carbone's mobs mod to create the entity, so I'm not sure how I would integrate the part of the code I want from the link you shared above with the mobs mod. I'll keep working on it though.
 

LonelyCrow
New member
 
Posts: 2
Joined: Sat Jan 10, 2015 16:17
In-game: Lonelycrow

Re: Post your modding questions here

by LonelyCrow » Sat Jan 10, 2015 17:46

Any Idea on how to access the World Directory? Sorry, I am rather new to modifying software and the lingo for that matter.
 

tfranko
Member
 
Posts: 12
Joined: Mon Oct 06, 2014 22:34

Re: Post your modding questions here

by tfranko » Sat Jan 10, 2015 18:03

tfranko wrote:I'm using Carbone's mobs mod to create the entity, so I'm not sure how I would integrate the part of the code I want from the link you shared above with the mobs mod. I'll keep working on it though.


I came up with the following relatively simple solution as an alternative. What do you think? Is there a better way to do this?

This is the function to manage the HUD text:

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 name_hud = nil

function display_mob_name(player_object, text)
-- Function to flash text near cursor.

    local player = player_object

    if name_hud == nil then

        name_hud = player:hud_add({
       hud_elem_type = "text",
       position = {x=.5, y=.5},
       alignment = {x=-0, y=0},
       offset = {x=0, y=-18},
       text =  text,
       number = 0xFFFF00, -- Color as 0xRRGGBB
   }) -- name_hud()

    else

        player:hud_change(name_hud, 'text', text)

    end -- if/then

    minetest.after(5, function()
        player:hud_remove(name_hud)
        name_hud = nil
    end) -- after()

end -- HUD function


Then, I call this function in the entity's on_rightclick() property:

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
display_mob_name(clicker, self.mob_name)


The end result puts the entity name just above the crosshair for 5 seconds when the player right-clicks the entity.

This is better than nothing, but it's obviously not ideal. I'd rather have the HUD text follow the entity for five seconds, or permanently, if that wouldn't impact performance too much. Any ideas?

*edit: spelling correction.*
 

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

Re: Post your modding questions here

by Hybrid Dog » Sat Jan 10, 2015 18:58

LonelyCrow wrote:Any Idea on how to access the World Directory? Sorry, I am rather new to modifying software and the lingo for that matter.

http://dev.minetest.net/minetest.get_worldpath
 

CWz
Member
 
Posts: 185
Joined: Tue Dec 24, 2013 17:01

Re: Post your modding questions here

by CWz » Sat Jan 10, 2015 20:44

how do I modify the bucket mod to check if a player has bucket priv before dumping out it contents? or have have it check if the player own the area before it dumps it's contents.
 

User avatar
ArguablySane
Member
 
Posts: 116
Joined: Sun Oct 12, 2014 21:29

Re: Post your modding questions here

by ArguablySane » Mon Jan 12, 2015 22:04

Is it safe to use the lua functions math.randomseed(seed) and math.random() to generate random numbers for each chunk during mapgen? I don't want it to behave differently on different computers.

Also, does anyone know of an elegant way to divide the world into Voroni cells (or similar) during mapgen? Subdividing any given chunk requires knowledge of the random points in adjacent chunks, but I see no way to get the random seed for adjacent chunks.
The above post and any ideas expressed therein are released to the public domain under a Creative Commons CC0 license.
 

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 Jan 13, 2015 01:09

ArguablySane wrote:Is it safe to use the lua functions math.randomseed(seed) and math.random() to generate random numbers for each chunk during mapgen? I don't want it to behave differently on different computers.

`math.random` is a straightforward interface to C's stdlib `random` function. I'm not sure if every C lib out there uses the same algorithm. Minetest's `PseudoRandom` class is the same across all supported systems (albeit with some limitations), so you should probably use it to be sure.
ArguablySane wrote:Also, does anyone know of an elegant way to divide the world into Voroni cells (or similar) during mapgen? Subdividing any given chunk requires knowledge of the random points in adjacent chunks, but I see no way to get the random seed for adjacent chunks.

I recall someone making such a mapgen. Paramat could help you there.
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
Kalabasa
Member
 
Posts: 34
Joined: Tue Jan 06, 2015 17:36
GitHub: Kalabasa
IRC: Kalabasa
In-game: Kalabasa

Re: Post your modding questions here

by Kalabasa » Thu Jan 15, 2015 18:02

Is there any way to change the length of a day? Change the speed of time of day.
insert signature here
 

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

Re: Post your modding questions here

by Hybrid Dog » Thu Jan 15, 2015 18:42

kaeza wrote:
ArguablySane wrote:Is it safe to use the lua functions math.randomseed(seed) and math.random() to generate random numbers for each chunk during mapgen? I don't want it to behave differently on different computers.

`math.random` is a straightforward interface to C's stdlib `random` function. I'm not sure if every C lib out there uses the same algorithm. Minetest's `PseudoRandom` class is the same across all supported systems (albeit with some limitations), so you should probably use it to be sure.

And math.random is about 6 times faster than PseudoRandom, isn't it?

Kalabasa wrote:Is there any way to change the length of a day? Change the speed of time of day.

https://github.com/minetest/minetest/bl ... ample#L376
there are settings to configure it
 

User avatar
Don
Member
 
Posts: 1641
Joined: Sat May 17, 2014 18:40
GitHub: DonBatman
IRC: Batman
In-game: Batman

Re: Post your modding questions here

by Don » Thu Jan 15, 2015 19:32

Kalabasa wrote:Is there any way to change the length of a day? Change the speed of time of day.

Server commands are the easy way to change time. Go down to world manipulation.http://wiki.minetest.com/wiki/Server_commands
Many of my mods are now a part of Minetest-mods. A place where you know they are maintained!

A list of my mods can be found here
 

User avatar
ArguablySane
Member
 
Posts: 116
Joined: Sun Oct 12, 2014 21:29

Re: Post your modding questions here

by ArguablySane » Mon Jan 19, 2015 00:12

Regarding ABMs, is there any way to detect if a node is near the edge of the active region of the map? I'm trying to create more dynamic trees, but when the trunk lies just outside the active region the active leaves stop receiving their keep-alive messages and die. I could put the code to check if the tree is still intact in the leaf node ABMs, but that seems very inefficient since there are maybe 80 leaf nodes but only 1 root node per tree.

Regarding metadata, does it get erased if I use minetest.set_node to replace a node with a different one?
The above post and any ideas expressed therein are released to the public domain under a Creative Commons CC0 license.
 

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 » Mon Jan 19, 2015 05:19

ArguablySane wrote:Regarding ABMs, is there any way to detect if a node is near the edge of the active region of the map? I'm trying to create more dynamic trees, but when the trunk lies just outside the active region the active leaves stop receiving their keep-alive messages and die. I could put the code to check if the tree is still intact in the leaf node ABMs, but that seems very inefficient since there are maybe 80 leaf nodes but only 1 root node per tree.

I'd suggest taking "ignore" (the name of the "unexisting node", i.e. parts of the map not loaded yet) as if it were part of the trunk. That way if the leaves are just on the border of the active map, they will take the unloaded map as if it were a tree.

ArguablySane wrote:Regarding metadata, does it get erased if I use minetest.set_node to replace a node with a different one?

Yes. You should use `minetest.swap_node` in that case.
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
Merlin
Member
 
Posts: 63
Joined: Tue Dec 09, 2014 22:07
GitHub: sct-0
In-game: my

Re: Post your modding questions here

by Merlin » Tue Jan 20, 2015 07:13

What is a mesh node?

People name it everywhere, but I cannot find a definition of it(at least not one which seems to have anything to do with Minetest).
 

PreviousNext

Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron