Post your modding questions here

1244
Member
 
Posts: 45
Joined: Fri Jul 13, 2012 16:40
Location: Poland

by 1244 » Thu May 09, 2013 16:46

In which way I can get itemstack which player hold in hand?
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Thu May 09, 2013 16:55

1244 wrote:In which way I can get itemstack which player hold in hand?

Code: Select all
player:get_wielded_item()
 

User avatar
12Me21
Member
 
Posts: 873
Joined: Tue Mar 05, 2013 00:36
Location: (Ignore all of my posts before 2018)
GitHub: 12Me21

by 12Me21 » Thu May 09, 2013 21:19

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
Shoutouts to Simpleflips
 

User avatar
kaeza
Moderator
 
Posts: 2162
Joined: Thu Oct 18, 2012 05:00
Location: Montevideo, Uruguay
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

by kaeza » Thu May 09, 2013 21:35

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

One way would be to override the node's on_metadata_inventory_put callback.
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
 

User avatar
12Me21
Member
 
Posts: 873
Joined: Tue Mar 05, 2013 00:36
Location: (Ignore all of my posts before 2018)
GitHub: 12Me21

by 12Me21 » Thu May 09, 2013 21:52

kaeza wrote:
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

One way would be to override the node's on_metadata_inventory_put callback.
See here.

So I would do
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


(I've never done anything with formspecs, so this is probably completely wrong)
Shoutouts to Simpleflips
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Thu May 09, 2013 22:01

12Me21 wrote:
kaeza wrote:
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

One way would be to override the node's on_metadata_inventory_put callback.
See here.

So I would do
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


(I've never done anything with formspecs, so this is probably completely wrong)

1.) There is a Lua syntax error
2.) Fix your indentation.
3.) This sound will be played locationless
4.) "stack" is a object of the type ItemStack (see lua-api.txt).
 

User avatar
12Me21
Member
 
Posts: 873
Joined: Tue Mar 05, 2013 00:36
Location: (Ignore all of my posts before 2018)
GitHub: 12Me21

by 12Me21 » Thu May 09, 2013 22:09

how about this?
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,


EDIT: I tried it and it still won't work. It says:
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
 

User avatar
12Me21
Member
 
Posts: 873
Joined: Tue Mar 05, 2013 00:36
Location: (Ignore all of my posts before 2018)
GitHub: 12Me21

by 12Me21 » Thu May 09, 2013 22:24

PilzAdam wrote:
12Me21 wrote:
kaeza wrote:One way would be to override the node's on_metadata_inventory_put callback.
See here.

So I would do
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


(I've never done anything with formspecs, so this is probably completely wrong)

1.) There is a Lua syntax error
2.) Fix your indentation.
3.) This sound will be played locationless
4.) "stack" is a object of the type ItemStack (see lua-api.txt).


1.) "I've never done anything with formspecs, so this is probably completely wrong"
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
 

User avatar
12Me21
Member
 
Posts: 873
Joined: Tue Mar 05, 2013 00:36
Location: (Ignore all of my posts before 2018)
GitHub: 12Me21

by 12Me21 » Thu May 09, 2013 23:57

Someone please help!
Shoutouts to Simpleflips
 

deivan
Member
 
Posts: 452
Joined: Fri Feb 15, 2013 10:16
Location: Brazil. :D

by deivan » Fri May 10, 2013 00:15

The moving (or running) light mode have a similar code, I think. Try read the code of this mode.
The mode who make you have light in the same place of you are if you have a torch in your hand.
 

User avatar
12Me21
Member
 
Posts: 873
Joined: Tue Mar 05, 2013 00:36
Location: (Ignore all of my posts before 2018)
GitHub: 12Me21

by 12Me21 » Fri May 10, 2013 00:45

Is it possible to make entities partially transparent?
Shoutouts to Simpleflips
 

User avatar
12Me22
Member
 
Posts: 38
Joined: Fri Apr 12, 2013 21:20
Location: Earth

by 12Me22 » Fri May 10, 2013 01:14

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:
12Me21 wrote:
kaeza wrote:One way would be to override the node's on_metadata_inventory_put callback.
See here.

So I would do
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


(I've never done anything with formspecs, so this is probably completely wrong)

1.) There is a Lua syntax error
2.) Fix your indentation.
3.) This sound will be played locationless
4.) "stack" is a object of the type ItemStack (see lua-api.txt).
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Fri May 10, 2013 09:18

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:
12Me21 wrote:So I would do
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


(I've never done anything with formspecs, so this is probably completely wrong)

1.) There is a Lua syntax error
2.) Fix your indentation.
3.) This sound will be played locationless
4.) "stack" is a object of the type ItemStack (see lua-api.txt).

For proper indentation read a tutorial about coding (the language doesnt matter).
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,

To play the sound at a position, just specify the pos field in the sound parameter table, like:
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,

Note that only mono channel sound files can be played at a position. Also only ogg files are supported.
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,
 

User avatar
Dan Duncombe
Member
 
Posts: 904
Joined: Thu May 09, 2013 21:11
Location: In the unknown depths of Earth

by Dan Duncombe » Mon May 13, 2013 19:05

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.
 

User avatar
Calinou
Moderator
 
Posts: 3155
Joined: Mon Aug 01, 2011 14:26
Location: Troyes, France
GitHub: Calinou
IRC: Calinou
In-game: Calinou

by Calinou » Mon May 13, 2013 19:37

Dan Duncombe wrote:I would strongly recommend using the free downloadable Notepad++ designed for coding


+1, it's a pretty good editor for Windows, it's also very fast to start.

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)


Don't do that. No, really, you'll regret it. 8)
 

User avatar
Dan Duncombe
Member
 
Posts: 904
Joined: Thu May 09, 2013 21:11
Location: In the unknown depths of Earth

by Dan Duncombe » Mon May 13, 2013 20:29

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.
 

User avatar
Dan Duncombe
Member
 
Posts: 904
Joined: Thu May 09, 2013 21:11
Location: In the unknown depths of Earth

by Dan Duncombe » Tue May 14, 2013 16:27

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.
 

User avatar
BlockMen
Developer
 
Posts: 768
Joined: Fri Mar 01, 2013 17:24
Location: Germany
GitHub: BlockMen

by BlockMen » Tue May 14, 2013 16:45

Dan 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'.


Yes, it is. Use
Code: Select all
get_objects_inside_radius(pos, radius)
(http://dev.minetest.net/EnvRef)

and
Code: Select all
set_hp(hp)
(http://dev.minetest.net/Player)
 

User avatar
Aqua
Member
 
Posts: 641
Joined: Wed Aug 22, 2012 09:11
Location: Sydney~Singapore

by Aqua » Wed May 15, 2013 12:25

Is it possible to make a player jump higher currently?
Hi there ^.~
 

User avatar
Evergreen
Member
 
Posts: 2135
Joined: Sun Jan 06, 2013 01:22
Location: A forest in the midwest
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen

by Evergreen » Wed May 15, 2013 12:33

Aqua wrote:Is it possible to make a player jump higher currently?

I think so with the new api for the player physics override, but Idk how to do it.
Back from the dead!
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Wed May 15, 2013 12:52

Evergreen wrote:
Aqua wrote:Is it possible to make a player jump higher currently?

I think so with the new api for the player physics override, but Idk how to do it.

Its trivial with set_physics_override().
 

1244
Member
 
Posts: 45
Joined: Fri Jul 13, 2012 16:40
Location: Poland

by 1244 » Thu May 16, 2013 14:33

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?
 

User avatar
kaeza
Moderator
 
Posts: 2162
Joined: Thu Oct 18, 2012 05:00
Location: Montevideo, Uruguay
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

by kaeza » Thu May 16, 2013 14:37

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?

Can you post the code?
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
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Thu May 16, 2013 14:45

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?

Not calling on_rightclick() when holding shift is a feature. This way you can place nodes when pointing at chests etc.
Last edited by PilzAdam on Thu May 16, 2013 14:45, edited 1 time in total.
 

User avatar
jojoa1997
Member
 
Posts: 2890
Joined: Thu Dec 13, 2012 05:11
Location: Earth

by jojoa1997 » Wed May 22, 2013 14:53

Is it possible to make torches only be placed on sale and ground by leaving out the ceiling node box?
Coding;
1X coding
3X debugging
12X tweaking to be just right
 

PreviousNext

Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 1 guest