Scripts / Attaching a single script to multiple entities.

Author
Message
SAR1
7
Years of Service
User Offline
Joined: 9th Jun 2017
Location:
Posted: 9th Jun 2017 19:57
This problem seems to have been touched on before but despite my searches I still haven't found a working solution. Apologies in advance if this has been sorted.

My issue in a nutshell is I would like to use a single script across multiple entities to return a text response to the effect of "This cupboard is empty" when searched. Obviously I don't want to save a multitude of identical scripts with tweaked names to each entity.

The single script approach works well enough using Smallg's 'PlayerLooking' script across multiple entities to identify each entity when looking at it but when adding the 'IntersectAll' ray tracer to make sure you can't search through walls it falls apart. This seems to be because some objects report an obstruction (for instance because they are in a different room) and this is presented as a blockade of the entity right in front of the player due to script sharing.

I've tried converting the variables into an array to handle all instances of [e]: i.e. defined var = {} prior to function *_init and referenced it as var[e] in the main body but this makes no difference...

I'm stumped for now and thinking I might have to resort to one unique script per entity which feels wasteful.

Thanks for any help in advance.
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 9th Jun 2017 21:33
Could you post the script with your changes and I'll take a look at it.
Been there, done that, got all the T-Shirts!
PM
SAR1
7
Years of Service
User Offline
Joined: 9th Jun 2017
Location:
Posted: 11th Jun 2017 14:23
Thanks for the reply !

I've been trying to get to the bottom of the IntersectAll issue and think my stupidity may be the major factor ! By looking at which entity object number was causing the obstruction it appears that placing a lot of entities inside a complex EBE environment is quite tricky, e.g. putting bookcases inside alcoves. So not truely a scripting problem. Strangely some entities seem more problematic than others (perhaps due to where their hotspot is set ?).

The single script approach appears to be working okay in this context now, but I still find sharing scripts amongst entities can be quite tricky. Would it be true to say this is at least in part a limitation of lua in this environment ?

Is it possible to edit the entity activation range on the fly from a global script that monitors the player co-ords to prevent simultaneous same-script clashes ?
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 11th Jun 2017 14:53
I don't have any issues with it myself it's definitely not any limitation of Lua.

The ray casting commands are rather tricky to use and have various limitations which are not documented.

For instance if you start a ray from inside an object and ending outside the transition point is the exit from inside to outside and the object number is returned .. unless there is another object in contact with it in that direction in which case it can report that object instead .. depending in the direction of the ray! Lot's of experimentation has not helped me figure out the rules!
Been there, done that, got all the T-Shirts!
PM
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 11th Jun 2017 19:47
@ SAR1
Quote: " adding the 'IntersectAll' ray tracer to make sure you can't search through walls it falls apart"

Why simply don't try "GetEntityPlayerVisibility(e)" and "g_Entity[e]['plrvisible'] == 1" lua commands, as extra condition?

Quote: "Obviously I don't want to save a multitude of identical scripts with tweaked names to each entity."

Using arrays as you pointed above (var[e]), you can work with just 1 script, for every items.

3com
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
SAR1
7
Years of Service
User Offline
Joined: 9th Jun 2017
Location:
Posted: 13th Jun 2017 00:05
@AmenMoses: I must confess I think it is the nature of ray casting that has me a bit vexed in this case !!! I found Identical entities placed against one wall would work fine, but when rotated against a perpendicular wall often didn't ? Trial and error until it works, then don't touch it is my current approach.

@3com: GetEntityPlayerVisibility(e) and g_Entity[e]['plrvisible'] were actually my first approach but didn't work for me with an entity close to an EBE wall. That's why I moved on to ray casting. I'm actually going to try some more experimentation with this. I hadn't thought of trying it as an additional failsafe though !

The array method does seem to be the answer to the single scripting for me now the ray casting is (sort of) working.

Thanks for the help guys - as soon as I posted I knew I'd probably done something stupid, or in this case looking in the wrong place for the problem !
PM
SAR1
7
Years of Service
User Offline
Joined: 9th Jun 2017
Location:
Posted: 16th Jun 2017 16:25
Having tested the use of g_Entity[e]['plrvisible'] it seems that any entity other than an NPC doesn't seem to be able to utilise this property ? ? ? Maybe just me again though. I'm not going to go into it anymore though as it's really a bit off the main topic which has been addressed.

Thanks again.
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 16th Jun 2017 18:16
it's one of the things i have no idea what controls it to be honest but yes, only characters (and strangely doors) can use it.
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 21st Jun 2017 16:42
@ SAR1
I've tried with smallg's custom function and it works fine, a least for me.
In the vid the medkit is not intended to be grabbed, instead it gives me a prompt with the ray cast co-ords; but just when player really closest.



I've not try in ebe wall, ignore if it makes the difference.




hth

3com
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
SAR1
7
Years of Service
User Offline
Joined: 9th Jun 2017
Location:
Posted: 5th Aug 2017 23:38
@3com. Thank you for the video and code snippet ! That was very kind. All seems to be working for me now and, as is always the case - a moment of elation and then the next bug ! I don't know if this coding business is fun or just voluntary torture ?!

Many thanks again everyone for all your help.
PM

Login to post a reply

Server time is: 2024-12-23 00:35:54
Your offset time is: 2024-12-23 00:35:54