function to grant permisions on rightclick?

Joseph13
Member
 
Posts: 188
Joined: Tue Dec 06, 2016 05:35
In-game: Joseph

function to grant permisions on rightclick?

by Joseph13 » Fri Jul 13, 2018 17:10

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
(55.5 KiB) Not downloaded yet
I love Hobby Drones! They are awesome! Also I love FPV rc cars!!!
 

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

Re: function to grant permisions on rightclick?

by Krock » Fri Jul 13, 2018 17:23

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,
Mod Search Engine - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
 

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

Re: function to grant permisions on rightclick?

by ExeterDad » Fri Jul 13, 2018 17:28

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
 

Joseph13
Member
 
Posts: 188
Joined: Tue Dec 06, 2016 05:35
In-game: Joseph

Re: function to grant permisions on rightclick?

by Joseph13 » Sat Jul 14, 2018 18:27

Thanks ExeterDad and Krock for the replies! I will test the code in a while!
I love Hobby Drones! They are awesome! Also I love FPV rc cars!!!
 

Joseph13
Member
 
Posts: 188
Joined: Tue Dec 06, 2016 05:35
In-game: Joseph

Re: function to grant permisions on rightclick?

by Joseph13 » Sat Jul 14, 2018 19:43

Your code works great! Thanks!
I love Hobby Drones! They are awesome! Also I love FPV rc cars!!!
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 1 guest