How do I get a playername and then send them items
-
- Member
- Posts: 117
- Joined: Sat May 28, 2022 00:04
How do I get a playername and then send them items
I want to create a on_rightclick function on a block that gives items. I can do it for each playername, but I want to get the name of the one who righclicked on the block and pass in their name into a /giveme command. Please help. Whoever finds solution will be credited on my project. Thanks and God bless.
God bless you.
List of releases:
Minetest Zombies Minigame - viewtopic.php?f=9&t=28442&p=412633#p412633
- > cdb_1d60e1a03f83
List of releases:
Minetest Zombies Minigame - viewtopic.php?f=9&t=28442&p=412633#p412633
- > cdb_1d60e1a03f83
Re: How do I get a playername and then send them items
To get his name you want something like:
And then pass it to whatever function you've made. Or you could simply just do:
although that will fail silently if his inventory is full. You can expand it to
To drop it at node's pos if they don't have room.
Code: Select all
local plname = clicker:get_player_name()
Code: Select all
local inv = clicker:get_inventory()
inv:add_item("main", "tech:torch 10")
Code: Select all
local inv = clicker:get_inventory()
if inv:room_for_item("main", "tech:torch 10") then
inv:add_item("main", "tech:torch 10")
else
minetest.drop("tech:torch 10", clicker, pos)
end
To drop it at node's pos if they don't have room.
Lead dev of Exile, git repo: https://codeberg.org/Mantar/Exile
-
- Member
- Posts: 117
- Joined: Sat May 28, 2022 00:04
Re: How do I get a playername and then send them items
Thank you. I will test this tomorrow. I think I can use if itemstack:item_fits("default:stone") it will check. Thanks. I am going to use something that blockhead showed me to do by passing in a com and for giveme with some code. I will try that with your solution and let you knos if kt works. Thanks and God bless.
God bless you.
List of releases:
Minetest Zombies Minigame - viewtopic.php?f=9&t=28442&p=412633#p412633
- > cdb_1d60e1a03f83
List of releases:
Minetest Zombies Minigame - viewtopic.php?f=9&t=28442&p=412633#p412633
- > cdb_1d60e1a03f83
-
- Member
- Posts: 117
- Joined: Sat May 28, 2022 00:04
Re: How do I get a playername and then send them items
I tested the code and it works. Thanks for showing me this, it will help with the project I am working kn very much!
God bless you.
List of releases:
Minetest Zombies Minigame - viewtopic.php?f=9&t=28442&p=412633#p412633
- > cdb_1d60e1a03f83
List of releases:
Minetest Zombies Minigame - viewtopic.php?f=9&t=28442&p=412633#p412633
- > cdb_1d60e1a03f83
Re: How do I get a playername and then send them items
You're welcome! Have a skim over lua_api.txt in the minetest docs folder, it's full of valuable info on things you can do.
Lead dev of Exile, git repo: https://codeberg.org/Mantar/Exile
Who is online
Users browsing this forum: Bing [Bot] and 2 guests