Post your modding questions here

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

Re: Post your modding questions here

by Hybrid Dog » Mon Aug 31, 2015 17:00

swordpaint12 wrote:
Hybrid Dog wrote: If they did, building roofs with slabs would become far more annoying.


Actually, that's WHY I asked. I'm trying to make a tall roof using 'walls.'

try screwdriver and the Sokomine's replacer mod (or my version which adds more than just single node mode https://github.com/HybridDog/replacer)
 

User avatar
Ben
Member
 
Posts: 157
Joined: Tue Mar 31, 2015 20:09

Re: Post your modding questions here

by Ben » Mon Aug 31, 2015 19:42

Hi, can I restrict actions on player inventories somehow? Like the allow_* callbacks on detached inventories, or the allow_metadata_inventory_* callbacks on nodes. The idea is to show the player an formspec of a player-based inventory that they can take items from, but not insert items to.
 

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 » Mon Aug 31, 2015 19:52

Ben wrote:Hi, can I restrict actions on player inventories somehow? Like the allow_* callbacks on detached inventories, or the allow_metadata_inventory_* callbacks on nodes. The idea is to show the player an formspec of a player-based inventory that they can take items from, but not insert items to.

deleted - miss read your post
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
Nathan.S
Member
 
Posts: 679
Joined: Wed Sep 24, 2014 17:47
GitHub: NathanSalapat
IRC: NathanS21
In-game: NathanS21

Re: Post your modding questions here

by Nathan.S » Tue Sep 01, 2015 01:48

Well I don't know how the inventory is being populated but you could do something like this
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
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
      if listname == 'sap' then
         if stack:get_name() == ('bucket:bucket_empty') then
            return 1
         else
            return 0
         end
      end
   end,

Of course you'd have to change the variables: sap, and bucket:bucket_empty. Maybe just change it to air or cloud. Then if a player tries to put anything in it will just get spit back at them. Unless they cheat to get clouds or air. You might even be able to use a non-existent string in place of the bucket:bucket_empty which would just return everything.
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website.
 

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 » Tue Sep 01, 2015 02:14

Untested but I think this should 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
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
      local meta = minetest.get_meta(pos)
         return 0
      end
      return count
   end,
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
Ben
Member
 
Posts: 157
Joined: Tue Mar 31, 2015 20:09

Re: Post your modding questions here

by Ben » Tue Sep 01, 2015 11:14

Thanks Nathan and Don, but those are for node inventories, right? I'm dealing with player inventories here.

Digging through mod code has not turned anything up, so far. Does anyone know where something like this has been done before?
 

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 » Tue Sep 01, 2015 11:51

@Ben - The mod "creative" in minetest_game might help.
https://github.com/minetest/minetest_ga ... e/init.lua
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
Ben
Member
 
Posts: 157
Joined: Tue Mar 31, 2015 20:09

Re: Post your modding questions here

by Ben » Wed Sep 02, 2015 19:53

Don wrote:The mod "creative" in minetest_game might help.


No, sorry. The creative inventory is a detached inventory – the same for all players. And the "craftpreview" inventory slot seems to be special-cased in the engine?

I'm beginning to feel it's not possible in the current MT?
 

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

Re: Post your modding questions here

by ArguablySane » Fri Sep 04, 2015 00:29

Does anyone know why these two methods of perlin noise generation give different results?

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 perlin_map = minetest.get_perlin_map(params, {x=sidelen, y=sidelen, z=sidelen}):get2dMap_flat({x=minp.x, y=minp.z})
local index = (x-minp.x+1) + (z-minp.z)*sidelen
return perlin_map[index]

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
return PerlinNoise(params):get2d{x=x, y=z}
The above post and any ideas expressed therein are released to the public domain under a Creative Commons CC0 license.
 

paramat
Member
 
Posts: 2662
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat

Re: Post your modding questions here

by paramat » Fri Sep 04, 2015 04:30

Try:
local index = (x - minp.x) + (z - minp.z) * sidelen
I'm not sure if the map indexes from 0 or 1.
And / or try:
return minetest.get_perlin(params):get2d{x = x, y = z}
 

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

Re: Post your modding questions here

by Hybrid Dog » Fri Sep 04, 2015 10:08

ArguablySane wrote:Does anyone know why these two methods of perlin noise generation give different results?

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 perlin_map = minetest.get_perlin_map(params, {x=sidelen, y=sidelen, z=sidelen}):get2dMap_flat({x=minp.x, y=minp.z})
local index = (x-minp.x+1) + (z-minp.z)*sidelen
return perlin_map[index]

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
return PerlinNoise(params):get2d{x=x, y=z}

maybe you need to set z to 1 to make it really flat
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 perlin_map = minetest.get_perlin_map(params, {x=sidelen, y=sidelen, z=1}):get2dMap_flat({x=minp.x, y=minp.z})
 

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

Re: Post your modding questions here

by ArguablySane » Fri Sep 04, 2015 17:25

paramat wrote:return minetest.get_perlin(params):get2d{x = x, y = z}

That worked, thanks!
It turns out that the PerlinNoise[Map] objects ignore the map seed but minetest.get_perlin[_map] includes it somehow. That discrepancy made them produce different noise.
Thanks for your suggestion too, Hybrid Dog.
The above post and any ideas expressed therein are released to the public domain under a Creative Commons CC0 license.
 

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

Re: Post your modding questions here

by Hybrid Dog » Fri Sep 04, 2015 21:40

ArguablySane wrote:
paramat wrote:return minetest.get_perlin(params):get2d{x = x, y = z}

That worked, thanks!
It turns out that the PerlinNoise[Map] objects ignore the map seed but minetest.get_perlin[_map] includes it somehow. That discrepancy made them produce different noise.
Thanks for your suggestion too, Hybrid Dog.

What happens if l use the functions somewhere outside generation, e.g. when the mods become loaded?
 

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

Re: Post your modding questions here

by ArguablySane » Sat Sep 05, 2015 10:18

Hybrid Dog wrote:
ArguablySane wrote:
paramat wrote:return minetest.get_perlin(params):get2d{x = x, y = z}

That worked, thanks!
It turns out that the PerlinNoise[Map] objects ignore the map seed but minetest.get_perlin[_map] includes it somehow. That discrepancy made them produce different noise.
Thanks for your suggestion too, Hybrid Dog.

What happens if l use the functions somewhere outside generation, e.g. when the mods become loaded?

You can't use minetest.get_perlin or minetest.get_perlin_map until the game has finished loading. If you put them in the body of your init.lua file, then they won't work. You can use them anywhere else though. They aren't restricted to being used in the on_generated callback, although that's the most obvious place to put them.

Also, I have another question: Does anyone know how to implement a version of minetest.hash_node_position(pos) which actually works to seed PcgRandom or PseudoRandom?
I've been testing the following code (part of a much larger mapgen project) and the image shows what it returns:
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 prng = PcgRandom(minetest.hash_node_position(pos) + self.seed)
minetest.chat_send_all(pos.x..","..pos.y..","..pos.z.." goes to "..prng:next())

Image
As you can see, similar values of x give the same result from the PRNG, which leads to repeating patterns on the map.

EDIT: Turns out it was a problem with adding the map seed (a very large number) to the result from minetest.hash_node_position(pos). When I removed that it started working again. I still need to figure out a good way to include the map seed though. Maybe I could just take the lower ~8 bits of it and add those. That should provide sufficient randomness.

EDIT2: Yep, that fixed it. I now only add the lower 16 bits of the map seed.
The above post and any ideas expressed therein are released to the public domain under a Creative Commons CC0 license.
 

User avatar
Ferk
Member
 
Posts: 330
Joined: Tue Aug 18, 2015 17:18
GitHub: Ferk

Re: Post your modding questions here

by Ferk » Tue Sep 08, 2015 08:28

What would be the best way for me to store all the entities of an area in a table that I can save to a file so it can later be loaded back?

I tried to serialize ``minetest.luaentities``, but it crashes the game.
{ ☠ Dungeontest ☠ , ᗧ••myarcade•• }
 

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

Re: Post your modding questions here

by Hybrid Dog » Tue Sep 08, 2015 10:12

ArguablySane wrote:EDIT: Turns out it was a problem with adding the map seed (a very large number) to the result from minetest.hash_node_position(pos). When I removed that it started working again. I still need to figure out a good way to include the map seed though. Maybe I could just take the lower ~8 bits of it and add those. That should provide sufficient randomness.

EDIT2: Yep, that fixed it. I now only add the lower 16 bits of the map seed.

l'm using this code https://github.com/HybridDog/vines/blob ... t.lua#L193, what are the disadvantages?
 

User avatar
Ferk
Member
 
Posts: 330
Joined: Tue Aug 18, 2015 17:18
GitHub: Ferk

Re: Post your modding questions here

by Ferk » Tue Sep 08, 2015 18:46

Ok after some struggle I found out what I think is the way to serialize minetest.luaentitites

It seems a bit awkward to have to pass self to the entity all the time. Maybe I'm accessing the functions the wrong way, I don't know...

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 entities = {}
      for id,entity in pairs(minetest.luaentities) do
         table.insert(entities, {
            pos = entity.object.getpos(entity.object),
            name = entity.name,
            staticdata = entity.object.get_luaentity(entity.object).get_staticdata(entity.object)
         })
      end
      local str = minetest.serialize(entities)


So, I store position, name (which according to the documentation is the identifier used in register_entity and already determines the initial_properties) and staticdata (according to the docs should hold any changes in state that are not covered already by the initial_properties).

The thing is that after doing this, I get a lot of entities with name "__builtin:item" for the items that are dropped down in the map.

I don't know if it's because they are "__builtin:*" but these items don't seem to expose any properties in the staticdata that determine what kind of item it is.

I can access some values if I directly use the entity as a table (there's for example "entity.stringitem"), but it's not clear to me how would I restore those entities when I try to deserialize the file, since minetest.add_entity(pos, "name") doesn't have enough parameters to specify this, and the only other method to change its state seems to be on_activate(self, staticdata) which requires a staticdata that is not present.

I see that there is a "minetest.add_item" function, which seems to suggest that items dropped are a special kind of entity (__builtin:item) that doesn't really follow the rules of standard entities. But even if I made an exception in the code for this entity name, I wouldn't know how to obtain the name of the item to be used in add_item. Or is it safe to assume that all items will have an "entity.stringitem" property that would always correspond to the item identifier? And are there other entities I have to add exceptions for?
{ ☠ Dungeontest ☠ , ᗧ••myarcade•• }
 

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

Re: Post your modding questions here

by ArguablySane » Tue Sep 08, 2015 20:26

Hybrid Dog wrote:l'm using this code https://github.com/HybridDog/vines/blob ... t.lua#L193, what are the disadvantages?


It will produce identical results for certain positions. For y = 0, there will be a set of points corresponding to x = -z^5 where the seed is just vine_seed, but there will be lots of other sets of identical points too. Using math.abs actually makes things worse because it doubles the number of symmetric points. You can seed the PRGN with a negative number just as effectively as with a positive number.
Also, you might want to do some testing with PseudoRandom. In my experience it gave similar results from similar seeds, but that might have been a programming error on my part. I usually use PcgRandom.

Depending on your particular use it might not matter. From looking at your code, the only thing it's going to do is make vines which appear at those symmetry points the same length, but that shouldn't be noticeable to the player.

I did notice a different possible problem though. On line 311 that PRNG is going to return the same result every time it's run. That means that 25% of rotten vines simply won't disappear no matter how long they are left. Is that the intended behaviour?
The same is true of the ABM on line 199. It will always immediately return for 25% of vines.
The above post and any ideas expressed therein are released to the public domain under a Creative Commons CC0 license.
 

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 » Tue Sep 08, 2015 23:07

How do you do a check for nodes when placing a schematic? I want to do if not air then return.
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
GunshipPenguin
Member
 
Posts: 94
Joined: Tue Jan 28, 2014 00:38
GitHub: GunshipPenguin
IRC: GunshipPenguin
In-game: GunshipPenguin

Re: Post your modding questions here

by GunshipPenguin » Wed Sep 09, 2015 00:48

I'm having trouble with a mod that utilizes minetest.after heavily.

Basically what I want to happen is this. A function is called through the use of minetest.after which does something and then uses minetest.after to call itself again sometime in the future. It will then continue to do something and call itself sometime in the future indefinitely.

Here is a very simple 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
local timerfunction
timerfunction = function()
   minetest.log("action", "timerfunction called, calling again in 5 seconds")
   minetest.after(5, timerfunction)
end

minetest.log("action", "Calling timerfunction in 5 seconds")
minetest.after(5, timerfunction)


This code calls timerfunction 5 seconds in the future through the use of minetest.after. timerfunction then logs a message, and uses minetest.after to call itself 5 seconds in the future. This cycle goes on indefinitely.

The problem is, all calls to timerfunction through minetest.after besides the first one seem to be executed after 10 seconds rather than 5 seconds. Here is the output from minetest with this mod running.

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
2015-09-08 17:32:59: ACTION[main]: Calling timerfunction in 5 seconds
2015-09-08 17:32:59: ACTION[main]:         .__               __                   __   
2015-09-08 17:32:59: ACTION[main]:   _____ |__| ____   _____/  |_  ____   _______/  |_
2015-09-08 17:32:59: ACTION[main]:  /     \|  |/    \_/ __ \   __\/ __ \ /  ___/\   __\
2015-09-08 17:32:59: ACTION[main]: |  Y Y  \  |   |  \  ___/|  | \  ___/ \___ \  |  | 
2015-09-08 17:32:59: ACTION[main]: |__|_|  /__|___|  /\___  >__|  \___  >____  > |__| 
2015-09-08 17:32:59: ACTION[main]:       \/        \/     \/          \/     \/       
2015-09-08 17:32:59: ACTION[main]: World at [/home/rhys/Desktop/minetest-0.4.13/bin/../worlds/asdf]
2015-09-08 17:32:59: ACTION[main]: Server for gameid="minetest" listening on 0.0.0.0:54258.
2015-09-08 17:32:59: ACTION[ServerThread]: singleplayer [127.0.0.1] joins game.
2015-09-08 17:32:59: ACTION[ServerThread]: singleplayer joins game. List of players: singleplayer
2015-09-08 17:33:00: ACTION[main]: Irrlicht: Could not open file of texture: character.png
2015-09-08 17:33:00: ACTION[main]: Irrlicht: Could not open file of texture: character.png
2015-09-08 17:33:04: ACTION[ServerThread]: timerfunction called, calling again in 5 seconds
2015-09-08 17:33:14: ACTION[ServerThread]: timerfunction called, calling again in 5 seconds
2015-09-08 17:33:24: ACTION[ServerThread]: timerfunction called, calling again in 5 seconds
2015-09-08 17:33:34: ACTION[ServerThread]: timerfunction called, calling again in 5 seconds
2015-09-08 17:33:44: ACTION[ServerThread]: timerfunction called, calling again in 5 seconds
2015-09-08 17:33:54: ACTION[ServerThread]: timerfunction called, calling again in 5 seconds


Notice how the first log message "Calling timerfunction in 5 seconds" appears at 17:32:59 and then the message "timerfunction called, calling again in 5 seconds" is logged at 17:33:04. These two messages are separated by 5 seconds, which makes sense, given that the call to minetest.after specified that timerfunction was to be called 5 seconds in the future.

What I don't understand however, is why all the remaining log messages are separated by 10 seconds. This presents a large problem in my mod, as the correct timing of actions is very important.

I'm pretty stumped here. Can anybody tell me why this is happening? Many thanks in advance.
 

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 » Wed Sep 09, 2015 07:16

It's possible that the messages aren't flushed immediately, but that wouldn't explain the 10 second gap.

Here is the minetest.after code: https://github.com/minetest/minetest/bl ... lua#L7-L75
 

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

Re: Post your modding questions here

by Hybrid Dog » Wed Sep 09, 2015 10:50

ArguablySane wrote:On line 311 that PRNG is going to return the same result every time it's run. That means that 25% of rotten vines simply won't disappear no matter how long they are left. Is that the intended behaviour?
The same is true of the ABM on line 199. It will always immediately return for 25% of vines.

I use PseudoRandom to reduce lag, originally it used math.random and the abms made the vines grow and die repeatedly.
 

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

Re: Post your modding questions here

by Hybrid Dog » Wed Sep 09, 2015 11:08

rubenwardy wrote:It's possible that the messages aren't flushed immediately, but that wouldn't explain the 10 second gap.

Here is the minetest.after code: https://github.com/minetest/minetest/bl ... lua#L7-L75

https://github.com/minetest/minetest/bl ... sc.lua#L18
https://github.com/minetest/minetest/bl ... sc.lua#L60
l think delay needs to be set to 0 but before a temporary copy of it needs to be set and used then for executing the function(s)

Edit: https://github.com/minetest/minetest/pull/3163/files
Last edited by Hybrid Dog on Wed Sep 09, 2015 11:56, edited 1 time in total.
 

User avatar
everamzah
Member
 
Posts: 490
Joined: Thu Jan 29, 2015 00:47
GitHub: everamzah
IRC: everamzah
In-game: everamzah

Re: Post your modding questions here

by everamzah » Wed Sep 09, 2015 11:46

How do I delete all weird characters - particularly spaces - from any text entered as param in this chat command:
+ warps
Thanks for any tips!
 

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

Re: Post your modding questions here

by Hybrid Dog » Wed Sep 09, 2015 11:58

everamzah wrote:How do I delete all weird characters - particularly spaces - from any text entered as param in this chat command:
+ warps
Thanks for any tips!

maybe param = string.trim(param)
 

User avatar
everamzah
Member
 
Posts: 490
Joined: Thu Jan 29, 2015 00:47
GitHub: everamzah
IRC: everamzah
In-game: everamzah

Re: Post your modding questions here

by everamzah » Wed Sep 09, 2015 12:55

I generally use Programming in Lua[1] which covers 5.0. Is string.trim() a 5.1 feature? Is there a good place to learn more about how to use it? Related: Is filtering for only A-Z and a-z and 0-9 better than trying to filter out anything like spaces, apostrophes, etc.?
[1] http://www.lua.org/pil
 

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 » Wed Sep 09, 2015 13:58

string.trim is Minetest-specific, documented in doc/lua_api.txt, and implemented in builtin/common/misc_helpers.lua, IIRC
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
jp
Member
 
Posts: 705
Joined: Wed Dec 18, 2013 09:03
GitHub: kilbith

Re: Post your modding questions here

by jp » Wed Sep 09, 2015 14:40

Or that :

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
param:gsub("%W", "")


(note : %W in uppercase, different from %w)
 

User avatar
everamzah
Member
 
Posts: 490
Joined: Thu Jan 29, 2015 00:47
GitHub: everamzah
IRC: everamzah
In-game: everamzah

Re: Post your modding questions here

by everamzah » Wed Sep 09, 2015 15:01

jp wrote:Or that :

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
param:gsub("%W", "")


(note : %W in uppercase, different from %w)

that seems to do the trick! thanks very much for help HybridDog, kaeza, and jp. :)
 

User avatar
Ferk
Member
 
Posts: 330
Joined: Tue Aug 18, 2015 17:18
GitHub: Ferk

Re: Post your modding questions here

by Ferk » Thu Sep 10, 2015 07:52

minetest.luaentities only holds the entities that are currently loaded.

Is there a way I can obtain all the entities of an area? ...or force an area to be loaded, along with its entities.

Alternatively: given a particular area, how can I know if all the entities inside it are loaded? this way at least I could tell apart the entities that were removed from the ones that are simply not loaded and update my data accordingly.

I could assume that the area around an entity has been completely loaded every time I find an entity. But then if a player removed all the entities from an area I won't have a way to know if it was simply not loaded.

Thanks!
{ ☠ Dungeontest ☠ , ᗧ••myarcade•• }
 

PreviousNext

Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 4 guests

cron