on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type == "player" then
minetest.chat_send_player(user:get_player_name(),"this player is: "..pointed_thing.ref:get_player_name)
end
end
it crash. i was searching info at modding book, github and forums but i can't find anything.
i want to show the playername from pointed player. how can i do that?
Last edited by 1faco on Thu Dec 02, 2021 22:52, edited 1 time in total.
pointed_thing.type can be "nothing" or "node" or "object". Not "player" :)
Also you are trying to concatenate string with function reference (missing parenthesis).
(edit: my 400th post, wohoo!)
Last edited by AspireMint on Thu Dec 02, 2021 03:59, edited 1 time in total.
pointed_thingonly has three types: nothing, node or object. A player is an object. So you need to first check the pointed_thing is an object, then you need to also check if that object is a player. Finally, you forgot to add the () to call get_player_name on the pointed player.
minetest.register_tool("pointtool:tool", {
on_use = function(itemstack, user, pointed_thing)
--minetest.chat_send_player(user:get_player_name(), "Pointed type: " .. tostring(pointed_thing.type))
if pointed_thing.type == "object" and minetest.is_player(pointed_thing.ref) then
--minetest.chat_send_player(user:get_player_name(), "player? " .. tostring(minetest.is_player(pointed_thing.ref)))
minetest.chat_send_player(user:get_player_name(),"this player is: "..pointed_thing.ref:get_player_name())
end
end
})
pointed_thingonly has three types: nothing, node or object. A player is an object. So you need to first check the pointed_thing is an object, then you need to also check if that object is a player. Finally, you forgot to add the () to call get_player_name on the pointed player.
minetest.register_tool("pointtool:tool", {
on_use = function(itemstack, user, pointed_thing)
--minetest.chat_send_player(user:get_player_name(), "Pointed type: " .. tostring(pointed_thing.type))
if pointed_thing.type == "object" and minetest.is_player(pointed_thing.ref) then
--minetest.chat_send_player(user:get_player_name(), "player? " .. tostring(minetest.is_player(pointed_thing.ref)))
minetest.chat_send_player(user:get_player_name(),"this player is: "..pointed_thing.ref:get_player_name())
end
end
})
Thanks u so much, easy to understand, now it works.