Post your modding questions 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 » Sun Feb 14, 2016 03:37

can_access is a line I forgot to remove from a previous method I tried.

Your code works much better, I can't place if I don't have the priv, but when I do have the priv I get this error instead Expecting itemstack, itemstring, table or nil. item=pacmine:mini_board.

I'm probably just missing something super obvious.
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website.
 

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

Re: Post your modding questions here

by Hybrid Dog » Sun Feb 14, 2016 09:40

BrunoMine, maybe emerge_area doesn't work if pos1 is pos2, you could set pos2 to vector.add(pos1, 1)
you could also look at the emergeblocks chatcommand: https://github.com/minetest/minetest/bl ... s.lua#L476
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

Re: Post your modding questions here

by BrunoMine » Sun Feb 14, 2016 12:57

Hybrid Dog wrote:BrunoMine, maybe emerge_area doesn't work if pos1 is pos2, you could set pos2 to vector.add(pos1, 1)
you could also look at the emergeblocks chatcommand: https://github.com/minetest/minetest/bl ... s.lua#L476


I tested this command but it does not return anything (and does not generate nor loads the map).
Only
Started emerge of area ranging
 

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 » Mon Feb 15, 2016 00:07

So it turns out I was just over thinking things, this code does exactly what I want, and I've used it in other mods. :S

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
after_place_node = function(pos, placer, itemstack, pointed_thing)
      if placer and minetest.check_player_privs(placer:get_player_name(), {myarcade = true}) then
      else
         minetest.remove_node(pos)
         return true
      end
   end,
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website.
 

amadin
Member
 
Posts: 471
Joined: Tue Jun 16, 2015 16:23
GitHub: Amadin

Back empty bottles

by amadin » Mon Feb 15, 2016 18:29

I need back empty bottles after using stack of potions.
minetest.item_eat don't work for me but work itemstack:add_item, but it add new item in same slot and only if 1 other item in slot left. Begin of code:
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 potions.register_potion(iname, color, exptime, action, expaction)
    local rname = string.gsub(iname, "[-%[%]()1023456789 ]", "")
    minetest.register_craftitem(minetest.get_current_modname()..":"..rname:lower(), {
   description = iname.." Potion",
   inventory_image = "potions_bottle.png^potions_"..color..".png",

   on_use = function(itemstack, user, pointed_thing)


Will be good if you answer in PM.
 

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 Feb 16, 2016 17:51

Take a look at the bucket code in default_game, it returns an empty bucket after placing the water. You might just need a line like this,
return {name="potions:empty_bottle}
Which you could call after using the potion.
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website.
 

amadin
Member
 
Posts: 471
Joined: Tue Jun 16, 2015 16:23
GitHub: Amadin

Re: Post your modding questions here

by amadin » Wed Feb 17, 2016 12:44

Nathan.S wrote:Take a look at the bucket code in default_game, it returns an empty bucket after placing the water. You might just need a line like this,
return {name="potions:empty_bottle}
Which you could call after using the potion.

This return work only for 1 item in slot, if try to use 10 potions you get back only 1 empty bottle instead 10. In farming mod i find 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
on_use = minetest.item_eat(2, "farming:drinking_cup"),
but i can't use this string because in potions mod:
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_use = function(itemstack, user, pointed_thing)
and i don't know how insert minetest.item_eat in it.
 

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

Re: Post your modding questions here

by Hybrid Dog » Wed Feb 17, 2016 15:40

You could put it into the player's inventory:
https://github.com/Sokomine/replacer/bl ... t.lua#L218
 

amadin
Member
 
Posts: 471
Joined: Tue Jun 16, 2015 16:23
GitHub: Amadin

Re: Post your modding questions here

by amadin » Wed Feb 17, 2016 16:27

Hybrid Dog wrote:You could put it into the player's inventory:
https://github.com/Sokomine/replacer/bl ... t.lua#L218

Thank you it work right, i used search in dev.minetest.net but not find this.
 

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 Feb 17, 2016 18:25

amadin wrote:
Hybrid Dog wrote:You could put it into the player's inventory:
https://github.com/Sokomine/replacer/bl ... t.lua#L218

Thank you it work right, i used search in dev.minetest.net but not find this.


lua api.txt is a more complete source

My book also has a chapter on this
 

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

Re: Post your modding questions here

by Hybrid Dog » Sat Feb 27, 2016 11:37

Can l use the logarithm as random number generator?
Image
Attachments
2016-02-26-234513_1920x1080_scrot.png
2016-02-26-234513_1920x1080_scrot.png (102.04 KiB) Viewed 2500 times
 

User avatar
iangp
Member
 
Posts: 114
Joined: Sat May 31, 2014 19:26
GitHub: 14NGiestas
IRC: iangp
In-game: iangp

Re: Post your modding questions here

by iangp » Sat Feb 27, 2016 17:08

Hybrid Dog wrote:Can l use the logarithm as random number generator?


(Ò_Ó)
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP):
 

User avatar
xeranas
Member
 
Posts: 99
Joined: Fri Feb 05, 2016 11:06
GitHub: xeranas

Re: Post your modding questions here

by xeranas » Sat Feb 27, 2016 18:52

Hybrid Dog wrote:Can l use the logarithm as random number generator?

What's wrong with math.random(min, max)?
 

User avatar
iangp
Member
 
Posts: 114
Joined: Sat May 31, 2014 19:26
GitHub: 14NGiestas
IRC: iangp
In-game: iangp

Re: Post your modding questions here

by iangp » Sat Feb 27, 2016 19:31

strange behavior, same here on python, however Hybrid, it's a pseudo random
choose a number and then the same numbers are generated
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
i = 1000
for n in xrange(100):
    i = abs((math.log(i)*1000)%1); print i
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP):
 

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

Re: Post your modding questions here

by Hybrid Dog » Sat Feb 27, 2016 19:50

math.random also has its math.randomseed

Does using logarithm work faster than using math.random()?
 

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

by Hybrid Dog » Sat Feb 27, 2016 21:04

It looks fairly random to me. Do you also see those strange yellow rings in the picture?
Image
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 load_time_start = os.clock()

-- $ time luajit raan.lua && pnmtopng tmp.ppm > tmp.png && optipng -o7 tmp.png

local path = "./tmp.ppm"
local file = io.open(path,"w")
file:write("")
file:close()
file = io.open(path,"a")

local s = 500
file:write("P3 "..s.." "..s.." 255 ")


local i = 2

local function getcol()
   i = math.abs((math.log(i)*1000)%1)
   return math.floor(i*255+0.5)
end

for y = 1,s do
   for x = 1,s do
      file:write(getcol().." "..getcol().." "..getcol().." ")
   end
end

file:close()

local time = math.floor(tonumber(os.clock()-load_time_start)*100+0.5)/100
local msg = "fertig nach ca. "..time.."s"
if time > 0.05 then
   print(msg)
end
Attachments
tmp.png
took ca. 0.44s
tmp.png (733.08 KiB) Viewed 2500 times
 

User avatar
iangp
Member
 
Posts: 114
Joined: Sat May 31, 2014 19:26
GitHub: 14NGiestas
IRC: iangp
In-game: iangp

Re: Post your modding questions here

by iangp » Sat Feb 27, 2016 23:28

That's funny and cool
did you already searched for someone similar idea 'cause this looks really new for me :D
I also plotted (using xmgrace/grace) random points changing the initial value and seems pretty randomized
But I can't tell you if this is less cpu intensive or not, because math.log probably reaches the result through Series Expansion (using loops) and well, you know... the only way, maybe, is make a benchmark using several loops for emphasize these differences...
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP):
 

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 Feb 28, 2016 00:48

You'd hope that math Random would be optimised as a standard library function
 

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

Re: Post your modding questions here

by Hybrid Dog » Sun Feb 28, 2016 08:33

l set the size to 700 and compared them, using math.random it took ca. 0.72s
and using that logarithm function it took ca. 0.85s
sqrt works better than log, it took ca. 0.76s


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 load_time_start = os.clock()

-- $ time luajit log_rand.lua && pnmtopng tmp.ppm > tmp.png && optipng -o7 -quiet tmp.png

local path = "./tmp.ppm"
local file = io.open(path,"w")
file:write("")
file:close()
file = io.open(path,"a")

local s = 500
file:write("P3 "..s.." "..s.." 255 ")


local i = 2

local function getcol()
   i = math.abs((1000/math.sqrt(i))%1)
   return math.floor(i*255+0.5)
end

for y = 1,s do
   for x = 1,s do
      file:write(getcol().." "..getcol().." "..getcol().." ")
   end
end

file:close()

local time = math.floor(tonumber(os.clock()-load_time_start)*100+0.5)/100
local msg = "fertig nach ca. "..time.."s"
if time > 0.05 then
   print(msg)
end

Image
Attachments
tmp.png
took ca. 0.39s
tmp.png (733.08 KiB) Viewed 2499 times
 

User avatar
iangp
Member
 
Posts: 114
Joined: Sat May 31, 2014 19:26
GitHub: 14NGiestas
IRC: iangp
In-game: iangp

Re: Post your modding questions here

by iangp » Sun Feb 28, 2016 11:54

Did you closed all apps before run these scripts? If you did soooo
We have a winner!

1st > Default Random 0.72s
2nd > Sqrt Random 0.76s
3th > Log Random 0.85s
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP):
 

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

Re: Post your modding questions here

by Hybrid Dog » Sun Feb 28, 2016 13:24

math.random is not coded in lua, so the tests would need to be done in minetest source code
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

Re: Post your modding questions here

by BrunoMine » Tue Mar 01, 2016 18:46

How to catch max_stack an item? (Just knowing your ID. example: "default:tree")
I want a method to do this.
I am referring to the default value of an item can be accumulated.
 

Byakuren
Member
 
Posts: 441
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri

Re: Post your modding questions here

by Byakuren » Tue Mar 01, 2016 20:20

BrunoMine wrote:How to catch max_stack an item? (Just knowing your ID. example: "default:tree")
I want a method to do this.
I am referring to the default value of an item can be accumulated.


You can look at the item definition in the table minetest.registered_items. E.g.
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 stack_max = minetest.registered_items["default:tree"].stack_max
.

I am not sure if the definition gets the default 99 filled in if not specified in the definition. To be safe you might want to check if stack_max is nil, and use 99 if it is.
Every time a mod API is left undocumented, a koala dies.
 

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 Mar 01, 2016 21:23

It does get the default value of stack_max in the definition, it's from builtin/game/item.lua or something
 

Misadventure
New member
 
Posts: 5
Joined: Tue Mar 01, 2016 21:36
In-game: Misadventure

Dual Crafting Output?

by Misadventure » Wed Mar 02, 2016 14:32

I have a recipe that calls for:
    a tool (named forge_hammer)
    and an ingot (in this example, iron_ingot)
Trying to output : The forge hammer (with less durability) AND the plate.
The problem is, if it consumes my hammer. I have almost solved this by setting the output of the recipe to the hammer.
writing a "register on craft" function to deduct the durability. My question is, how do I write it, so that either

    A) the forge_hammer stays in the original crafting grid (while now having its updated durability deduction) allowing you to take out the plate as you normally would, then in a separate click, drag the hammer off the grid.
    or
    B) Have it so when the player clicks the plate to craft it, it immediately sends the now less-durable hammer to the inventory, while the player still is holding the plate to drag wherever they please.
 

Byakuren
Member
 
Posts: 441
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri

Re: Dual Crafting Output?

by Byakuren » Wed Mar 02, 2016 18:07

Misadventure wrote:I have a recipe that calls for:
    a tool (named forge_hammer)
    and an ingot (in this example, iron_ingot)
Trying to output : The forge hammer (with less durability) AND the plate.
The problem is, if it consumes my hammer. I have almost solved this by setting the output of the recipe to the hammer.
writing a "register on craft" function to deduct the durability. My question is, how do I write it, so that either

    A) the forge_hammer stays in the original crafting grid (while now having its updated durability deduction) allowing you to take out the plate as you normally would, then in a separate click, drag the hammer off the grid.
    or
    B) Have it so when the player clicks the plate to craft it, it immediately sends the now less-durable hammer to the inventory, while the player still is holding the plate to drag wherever they please.


the register_on_craft callbacks receive the old craft grid (from before crafting) and the inventory the craft is from. So you should be able to look at the hammer from the old craft grid and insert it back into the inventory with more wear.

You could do something similar to send the hammer to the player's inventory instead, since the callback will receive an ObjectRef to the player as another argument.
Every time a mod API is left undocumented, a koala dies.
 

User avatar
Neon
Member
 
Posts: 119
Joined: Thu Aug 15, 2013 02:03
In-game: Neon

Re: Post your modding questions here

by Neon » Thu Mar 03, 2016 23:02

I'm trying to replace a mod-specific node with a more general one, from a different mod. For some reason, I can't seem to make it work.

From home/.minetest/mods/my_mod/init.lua:
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
if minetest.get_modpath("moonrealm") then
  -- Make moonrealm soil the same as dirt
  minetest.register_alias(":moonrealm:soil", "default:dirt")
end


When I log into the server, a pre-existing expanse of moonrealm:soil is still moonrealm:soil and not default:dirt

my_mod is being loaded after the other two, in this case, because of the depends file
home/.minetest/mods/my_mod/depends.txt:
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
default
moonrealm?


Any thoughts?
 

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 » Thu Mar 03, 2016 23:13

Aliases can't be used on existing nodes, only undeclared ones.

Use an abm, I guess?
 

User avatar
Neon
Member
 
Posts: 119
Joined: Thu Aug 15, 2013 02:03
In-game: Neon

Re: Post your modding questions here

by Neon » Thu Mar 03, 2016 23:22

Well, Instead of adding another ABM, can I "overload" (to use a programming term) the function from the original mod? In effect, replace the function in the other mod with one of my own?

Additionally, the code in the above post also does not work:
- on a shiny new server (none of the moonrealm soil has ever been created, yet the alias is in the codebase)
- when the alias code is placed in the moonrealm code before the soil nodes are defined
- with the other three combinations of leading colons in the node names

I suppose I can replace the soil definition with the alias code. That's if I wanted to let edits to the moonrealm code stand, in the final server code. (as opposed to having my own mod that does all of this node editing after the mods are loaded)

EDIT: Could I unload a node definition after it's been loaded? Thus removing the node from the server?

I admit that it's not always a good idea to do, since the mapgen might be creating "unknown nodes", certain crafts might be icky, and certain ABMs might fail. That's things for the mod creator (who told the engine to unload the node) to overload with proper crafts/ABMs.
 

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

Re: Post your modding questions here

by Hybrid Dog » Fri Mar 04, 2016 16:16

If you manage to make your mod become loaded before moonrealm, you could simply override minetest.register_node,
else you could use minetest.override_node on the soil node to add an on_construct which sets dirt, but on_construct doesn't work for vmanip (and minetest.swap_node).
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.override_node("moonrealm:soil", {
   on_construct = function(pos)
      minetest.set_node(pos, {name = "default:dirt"})
   end
})

l assume you use paramat's moonrealm mod, the content id of the soil node is fetched every time it's needed for vmanip there: https://github.com/paramat/moonrealm/bl ... ctions.lua
So you could override the minetest.get_content_id 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 get_id = minetest.get_content_id
function minetest.get_content_id(name)
   if name == "moonrealm:soil" then
      name = "default:dirt"
   end
   return get_id(name)
end
 

PreviousNext

Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 34 guests

cron