get luaentity name

juli
Member
 
Posts: 203
Joined: Sat Jun 11, 2016 10:31
GitHub: cpdef
In-game: juli

get luaentity name

by juli » Fri Apr 07, 2017 06:03

How can i get the name of an luaentity from pointed_thing?
For example if i click with a item on an fish, it sends the name of the fish as a chat message.

i know the method LuaEntitySAO.get_entity_name() but this is Deprecated ...
 

User avatar
kaeza
Moderator
 
Posts: 2162
Joined: Thu Oct 18, 2012 05:00
Location: Montevideo, Uruguay
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: get luaentity name

by kaeza » Fri Apr 07, 2017 06:21

You can get the "name" of an object with `object:get_luaentity().name`.

You can check if a pointed thing is for an object by checking its `type`, and then get the object with the `ref` field:

Code: Select all
if pointed_thing.type == "object" then
  local obj = pointed_thing.ref
  local name = obj:get_luaentity().name
  -- do something here
end
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal
 

juli
Member
 
Posts: 203
Joined: Sat Jun 11, 2016 10:31
GitHub: cpdef
In-game: juli
 


Return to Modding Discussion



Who is online

Users browsing this forum: texmex and 1 guest