function to grant permisions on rightclick?

Post Reply
User avatar
Joseph16
Member
Posts: 310
Joined: Tue Dec 06, 2016 05:35
In-game: smb3

function to grant permisions on rightclick?

by Joseph16 » Post

I am making a mod for my home server that grants you privs when you right click a item. I have the item part down, but the on_use function does not work. I took some code from the flight mod that give a priv on use but it is missing something. Here is the code I use:

Code: Select all

minetest.register_craftitem("toast_machine:privs", {
description = "1",
inventory_image = "1.png",
on_use = function(player)
            local playername = player:get_player_name()
            local privs = minetest.get_player_privs(playername)
            privs.fly = true
            privs.fast = true
            minetest.set_player_privs(playername, privs)
        end,

})
but when I click the item I get this: Image
I do have the playereffects mod installed and set as a dependency. I am missing some code to define the player code. Any ideas?
Attachments
error.PNG
error.PNG (55.5 KiB) Viewed 201 times
Testin' mines since 1989

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: function to grant permisions on rightclick?

by Krock » Post

You must look at the function parameters which are given to the on_use callback. See docs: https://github.com/minetest/minetest/bl ... .txt#L5462
`user`, or in your case `player` is the 2nd argument, but your code uses argument 1, which would be the item stack.

Code: Select all

on_use = function(itemstack, player, pointed)
... code
end,
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
ExeterDad
Member
Posts: 1717
Joined: Sun Jun 01, 2014 20:00
In-game: ExeterDad
Location: New Hampshire U.S.A

Re: function to grant permisions on rightclick?

by ExeterDad » Post

Code: Select all

minetest.register_craftitem("toast_machine:privs", {
description = "1",
inventory_image = "1.png",
on_use = function(itemstack, user, pointed_thing)
            local playername = user:get_player_name()
            local privs = minetest.get_player_privs(playername)
            privs.fly = true
            privs.fast = true
            minetest.set_player_privs(playername, privs)
        end,

})
This might get ya closer. Untested of course :)

Edit: And Ninja'd by da Krock lol

User avatar
Joseph16
Member
Posts: 310
Joined: Tue Dec 06, 2016 05:35
In-game: smb3

Re: function to grant permisions on rightclick?

by Joseph16 » Post

Thanks ExeterDad and Krock for the replies! I will test the code in a while!
Testin' mines since 1989

User avatar
Joseph16
Member
Posts: 310
Joined: Tue Dec 06, 2016 05:35
In-game: smb3

Re: function to grant permisions on rightclick?

by Joseph16 » Post

Your code works great! Thanks!
Testin' mines since 1989

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests