Scripts / Player Looking At Entity?

Author
Message
Teabone
Forum Support
17
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 12th Dec 2017 04:51
Is there no command for if the player is looking at an entity? In FPSC I recall there being more than one command for this. One for if the entity is within view of the player and another for if the players cross hairs are on the entity.

I know we have a command for if the entity is viewing the player but I'm wondering if Lee made the reverse? I took a look at some of the existing code but its not 100% functional. For example like picking up keys and etc the degrees are a bit off. Additionally they add to many statements that I wish could all be replaced with a single command.

Is there such a thing in GG?
Twitter - Teabone3 | Youtube - Teabone3 | Twitch - Teabone3 | TGC Assets - Store Link | Patreon - Teabone3

i7 -2600 CPU @ 3.40GHz - Windows 7 - 8GB RAM - Nivida GeForce GTX 960
Pirate Myke
Forum Support
13
Years of Service
Recently Online
Joined: 31st May 2010
Location: El Dorado, California
Posted: 12th Dec 2017 07:02
Not yet. But smallg made a function for such a thing.
https://forum.game-guru.com/outbound?url=https%3A%2F%2Fforum.game-guru.com%2Fthread%2F207801%3Fpage%3D7%23msg2515459
Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz, 2400 Mhz, 4 Core(s), 4 Logical Processor(s), 8gb RAM, Nvidia gtx660, Windows 7 Pro 64bit, Screen resolution 1680 x 1050.

AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 12th Dec 2017 08:50
I have many different 'looking at' functions for different occasions, for example the hidden object script uses the ray casting command to identify which entity is under the cross hair.

It is best to tailor the function to get exactly the behaviour you require, you may just want to detect if the object is within the players field of view or whether it is within a narrower view cone first then do a final check to see if the entity is actually visible by using ray casting, I doubt if Lee could come up with a single internal function to cater for all cases.

I'm toying with the idea of putting a collection of my more generic functions in a standalone Lua module, if there is enough interest from you guys I'm sure we could get Lee to include it in the GG base build.
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 12th Dec 2017 09:36
@amen definitely sounds like a great idea to me.
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Pirate Myke
Forum Support
13
Years of Service
Recently Online
Joined: 31st May 2010
Location: El Dorado, California
Posted: 14th Dec 2017 01:55
I am interested.
Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz, 2400 Mhz, 4 Core(s), 4 Logical Processor(s), 8gb RAM, Nvidia gtx660, Windows 7 Pro 64bit, Screen resolution 1680 x 1050.

AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 14th Dec 2017 08:51
Ok, I'll put together a list of what I consider 'generic' functions that I have dotted around, ones I use a lot and are stand-alone and add them to this thread, if you all agree that the list is sensible I'll package them together as a Lua module (similar to the quaternion library) and we can try to persuade Lee to include it in the base set.


Been there, done that, got all the T-Shirts!
PM
Bolt Action Gaming
GameGuru Tool Maker
10
Years of Service
User Offline
Joined: 24th Oct 2013
Location: Harrisburg, PA (USA)
Posted: 15th Dec 2017 18:21
Alternately Amen, you could just put it on the GG store as a free /cheap script.
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 15th Dec 2017 19:13 Edited at: 15th Dec 2017 21:17
Ok so here is my first stab at a utilities module.

I've included a script with 6 examples of use, I picked really simple examples for now but the functions are quite flexible and I'm sure people will find many other uses.

Here is video of the examples script in action, to try it out yourself just attach the utils_examples.lua script to an entity, export it and make 5 more copies of it. (utillib.lua just lives in scriptbank alongside quatlib.lua)



It follows the same basic structure as the quatlib and, although it may look a bit strange, is the recommended way of writing modules (according to Lua's creator).

If anyone has any requests for similar generic functions, or extensions to the ones I've included, they think they need speak up and I'll see what I can do about adding them.

I will make sure any future scripts I produce use this module and will endeavour to re-write previous ones as time permits.

(edited to add updated lib with more comments in)
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 15th Dec 2017 19:44 Edited at: 15th Dec 2017 19:46
nice
what does
local U = {_G = _G}
do?
i've never seen anything inside the {} before, is that a quick way to make a double array/list or something?

what's the difference between
function U.PlayerLookingAtObj( obj, dist, ignore )
&
function U.PlayerLookingAt( e, dist, ignore )
they seem the same to me?
from what i can tell U.ObjectPlayerLookingAt( e, dist, ignore ) will return 1 or nil (the default ray casting returns), but the 2 above seem to give the same result (either nil or the ID of the object being looked at)? (sorry i haven't actually tried them out, just browsing your code)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 15th Dec 2017 20:20
As I'm creating a new environment for the module so it doesn't pollute the global environment but also need access to the player position globals the _G = _G just creates a way for me to access the global namespace from within the module, hence the local functions inside the module environment that reference _G.g_PlayerPosX etc.

Accessing tables and functions in the global space is simply done by making locals to access them before creating the new environment.

The ray casting functions return the object identifier of the 'collision' with the ray, the terrain version probably returns 1 or 0.

The diifference between the functions is that the first returns true if the object specified is being looked at whereas the second uses the entity id. Currently the first is not as useful as we don't have any commands to get information about non-active objects all we can see is that they are there but I have the feeling Lee is intending to expand on that so in future it may become a lot more useful.

I've been pestering him off and on to give us a way to get the size and shape of an object and maybe its name directly regardless of whether it is active or not, hopefully he will do so at some point.

btw, all my functions either return true/false or position/offset values, I probably should explicitly state which in the function headers.

Take a look at the examples script to see how easy they are to use.
Been there, done that, got all the T-Shirts!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 15th Dec 2017 21:51 Edited at: 15th Dec 2017 23:48
Right so I've trawled through my back catalogue and there are literally thousands of functions but there is no way I can shove them all in a single general purpose library, to be fair the vast majority of them are not really that generic so I need feedback from you guys on the set currently in the library, i.e. is that a useful enough set for now or have I missed something obvious? Would a generic entity counting function be useful for example, or how about a function to return a list of entities in order of distance from the player (or from a specified point) .

I did have a lot of AI specific functions but then Lee did his re-write and I'm not sure whether they are all still valid anymore.

I only want to include generic routines btw, nothing that only works with specific entities or rely on other modules/scripts being present other than the base set Lee delivers (and even then I try to avoid them if possible because he may change them at any time).

Edited:

I've added the 'list entities in order of distance one' as I was using that in quite a few places, it ignores any entity with no 'health' so should be useful for finding surviving enemies for example.

Word of warning, I've run out of simple functions, this latest one and probably any that follow will make your head spin unless you are really proficient in Lua.

With this function in place you don't really need a 'count entities' one as well, just call this one and use the size of the returned list as the count.

Edited:

New version, 'near' routine now includes x angle check. (found a newer version in my pickuppable script)
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
PCS
7
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 17th Dec 2017 11:12
can just say wow, these scripts make my brain come loose and then fly away. hahaha.
Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 4GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 17th Dec 2017 12:32
Don't worry too much about how they work just concentrate on how to use them, the examples script should be easy enough to understand.
Been there, done that, got all the T-Shirts!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 19th Dec 2017 09:05
Well I was expecting a little more feedback.

Been there, done that, got all the T-Shirts!
PM
Pink Panther
14
Years of Service
User Offline
Joined: 1st Feb 2010
Location:
Posted: 21st Dec 2017 18:58
These are great! I am so new to scripting and trying hard to learn. Thank you for your time and generosity !
PM

Login to post a reply

Server time is: 2024-04-25 01:20:41
Your offset time is: 2024-04-25 01:20:41