Page 1 of 1

on_rightclick...

PostPosted: Mon Jul 15, 2013 02:17
by philipbenr
Right now, I'm working on a small mod about audio, because the radio mod doesn't work on my computer, or my version of Minetest (latest version, always). I am hoping to use the player's wield_hand to right click on of the nodes (there are eight different nodes, one of a different shade/color, and one per song.), but I just don't know how to use the "on_rightclick", even though I looked it up on the dev. wiki. I'm 14 and just starting to make mods.

Help!

PostPosted: Mon Jul 15, 2013 11:33
by PilzAdam
What have you tried? Look at the doors mod in default, it uses on_rightclick() (although its a bit more complicated there).

PostPosted: Mon Jul 15, 2013 13:16
by webdesigner97
philipbenr wrote:I'm 14 and just starting to make mods.

Your age isn't important for modding! I'm 15 and I can create nice mods (at least I think they're nice). So, let's try to solve your problem together:

You need help on "on_rightclick", so you should visit the Minetest API.

Then you look for some explanations for "on_rightclick" => Ctrl + F(ind) and type "on_rightclick" => The 4th result is what you're looking for:

on_rightclick = func(pos, node, clicker, itemstack),
^ default: nil
^ if defined, itemstack will hold clicker's wielded item
Shall return the leftover itemstack


It explains that you must set the value of "on_rightclick" as a function with the parameters:
- pos (position of clicked node => table)
- node (info about the clicked node => table)
- clicker (the player who clicked the node => ObjectRef)
- itemstack (info about the item in player's hand => ItemStack)

What you have to do now, is adding on_rightclick to your node definition:

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.register_node("",{
    description = "Test",
    (.....)
    on_rightclick = function(pos,node,clicker,itemstack)
   
    end,
})


And all needed code into his function. You should also visit Dev Wiki for more information about nodes, objectrefs etc.

PostPosted: Mon Jul 15, 2013 17:28
by philipbenr
So, If i want to use the wield_hand to right_click with, would I put

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
itemstack = {":"}


because that is what your hand is defined as in the default init.lua?
And the node as

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
node = {"mod:example_node"}


Or is that wrong?

The only reason I said I was 14 is because I'm not very experienced in programming, but I making mods, because the mod request sticky gets roughly 20% to 30% mod requests made. :^/

PostPosted: Mon Jul 15, 2013 18:23
by webdesigner97
philipbenr wrote:So, If i want to use the wield_hand to right_click with, would I put

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
itemstack = {":"}


because that is what your hand is defined as in the default init.lua?
And the node as

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
node = {"mod:example_node"}


Or is that wrong?

The only reason I said I was 14 is because I'm not very experienced in programming, but I making mods, because the mod request sticky gets roughly 20% to 30% mod requests made. :^/

I don't know the name of wieldhand. Maybe ask on IRC

PostPosted: Mon Jul 15, 2013 18:44
by philipbenr
I looked in the init.lua in default

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
-- The hand
minetest.register_item(":", {
    type = "none",
    wield_image = "wieldhand.png",
    wield_scale = {x=1,y=1,z=2.5},
    tool_capabilities = {
        full_punch_interval = 0.9,
        max_drop_level = 0,
        groupcaps = {
            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}
        },
        damage_groups = {fleshy=1},
    }
})


PostPosted: Mon Jul 15, 2013 18:51
by webdesigner97
philipbenr wrote:I looked in the init.lua in default

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
-- The hand
minetest.register_item(":", {
    type = "none",
    wield_image = "wieldhand.png",
    wield_scale = {x=1,y=1,z=2.5},
    tool_capabilities = {
        full_punch_interval = 0.9,
        max_drop_level = 0,
        groupcaps = {
            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}
        },
        damage_groups = {fleshy=1},
    }
})


Maybe you should just try it out ;)

PostPosted: Mon Jul 15, 2013 21:06
by philipbenr
well, I canceled what I was doing and ran off of the fake fire mod. It worked well enough. Take a look.
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.register_node("audio:player_red", {
    drawtype = "normal",
    tiles = {"color_player_red.png"},
    paramtype = "light",
    light_source = 6 ,
    groups = {choppy=3, oddly_breakable_by_hand=3},
    sound = Sound_Red,
    after_place_node = function (pos,placer)
        minetest.sound_play("Sound_Red",
        {pos = pos, gain = 1.0, max_hear_distance = 40,})
    end

    after_dig_node = function (pos, oldnode, oldmetadata, digger)
        minetest.sound_play("Sound_Blank",
        {pos = pos, gain = 1.0, max_hear_distance = 2,})
    end

})



The first part about
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
worked, but when I tried to use
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_dig_node
it failed on me, saying
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
13:58:55: ERROR[main]: Failed to load and run script from
13:58:55: ERROR[main]: C:\Users\robinson\Game Data\Minetest - Copy\bin\..\games\minetest_game\mods\audio\init.lua:
13:58:55: ERROR[main]: ...st - Copy\bin\..\games\minetest_game\mods\audio\init.lua:13: '}' expected (to close '{' at line 1) near 'after_dig_node'


What should I do? I'm almost 100% positive it has to do with parentheses in line 1 and 13...

PostPosted: Tue Jul 16, 2013 02:15
by Mossmanikin
Looks like you forgot a comma after "end" (both).

PostPosted: Tue Jul 16, 2013 05:27
by philipbenr
I always screw up on commas... :(
Thanks anyhow. :)

PostPosted: Tue Jul 16, 2013 05:29
by philipbenr
part 2 of the mod:
how can I stop/replace the sound being played from the node?

PostPosted: Tue Jul 16, 2013 05:45
by webdesigner97
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
sound = minetest.sound_play(....)
minetest.sound_stop(sound)

PostPosted: Tue Jul 16, 2013 09:08
by Zeg9
If anyone is still looking for the answer, the name of the hand is actually "", the ":" is used in default mod so they can override it (else, it would crash because the name of the tool doesn't start with "default:")

PostPosted: Tue Jul 16, 2013 12:10
by BlockMen
philipbenr wrote:Right now, I'm working on a small mod about audio, because the radio mod doesn't work on my computer, or my version of Minetest (latest version, always). I am hoping to use the player's wield_hand to right click on of the nodes (there are eight different nodes, one of a different shade/color, and one per song.), but I just don't know how to use the "on_rightclick", even though I looked it up on the dev. wiki. I'm 14 and just starting to make mods.

Help!



You can take a look at my Jukebox mod or just copy parts of it if you need :P

PostPosted: Thu Jul 18, 2013 03:49
by philipbenr
no, I changed it. Thanks anyway Zeg9.

So, Webdesigner, I tried implementing your stop_sound and I got 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
20:31:12: ERROR[main]: ServerError: LuaError: error: ...st - Copy\bin\..\games\minetest_game\mods\audio\init.lua:42: bad argument #1 to 'sound_stop' (number expected, got string)

well, I think it isn't stop_sound. Does anyone know what the code is for stoping a sound, or if I screwed up?

https://www.dropbox.com/s/eo4qjiuzqm71xuw/init.lua

heres the init.lua for the program as of yet.

PostPosted: Thu Jul 18, 2013 08:57
by webdesigner97
Nonono, stop_sound() doesn't want the name of the song, it wants some kind of internal ID, returned by sound_play:

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)
        mysound = minetest.sound_play("Sound_Yellow",
        {pos = pos, gain = 1.0, max_hear_distance = 40,})
    end,

    after_dig_node = function (pos, oldnode, oldmetadata, digger)
        minetest.sound_stop(mysound)
    end,

PostPosted: Thu Jul 18, 2013 19:20
by philipbenr
so what do you think I should put? (sorry for this, I think it seems like a stupid question.)

PostPosted: Thu Jul 18, 2013 19:36
by webdesigner97
just copy & paste my code to your node :)

PostPosted: Fri Jul 19, 2013 04:28
by philipbenr
I have it all, and it works. :) should I post it online?

PostPosted: Fri Jul 19, 2013 06:02
by webdesigner97
The mod? Or the code? Of course you can post your mod in "Modding general", but we won't force you ;)

PostPosted: Tue Jul 23, 2013 19:27
by philipbenr
well, I have another bug. I understand that after I logout, go back in, and dig the node, it is trying to stop playing a sound that isn't playing. It gives me a bad argument message. how can I fix this? I have a feeling it'll have to do with if's and then's.

https://www.dropbox.com/s/eo4qjiuzqm71xuw/init.lua

heres the entire init.lua itself, though it still has the bug.

PostPosted: Tue Jul 23, 2013 19:41
by webdesigner97
You have to check wheter mysound has been definded:

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 mysound then
    minetest.sound_stop(mysound)
end

PostPosted: Tue Jul 23, 2013 20:27
by philipbenr
thanks so much webdesigner I think I've got the rest. I think I'll release it under GPLv3.

PostPosted: Tue Jul 23, 2013 21:02
by webdesigner97
philipbenr wrote:thanks so much webdesigner I think I've got the rest. I think I'll release it under GPLv3.

np :) It's nice to help other people ;)

PostPosted: Wed Jul 24, 2013 05:59
by philipbenr
and thank people too, like in my thanks to the developers, and all modders.

PostPosted: Fri Jul 26, 2013 05:09
by philipbenr
one last thing. I'm going to need some music to implement. I can change the code for licenses, but I just can't find great music right now. For the default sound I hinda prefer more ambient music for the most part.