Scripts / Get an Entity's Index From its g_Entity['obj'] value

Author
Message
Nathan38
13
Years of Service
User Offline
Joined: 13th Feb 2011
Location:
Posted: 7th May 2020 23:59
Hi All,
currently experimenting with some stuff in LUA.

I want to know if theres a command or a way to get the entity's index based on its obj value, the one stored in the g_Entity global. So in the screen shot it would be something like this (I'm guessing):

g_Entity[3]['obj'] = 70003

so if I know that the value is 70003, using the ObjectPlayerLookingAt() function in AmenMoses' utillib.lua, how can I then find out what it's index is?

Basically I am trying to find out how far the current entity being looked at is away from the player, maybe something like this: g_Entity[entityID]['plrdist']

This is probably a bad/long winded solution so if anyone can offer some advice, i would very much appreciate it

Thanks
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 8th May 2020 00:05
yes, look in physlib.lua as amen added a way to do it
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Nathan38
13
Years of Service
User Offline
Joined: 13th Feb 2011
Location:
Posted: 8th May 2020 00:19
Got it, thanks smallg, its called ObjectToEntity() in case anyone is wondering
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 8th May 2020 11:57
If ObjectPlayerLookingAt() returns an object id you can use:

local rayX = GetIntersectCollisionX()
local rayY = GetIntersectCollisionY()
local rayZ = GetIntersectCollisionZ()

to get the contact point of the raycast.

That way you can calculate the distance to static entities as well.

Been there, done that, got all the T-Shirts!
PM

Login to post a reply

Server time is: 2024-12-22 02:49:50
Your offset time is: 2024-12-22 02:49:50