on_rightclick...

User avatar
philipbenr
Member
 
Posts: 1665
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: WisdomFire or philipbenr

on_rightclick...

by philipbenr » Mon Jul 15, 2013 02:17

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!
"The Foot is down!"
 

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

by PilzAdam » Mon Jul 15, 2013 11:33

What have you tried? Look at the doors mod in default, it uses on_rightclick() (although its a bit more complicated there).
 

User avatar
webdesigner97
Member
 
Posts: 1307
Joined: Mon Jul 30, 2012 19:16
GitHub: webD97
IRC: webdesigner97
In-game: webdesigner97

by webdesigner97 » Mon Jul 15, 2013 13:16

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.
 

User avatar
philipbenr
Member
 
Posts: 1665
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: WisdomFire or philipbenr

by philipbenr » Mon Jul 15, 2013 17:28

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. :^/
"The Foot is down!"
 

User avatar
webdesigner97
Member
 
Posts: 1307
Joined: Mon Jul 30, 2012 19:16
GitHub: webD97
IRC: webdesigner97
In-game: webdesigner97

by webdesigner97 » Mon Jul 15, 2013 18:23

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
 

User avatar
philipbenr
Member
 
Posts: 1665
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: WisdomFire or philipbenr

by philipbenr » Mon Jul 15, 2013 18:44

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},
    }
})

"The Foot is down!"
 

User avatar
webdesigner97
Member
 
Posts: 1307
Joined: Mon Jul 30, 2012 19:16
GitHub: webD97
IRC: webdesigner97
In-game: webdesigner97

by webdesigner97 » Mon Jul 15, 2013 18:51

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 ;)
 

User avatar
philipbenr
Member
 
Posts: 1665
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: WisdomFire or philipbenr

by philipbenr » Mon Jul 15, 2013 21:06

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...
"The Foot is down!"
 

User avatar
Mossmanikin
Member
 
Posts: 599
Joined: Sun May 19, 2013 16:26

by Mossmanikin » Tue Jul 16, 2013 02:15

Looks like you forgot a comma after "end" (both).

Noob 4 life!
My stuff
 

User avatar
philipbenr
Member
 
Posts: 1665
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: WisdomFire or philipbenr

by philipbenr » Tue Jul 16, 2013 05:27

I always screw up on commas... :(
Thanks anyhow. :)
"The Foot is down!"
 

User avatar
philipbenr
Member
 
Posts: 1665
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: WisdomFire or philipbenr

by philipbenr » Tue Jul 16, 2013 05:29

part 2 of the mod:
how can I stop/replace the sound being played from the node?
"The Foot is down!"
 

User avatar
webdesigner97
Member
 
Posts: 1307
Joined: Mon Jul 30, 2012 19:16
GitHub: webD97
IRC: webdesigner97
In-game: webdesigner97

by webdesigner97 » Tue Jul 16, 2013 05:45

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)
 

User avatar
Zeg9
Member
 
Posts: 608
Joined: Fri Sep 21, 2012 11:02

by Zeg9 » Tue Jul 16, 2013 09:08

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:")
Last edited by Zeg9 on Tue Jul 16, 2013 09:12, edited 1 time in total.
I made a few (a lot of?) mods for minetest: here is a list.
See also the MT-Faithful texture pack (work in progress).
 

User avatar
BlockMen
Member
 
Posts: 768
Joined: Fri Mar 01, 2013 17:24
GitHub: BlockMen

by BlockMen » Tue Jul 16, 2013 12:10

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
 

User avatar
philipbenr
Member
 
Posts: 1665
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: WisdomFire or philipbenr

by philipbenr » Thu Jul 18, 2013 03:49

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.
"The Foot is down!"
 

User avatar
webdesigner97
Member
 
Posts: 1307
Joined: Mon Jul 30, 2012 19:16
GitHub: webD97
IRC: webdesigner97
In-game: webdesigner97

by webdesigner97 » Thu Jul 18, 2013 08:57

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,
 

User avatar
philipbenr
Member
 
Posts: 1665
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: WisdomFire or philipbenr

by philipbenr » Thu Jul 18, 2013 19:20

so what do you think I should put? (sorry for this, I think it seems like a stupid question.)
"The Foot is down!"
 

User avatar
webdesigner97
Member
 
Posts: 1307
Joined: Mon Jul 30, 2012 19:16
GitHub: webD97
IRC: webdesigner97
In-game: webdesigner97

by webdesigner97 » Thu Jul 18, 2013 19:36

just copy & paste my code to your node :)
 

User avatar
philipbenr
Member
 
Posts: 1665
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: WisdomFire or philipbenr

by philipbenr » Fri Jul 19, 2013 04:28

I have it all, and it works. :) should I post it online?
"The Foot is down!"
 

User avatar
webdesigner97
Member
 
Posts: 1307
Joined: Mon Jul 30, 2012 19:16
GitHub: webD97
IRC: webdesigner97
In-game: webdesigner97

by webdesigner97 » Fri Jul 19, 2013 06:02

The mod? Or the code? Of course you can post your mod in "Modding general", but we won't force you ;)
 

User avatar
philipbenr
Member
 
Posts: 1665
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: WisdomFire or philipbenr

by philipbenr » Tue Jul 23, 2013 19:27

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.
"The Foot is down!"
 

User avatar
webdesigner97
Member
 
Posts: 1307
Joined: Mon Jul 30, 2012 19:16
GitHub: webD97
IRC: webdesigner97
In-game: webdesigner97

by webdesigner97 » Tue Jul 23, 2013 19:41

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
 

User avatar
philipbenr
Member
 
Posts: 1665
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: WisdomFire or philipbenr

by philipbenr » Tue Jul 23, 2013 20:27

thanks so much webdesigner I think I've got the rest. I think I'll release it under GPLv3.
"The Foot is down!"
 

User avatar
webdesigner97
Member
 
Posts: 1307
Joined: Mon Jul 30, 2012 19:16
GitHub: webD97
IRC: webdesigner97
In-game: webdesigner97

by webdesigner97 » Tue Jul 23, 2013 21:02

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 ;)
 

User avatar
philipbenr
Member
 
Posts: 1665
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: WisdomFire or philipbenr

by philipbenr » Wed Jul 24, 2013 05:59

and thank people too, like in my thanks to the developers, and all modders.
"The Foot is down!"
 

User avatar
philipbenr
Member
 
Posts: 1665
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: WisdomFire or philipbenr

by philipbenr » Fri Jul 26, 2013 05:09

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.
Last edited by philipbenr on Fri Jul 26, 2013 05:09, edited 1 time in total.
"The Foot is down!"
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 15 guests

cron