How do I get a playername and then send them items

Post Reply
ChristienChapman
Member
Posts: 117
Joined: Sat May 28, 2022 00:04

How do I get a playername and then send them items

by ChristienChapman » Post

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

User avatar
Mantar
Member
Posts: 590
Joined: Thu Oct 05, 2017 18:46
Contact:

Re: How do I get a playername and then send them items

by Mantar » Post

To get his name you want something like:

Code: Select all

local plname = clicker:get_player_name()
And then pass it to whatever function you've made. Or you could simply just do:

Code: Select all

local inv =  clicker:get_inventory() 
 inv:add_item("main", "tech:torch 10")
although that will fail silently if his inventory is full. You can expand it to

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

ChristienChapman
Member
Posts: 117
Joined: Sat May 28, 2022 00:04

Re: How do I get a playername and then send them items

by ChristienChapman » Post

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

ChristienChapman
Member
Posts: 117
Joined: Sat May 28, 2022 00:04

Re: How do I get a playername and then send them items

by ChristienChapman » Post

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

User avatar
Mantar
Member
Posts: 590
Joined: Thu Oct 05, 2017 18:46
Contact:

Re: How do I get a playername and then send them items

by Mantar » Post

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

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 7 guests