[SOLVED]get pointed player

Post Reply
User avatar
1faco
Member
Posts: 84
Joined: Tue Sep 08, 2020 20:32
GitHub: minefaco
In-game: faco

[SOLVED]get pointed player

by 1faco » Post

i got this code for a tool

Code: Select all

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.

User avatar
AspireMint
Member
Posts: 415
Joined: Mon Jul 09, 2012 12:59
GitHub: AspireMint
IRC: AspireMint
In-game: AspireMint
Location: Stuck at spawn

Re: get pointed player

by AspireMint » Post

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.

User avatar
Blockhead
Member
Posts: 1602
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: get pointed player

by Blockhead » Post

pointed_thing only 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.

Code: Select all

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 
})  

/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

User avatar
1faco
Member
Posts: 84
Joined: Tue Sep 08, 2020 20:32
GitHub: minefaco
In-game: faco

Re: get pointed player

by 1faco » Post

Blockhead wrote:
Thu Dec 02, 2021 03:58
pointed_thing only 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.

Code: Select all

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests