Post your modding questions here

Robsoie
Member
 
Posts: 98
Joined: Fri Apr 29, 2016 16:22

Re: Post your modding questions here

by Robsoie » Tue May 02, 2017 10:29

I'm not lua competent at all, but for fun i've been trying to remove all water from some worlds.

After looking around i found people saying to use
Code: Select all
minetest.register_alias("mapgen_water_source", "air")
minetest.register_alias("default:water_source", "air")

in a mod to have all the water replaced by air.

So i tried , in a folder i named "nowater", i had made the following file
init.lua
Code: Select all
local path = minetest.get_modpath("nowater")
dofile(path .. "/aliases.lua")


aliases.lua
Code: Select all
minetest.register_alias("mapgen_water_source", "air")
minetest.register_alias("default:water_source", "air")


depends.txt
Code: Select all
default


and mod.conf
Code: Select all
name = nowater


But when i enable it, nothing happens and the only trace i see in the log :
2017-05-02 11:53:32: WARNING[Main]: Not registering alias, item with same name is already defined: mapgen_water_source -> air
2017-05-02 11:53:32: WARNING[Main]: Not registering alias, item with same name is already defined: default:water_source -> air


So without having any idea of why it does not work, help please ?
 

User avatar
burli
Member
 
Posts: 1641
Joined: Fri Apr 10, 2015 13:18

Re: Post your modding questions here

by burli » Tue May 02, 2017 14:12

kaeza wrote:
sofar wrote:local my_data = minetest.get_mod_storage()

then use it like it's a `meta`:

my_data.set_string("foo", "bar")
s = my_data.get_string("foo")

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

Just a minor correction: it should be `my_data:blah(...)` (note the colon instead of a period).


I have a question about mod storage: Will data be loaded on demand or is everything loaded to memory when Minetest starts?
 

User avatar
Casimir
Member
 
Posts: 1163
Joined: Fri Aug 03, 2012 16:59
GitHub: CasimirKaPazi

Re: Post your modding questions here

by Casimir » Tue May 02, 2017 17:22

Robsoie wrote:So without having any idea of why it does not work, help please ?

You depend on default. But in default the mapgen nodes already get aliased to normal nodes. You would need to load your mod before default (don't know if there is a nice way to do this). Easiest would be to just edit the files in default.

Edit: Or you could try minetest.register_alias_force
 

Robsoie
Member
 
Posts: 98
Joined: Fri Apr 29, 2016 16:22

Re: Post your modding questions here

by Robsoie » Tue May 02, 2017 23:20

Thank you very much !
The minetest.register_alias_force works great !

Before :
Image

After enabling the mod with :
Code: Select all
minetest.register_alias_force("mapgen_water_source", "air")
minetest.register_alias_force("default:water_source", "air")

Image
More places to explore now :D
(edit : though it's better to enable the mod before visiting the world for the first time as in the already generated underwater areas will have the dark shadows of the water surface on the ground, while newly generated underwater without water will not be affected by the shadow problem),

(edit 2 , looks like i had to use
Code: Select all
minetest.register_alias_force("default:ice", "air")

too, as the ice sheets in icy biomes seems to require water to not transform into the infinitively high pillars of ice blocks i saw.
 

User avatar
DS-minetest
Member
 
Posts: 1112
Joined: Thu Jun 19, 2014 19:49
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.
GitHub: DS-Minetest
In-game: DS

Re: Post your modding questions here

by DS-minetest » Wed May 03, 2017 12:30

@Robsoie: There's a setting called "water_level".
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

Robsoie
Member
 
Posts: 98
Joined: Fri Apr 29, 2016 16:22

Re: Post your modding questions here

by Robsoie » Wed May 03, 2017 19:23

I didn't knew this, thanks i guess i just learn something everyday with minetest :)
 

User avatar
pandaro
Member
 
Posts: 320
Joined: Sun Jan 08, 2012 21:34
Location: behind
GitHub: pandaro

Re: Post your modding questions here

by pandaro » Thu May 04, 2017 19:09

I'm trying to overwrite the function
Code: Select all
on use = function(itemstack, user, pointed_thing)
of the hand of the players.
Is possible?
i have try to do this in several manner inside a new mod:
1 through:
Code: Select all
minetest.override_item("", {
   on_use = function(itemstack, user, pointed_thing)
      print(tostring('hello'))
   end
})

2 through:
Code: Select all
local hand = minetest.registered_items[""]
hand.on_use = 'ciao'
print(dump(hand))
hand.on_use = function(itemstack, user, pointed_thing)
      print(tostring('hello'))
   end

3 through:
Code: Select all
minetest.register_item(":", {
   type = "none",
   wield_image = "wieldhand.png",
   wield_scale = {x=1,y=1,z=2.5},
   tool_capabilities = {
      full_punch_interval = 1.0,
      max_drop_level = 0,
      groupcaps = {
         fleshy = {times={[2]=2.00, [3]=1.00}, uses=0, maxlevel=1},
         crumbly = {times={[2]=3.00, [3]=0.70}, uses=0, maxlevel=1},
         snappy = {times={[3]=0.40}, uses=0, maxlevel=1},
         oddly_breakable_by_hand = {times={[1]=7.00,[2]=4.00,[3]=1.40}, uses=0, maxlevel=3},
      }
   },
   on_use = function(itemstack, user, pointed_thing)
      print(tostring('hello'))   
   end,
})

but no one of this attempts work.
The only way that work is modify the hand definition inside:
Code: Select all
/minetest/games/minimal/mods/default/init.lua

if here i add the function
Code: Select all
on_use = function(itemstack, user, pointed_thing)
      print(tostring('hello'))
   end
it work.
There is a way to do what i want to do? What am I doing wrong?
 

User avatar
RealGoldenHart
Member
 
Posts: 57
Joined: Fri Dec 23, 2016 23:27
Location: My office.
IRC: GoldenHart
In-game: GoldenHart

Re: Post your modding questions here

by RealGoldenHart » Fri May 05, 2017 05:15

Another noob question from me, as I'm just getting into modding.

I have 2 food items, and upon eating the food, the player gets jump or speed boost for a certain amount of time, depending on the food. I know that crystal boots had the following code in groups, but that required the player to wear the armor for the boosts to take effect(physics_speed=1,physics_jump=0.5,). How would I set it up so that the player eats the food and gets the boost for a certain amount of time.


I am worried the answer will be very simple. Bear with my stupidity :/
K. I'm bored with signatures.
 

User avatar
Lone_Wolf
Member
 
Posts: 2186
Joined: Sun Apr 09, 2017 05:50
Location: Hopefully very far from yours, snoop :P
GitHub: LoneWolfHT
IRC: Lone_Wolf
In-game: Lone_Wolf

Re: Post your modding questions here

by Lone_Wolf » Fri May 05, 2017 05:54

RealGoldenHart wrote:Another noob question from me, as I'm just getting into modding.

I have 2 food items, and upon eating the food, the player gets jump or speed boost for a certain amount of time, depending on the food. I know that crystal boots had the following code in groups, but that required the player to wear the armor for the boosts to take effect(physics_speed=1,physics_jump=0.5,). How would I set it up so that the player eats the food and gets the boost for a certain amount of time.


I am worried the answer will be very simple. Bear with my stupidity :/

Mine's worse, Maybe edit the textures of potions? Then make them placeable?
 

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

Re: Post your modding questions here

by orwell » Fri May 05, 2017 12:33

RealGoldenHart wrote:Another noob question from me, as I'm just getting into modding.

I have 2 food items, and upon eating the food, the player gets jump or speed boost for a certain amount of time, depending on the food. I know that crystal boots had the following code in groups, but that required the player to wear the armor for the boosts to take effect(physics_speed=1,physics_jump=0.5,). How would I set it up so that the player eats the food and gets the boost for a certain amount of time.


I am worried the answer will be very simple. Bear with my stupidity :/

It's indeed not that simple. The group values in the armor definition are handled by the 3d armor mod internally.
you probably have this in your item definition:
Code: Select all
on_use=minetest.item_eat(2),

you need to execute an additional action on eating the item, like:
Code: Select all
on_use=function(itemstack, user, pointed_thing)
  minetest.do_item_eat(2, nil, itemstack, user, pointed_thing)
  ...action-here...
end,

I would suggest you to depend on the playereffects mod and add an effect using its api.
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

User avatar
Casimir
Member
 
Posts: 1163
Joined: Fri Aug 03, 2012 16:59
GitHub: CasimirKaPazi

Re: Post your modding questions here

by Casimir » Fri May 05, 2017 15:37

Does someone know how fast set_attribute and get_attribute are? Would it be better if I load them in local variables when used a lot?

@ pandaro
As far as I remember there once was an issue about overriding the hand in the minetest issue tracker. But I haven't found it on the fly.
 

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 » Sat May 06, 2017 02:08

Casimir wrote:Does someone know how fast set_attribute and get_attribute are? Would it be better if I load them in local variables when used a lot?


Very, very fast. For most operations you should directly use them. I would maybe not use these if you're running code that loops over all players every server tick, but even that should be any noticeable impact on the server load.

Casimir wrote:@ pandaro
As far as I remember there once was an issue about overriding the hand in the minetest issue tracker. But I haven't found it on the fly.


There's a patch in minetest-dev that actually makes this work OK now.
 

User avatar
Lone_Wolf
Member
 
Posts: 2186
Joined: Sun Apr 09, 2017 05:50
Location: Hopefully very far from yours, snoop :P
GitHub: LoneWolfHT
IRC: Lone_Wolf
In-game: Lone_Wolf

Re: Post your modding questions here

by Lone_Wolf » Sat May 06, 2017 04:55

RealGoldenHart wrote:Another noob question from me, as I'm just getting into modding.

I have 2 food items, and upon eating the food, the player gets jump or speed boost for a certain amount of time, depending on the food. I know that crystal boots had the following code in groups, but that required the player to wear the armor for the boosts to take effect(physics_speed=1,physics_jump=0.5,). How would I set it up so that the player eats the food and gets the boost for a certain amount of time.


I am worried the answer will be very simple. Bear with my stupidity :/

Maybe edit/combine the sprinting mod a little?
 

User avatar
Casimir
Member
 
Posts: 1163
Joined: Fri Aug 03, 2012 16:59
GitHub: CasimirKaPazi

Re: Post your modding questions here

by Casimir » Sat May 06, 2017 13:12

sofar wrote:
Casimir wrote:I would maybe not use these if you're running code that loops over all players every server tick,

Exactly this. It's for a hunger mod. But I can move it behind the other checks and be okay with it for now. Thanks for the answer.
 

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 » Sat May 06, 2017 20:20

So, in the bucket mod that comes with the default minetest game, when you use a bucket full of water or lava you are left with an empty bucket. How do I code this? I'm making a small morefood mod and I want to know how to eat the contents of the bowl but leave the empty bowl afterwards.
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
pandaro
Member
 
Posts: 320
Joined: Sun Jan 08, 2012 21:34
Location: behind
GitHub: pandaro

Re: Post your modding questions here

by pandaro » Sat May 06, 2017 20:57

sofar wrote:
Casimir wrote:@ pandaro
As far as I remember there once was an issue about overriding the hand in the minetest issue tracker. But I haven't found it on the fly.


There's a patch in minetest-dev that actually makes this work OK now.


thanks for infos, i will try to update it at last dev version and check soon.
EDIT:
just installed last unstable dev:
it seems not work, i need to know something about how to use it? Which of the methods I exhibited is correct to use?
 

User avatar
Lone_Wolf
Member
 
Posts: 2186
Joined: Sun Apr 09, 2017 05:50
Location: Hopefully very far from yours, snoop :P
GitHub: LoneWolfHT
IRC: Lone_Wolf
In-game: Lone_Wolf

Re: Post your modding questions here

by Lone_Wolf » Fri May 12, 2017 21:02

I can't mine mese blocks with the rainbow pick? I've tried a few things but have gotten no results. What does the 'cracky' section do?
Code: Select all
minetest.register_tool("nyancats_plus:rainbow_pick",{
   description = "Rainbow Pickaxe",
   inventory_image = "rainbow_pick.png",
   tool_capabilities = {
      full_punch_interval = 0.5,
      max_drop_level=10,
      groupcaps={
         cracky = {times={[1]=1.0, [2]=0.7, [3]

=0.25}, uses=0},
      },
      damage_groups = {fleshy=20},
   },

(I have 0.5% knowledge of lua)
EDIT The mod was modified a little...
 

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 » Sat May 13, 2017 14:42

how to get the position of a player if i have his name?

EDIT: neverming, i was actually refering to a string instead of an OBJref...
 

User avatar
yzelast
Member
 
Posts: 54
Joined: Sun Oct 02, 2016 01:18
Location: Far Far Away
GitHub: yzelast
In-game: yzelast

Re: Post your modding questions here

by yzelast » Sat May 13, 2017 19:53

Hey guys, just some small questions:

I'm planning to create a sickle to destroy leaves in an area but after reading the wiki and the api, i still do not understand how the wear parameter works.

And in my tests, the nodes are being instantly destroyed, if someone could tell me how to dig the nodes in the right way i would be glad.

Code: Select all
minetest.register_tool("real_trees:test", {
   description = "test",
   inventory_image = "example2.png",

   on_use = function(itemstack, player, pointed_thing)
   local pos = minetest.get_pointed_thing_position(pointed_thing)
      if pos == nil then return end

   local pmin = {x = pos.x - 1, y = pos.y - 1, z = pos.z - 1}
   local pmax = {x = pos.x + 1, y = pos.y + 1, z = pos.z + 1}
   local area = minetest.find_nodes_in_area(pmin,pmax,"default:leaves")
      for key,value in pairs(area) do
         minetest.set_node(value,{name = "air"})
         minetest.add_item(value,{name = "default:leaves"})
         itemstack:add_wear(256)
      end
      return itemstack
   end
})
G84mU6AQ9dKaNhxn6dq8P5C0y5r8NssE
 

Byakuren
Member
 
Posts: 816
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

Re: Post your modding questions here

by Byakuren » Sat May 13, 2017 23:16

yzelast wrote:Hey guys, just some small questions:

I'm planning to create a sickle to destroy leaves in an area but after reading the wiki and the api, i still do not understand how the wear parameter works.

And in my tests, the nodes are being instantly destroyed, if someone could tell me how to dig the nodes in the right way i would be glad.

Code: Select all
minetest.register_tool("real_trees:test", {
   description = "test",
   inventory_image = "example2.png",

   on_use = function(itemstack, player, pointed_thing)
   local pos = minetest.get_pointed_thing_position(pointed_thing)
      if pos == nil then return end

   local pmin = {x = pos.x - 1, y = pos.y - 1, z = pos.z - 1}
   local pmax = {x = pos.x + 1, y = pos.y + 1, z = pos.z + 1}
   local area = minetest.find_nodes_in_area(pmin,pmax,"default:leaves")
      for key,value in pairs(area) do
         minetest.set_node(value,{name = "air"})
         minetest.add_item(value,{name = "default:leaves"})
         itemstack:add_wear(256)
      end
      return itemstack
   end
})


Instead of on_use, you could use minetest.register_on_dignode and check if the digger is holding a sickle. There is no dig callback for items.
Every time a mod API is left undocumented, a koala dies.
 

dawgdoc
Member
 
Posts: 246
Joined: Mon Feb 27, 2017 01:10
GitHub: dawgdoc

Re: Post your modding questions here

by dawgdoc » Sun May 14, 2017 02:38

yzelast wrote:Hey guys, just some small questions:

I'm planning to create a sickle to destroy leaves in an area but after reading the wiki and the api, i still do not understand how the wear parameter works.

And in my tests, the nodes are being instantly destroyed, if someone could tell me how to dig the nodes in the right way i would be glad.

Nathan.S has a sickle in his Survival Sub-Game. You may be able to find some useful information there. (When used on grass the sickle leaves cut grass on top of the dirt/grass node.)
 

FaceDeer
Member
 
Posts: 351
Joined: Sat Aug 29, 2015 19:01
GitHub: FaceDeer

Re: Post your modding questions here

by FaceDeer » Sun May 14, 2017 05:12

I'm working on a new crafting system mod. It takes an input inventory filled with raw materials, populates an output inventory with all possible itemstacks that could be crafted from those inputs, and the player picks what output he'd like to craft by taking an item from the output inventory and dropping it into his own inventory.

This is quite straightforward to do when using a crafting table to access this system, I just use the various on_metadata_inventory_* callbacks for the node to detect when the player's moving items between various inventories and apply the crafting rules at that point. However, I'd like to add an option to replace the player's "native" crafting system with this approach and I'm missing a few key pieces.

I can see how to fiddle with a player's formspec and the player's inventory layout, but I need the equivalent of the player's on_metadata_inventory_move method to detect when a player is moving stuff between their inventories. register_on_craft doesn't look like it does what I need, it seems firmly wedded to the existing grid-based crafting system. register_on_player_receive_fields is able to handle button presses in the player inventory formspec but it doesn't appear to be triggered by inventory movement.

Anyone know if what I want to do is even possible? I've never seen a mod that tampers with the default 3*3 crafting grid and recipe system like this before.
 

User avatar
Casimir
Member
 
Posts: 1163
Joined: Fri Aug 03, 2012 16:59
GitHub: CasimirKaPazi

Re: Post your modding questions here

by Casimir » Sun May 14, 2017 20:19

Maybe a bug in the engine, or maybe I'm just stupid and someone can point me to my mistake: player:get_attributes returns a number as string.

In my drowning mod. Remove "tonumber" and uncomment the print. This will cause this error:
Code: Select all
    h_breath 0, typestring
    2017-05-14 22:13:47: ERROR[Main]: ServerError: AsyncErr: environment_Step: Runtime error from mod '' in callback environment_Step(): ...minetest/bin/../games/Voxelgarden/mods/drowning/init.lua:183: attempt to compare number with string


In my hunger mod, which works similar, there is no problem.

I'm kind of confused.
 

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

Re: Post your modding questions here

by orwell » Mon May 15, 2017 13:44

This is because the type of player attributes is always "string", you can't save other type's values there
When setting the atttribute, the value is implicitly converted to a string
Fortunately, for Lua, the expression "1" is equal to 1 when doing maths, so "1"+"1" will result in 2
(as well as 1..2 results in "12")

EDIT: I won't comment what you wrote on PHP.
Last edited by orwell on Mon May 15, 2017 20:56, edited 1 time in total.
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

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 » Mon May 15, 2017 15:32

not sure if it is a modding question, but... why no one thought using this:
Code: Select all
collision_removal = true,

in particle definition? It's so useful!
 

PreviousNext

Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 6 guests