Post your modding questions here
- PilzAdam
- Member
- Posts: 4026
- Joined: Fri Jul 20, 2012 16:19
- GitHub: PilzAdam
- IRC: PilzAdam
- Location: Germany
1244 wrote:In which way I can get itemstack which player hold in hand?
Code: Select all
player:get_wielded_item()
- kaeza
- Moderator
- Posts: 2162
- Joined: Thu Oct 18, 2012 05:00
- GitHub: kaeza
- IRC: kaeza diemartin blaaaaargh
- In-game: kaeza
- Location: Montevideo, Uruguay
- Contact:
One way would be to override the node's on_metadata_inventory_put callback.12Me21 wrote:How do you make it so if there is a certain item in a node's formspec, something will happen?
Example: if you put a music disk in a chest it will play a sound
See here.
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
Check out my stuff! | Donations greatly appreciated! PayPal
- 12Me21
- Member
- Posts: 873
- Joined: Tue Mar 05, 2013 00:36
- GitHub: 12Me21
- Location: (Ignore all of my posts before 2018)
So I would dokaeza wrote:One way would be to override the node's on_metadata_inventory_put callback.12Me21 wrote:How do you make it so if there is a certain item in a node's formspec, something will happen?
Example: if you put a music disk in a chest it will play a sound
See here.
Code: Select all
on_metadata_inventory_put = function(pos, listname, index, stack, player),
if stack == "music:disk" then
minetest.sound_play("song.ogg", {gain = 0.5, max_hear_distance = 25})
end
Shoutouts to Simpleflips
- PilzAdam
- Member
- Posts: 4026
- Joined: Fri Jul 20, 2012 16:19
- GitHub: PilzAdam
- IRC: PilzAdam
- Location: Germany
1.) There is a Lua syntax error12Me21 wrote:So I would dokaeza wrote:One way would be to override the node's on_metadata_inventory_put callback.12Me21 wrote:How do you make it so if there is a certain item in a node's formspec, something will happen?
Example: if you put a music disk in a chest it will play a sound
See here.(I've never done anything with formspecs, so this is probably completely wrong)Code: Select all
on_metadata_inventory_put = function(pos, listname, index, stack, player), if stack == "music:disk" then minetest.sound_play("song.ogg", {gain = 0.5, max_hear_distance = 25}) end
2.) Fix your indentation.
3.) This sound will be played locationless
4.) "stack" is a object of the type ItemStack (see lua-api.txt).
- 12Me21
- Member
- Posts: 873
- Joined: Tue Mar 05, 2013 00:36
- GitHub: 12Me21
- Location: (Ignore all of my posts before 2018)
how about this?
EDIT: I tried it and it still won't work. It says:
Code: Select all
on_metadata_inventory_put = function(pos, node, listname, index, stack, player)
if inv:contains_item("music:disk") then
minetest.sound_play("music.ogg", {gain = 0.5, max_hear_distance = 25})
end
end,
Code: Select all
18:09:37: ERROR[main]: ServerError: LuaError: error: ...netest-0.4.6\bin\..\mods\minetest\music\init.lua:37: attempt to index global 'inv' (a nil value)
18:09:37: ERROR[main]: stack traceback:
18:09:37: ERROR[main]: InventoryMenu: The selected inventory location "nodemeta:-449,3,467" doesn't exist
In trans_func.
Access violation at 5474754F write?=8 address=1416918351
18:09:37: ERROR[main]: Some exception: "Access violation"
In trans_func.
Access violation at 00EB1AF8 write?=8 address=15407864
18:09:37: ERROR[main]: ERROR: An unhandled exception occurred: Access violation
Last edited by 12Me21 on Thu May 09, 2013 22:22, edited 1 time in total.
Shoutouts to Simpleflips
- 12Me21
- Member
- Posts: 873
- Joined: Tue Mar 05, 2013 00:36
- GitHub: 12Me21
- Location: (Ignore all of my posts before 2018)
1.) "I've never done anything with formspecs, so this is probably completely wrong"PilzAdam wrote:1.) There is a Lua syntax error12Me21 wrote:So I would dokaeza wrote: One way would be to override the node's on_metadata_inventory_put callback.
See here.(I've never done anything with formspecs, so this is probably completely wrong)Code: Select all
on_metadata_inventory_put = function(pos, listname, index, stack, player), if stack == "music:disk" then minetest.sound_play("song.ogg", {gain = 0.5, max_hear_distance = 25}) end
2.) Fix your indentation.
3.) This sound will be played locationless
4.) "stack" is a object of the type ItemStack (see lua-api.txt).
2.) I'll fix that if the mod ever works
3.) I'll fix that if the mod ever works
4.) ok
Last edited by 12Me21 on Sat May 11, 2013 23:26, edited 1 time in total.
Shoutouts to Simpleflips
My partner 12Me21 and I don't know a lot about this type of coding. Can you guide us with more details?
What syntax error, what is the proper indentation?
Thanks,
What syntax error, what is the proper indentation?
Thanks,
PilzAdam wrote:1.) There is a Lua syntax error12Me21 wrote:So I would dokaeza wrote: One way would be to override the node's on_metadata_inventory_put callback.
See here.(I've never done anything with formspecs, so this is probably completely wrong)Code: Select all
on_metadata_inventory_put = function(pos, listname, index, stack, player), if stack == "music:disk" then minetest.sound_play("song.ogg", {gain = 0.5, max_hear_distance = 25}) end
2.) Fix your indentation.
3.) This sound will be played locationless
4.) "stack" is a object of the type ItemStack (see lua-api.txt).
- PilzAdam
- Member
- Posts: 4026
- Joined: Fri Jul 20, 2012 16:19
- GitHub: PilzAdam
- IRC: PilzAdam
- Location: Germany
For proper indentation read a tutorial about coding (the language doesnt matter).12Me22 wrote:My partner 12Me21 and I don't know a lot about this type of coding. Can you guide us with more details?
What syntax error, what is the proper indentation?
Thanks,
PilzAdam wrote:1.) There is a Lua syntax error12Me21 wrote: So I would do(I've never done anything with formspecs, so this is probably completely wrong)Code: Select all
on_metadata_inventory_put = function(pos, listname, index, stack, player), if stack == "music:disk" then minetest.sound_play("song.ogg", {gain = 0.5, max_hear_distance = 25}) end
2.) Fix your indentation.
3.) This sound will be played locationless
4.) "stack" is a object of the type ItemStack (see lua-api.txt).
There are several syntax errors, here is the fixed code.
Code: Select all
on_metadata_inventory_put = function(pos, listname, index, stack, player)
if stack == "music:disk" then
minetest.sound_play("song.ogg", {gain = 0.5, max_hear_distance = 25})
end
end,
Code: Select all
on_metadata_inventory_put = function(pos, listname, index, stack, player)
if stack == "music:disk" then
minetest.sound_play("song.ogg", {gain = 0.5, max_hear_distance = 25, pos=pos})
end
end,
To get the name of a ItemStack, use get_name():
Code: Select all
on_metadata_inventory_put = function(pos, listname, index, stack, player)
if stack:get_name() == "music:disk" then
minetest.sound_play("song.ogg", {gain = 0.5, max_hear_distance = 25, pos=pos})
end
end,
- Dan Duncombe
- Member
- Posts: 904
- Joined: Thu May 09, 2013 21:11
- Location: In the unknown depths of Earth
I would strongly recommend using the free downloadable Notepad++ designed for coding, however if you don't want to do that you can use Window's Wordpad text editor, if you want to save a file as LUA in wordpad, you need to call it (name of file) .lua
ArcticStorm wrote:question: what program do you recommend to make a mod with?
reason: I wanna try to make mods.
more info: i'm using windows 7.
Last edited by Dan Duncombe on Mon May 13, 2013 19:06, edited 1 time in total.
Some Mods: Castles Prefab Camouflage
My Games: Nostalgia Realtest Revamped
Servers: See above games.
My Games: Nostalgia Realtest Revamped
Servers: See above games.
- Calinou
- Moderator
- Posts: 3169
- Joined: Mon Aug 01, 2011 14:26
- GitHub: Calinou
- IRC: Calinou
- In-game: Calinou
- Location: Troyes, France
- Contact:
+1, it's a pretty good editor for Windows, it's also very fast to start.Dan Duncombe wrote:I would strongly recommend using the free downloadable Notepad++ designed for coding
Don't do that. No, really, you'll regret it. 8)Dan Duncombe wrote:however if you don't want to do that you can use Window's Wordpad text editor, if you want to save a file as LUA in wordpad, you need to call it (name of file)
- Dan Duncombe
- Member
- Posts: 904
- Joined: Thu May 09, 2013 21:11
- Location: In the unknown depths of Earth
I'm doing a mod (the Metal Light mod) and I want to implement a coal fueling feature.Basically, what I want is for the node which is the metallight:lighton to be replaced after 20 min with metallight:lightoff. I know how to do this, but, I was wondering, how do you make it restart by right-clicking it with coal, changing it back to a metallight:lighton and removing 1 coal from your inventory. This whole process needs to loop so so you can refuel it infinite times.
Some Mods: Castles Prefab Camouflage
My Games: Nostalgia Realtest Revamped
Servers: See above games.
My Games: Nostalgia Realtest Revamped
Servers: See above games.
- Dan Duncombe
- Member
- Posts: 904
- Joined: Thu May 09, 2013 21:11
- Location: In the unknown depths of Earth
Is there any way to make a block heal any player within a 20 block radius? The block name is 'decoblock:eyestone_active'.
Some Mods: Castles Prefab Camouflage
My Games: Nostalgia Realtest Revamped
Servers: See above games.
My Games: Nostalgia Realtest Revamped
Servers: See above games.
Yes, it is. UseDan Duncombe wrote:Is there any way to make a block heal any player within a 20 block radius? The block name is 'decoblock:eyestone_active'.
Code: Select all
get_objects_inside_radius(pos, radius)
and
Code: Select all
set_hp(hp)
- Evergreen
- Member
- Posts: 2135
- Joined: Sun Jan 06, 2013 01:22
- GitHub: 4Evergreen4
- IRC: EvergreenTree
- In-game: Evergreen
- Location: A forest in the midwest
- Contact:
- kaeza
- Moderator
- Posts: 2162
- Joined: Thu Oct 18, 2012 05:00
- GitHub: kaeza
- IRC: kaeza diemartin blaaaaargh
- In-game: kaeza
- Location: Montevideo, Uruguay
- Contact:
Can you post the code?1244 wrote:I have problem with rightclick event in register node. This function working ok if I don't hold shift("sneak"). When I hold shift function isn't working. Why?
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
Check out my stuff! | Donations greatly appreciated! PayPal
- PilzAdam
- Member
- Posts: 4026
- Joined: Fri Jul 20, 2012 16:19
- GitHub: PilzAdam
- IRC: PilzAdam
- Location: Germany
Not calling on_rightclick() when holding shift is a feature. This way you can place nodes when pointing at chests etc.1244 wrote:I have problem with rightclick event in register node. This function working ok if I don't hold shift("sneak"). When I hold shift function isn't working. Why?
Last edited by PilzAdam on Thu May 16, 2013 14:45, edited 1 time in total.
Who is online
Users browsing this forum: No registered users and 6 guests