Scripts / script for object visible or not...

Author
Message
Mariokiki
16
Years of Service
User Offline
Joined: 22nd Oct 2008
Location:
Posted: 12th Jan 2016 00:50
I look for the command that would test if an object is visible or not.

I explain the situation:

At the beginning of the level, all objects to collect are hidden.
I activate a switch object that makes visible these objects to collect.
I created a simple script in order to collect these objects (with distance detection using "PlayerDist" command) but the script detect objects to collect even if they are hidden.

I would make a condition that looks like this:
if PlayerDist <50 and g_Entity [e] ['visibility'] == 1 then (note that this command doesn't exist !)


Is a great coder like Smallg or Pirate Myke can help about that ? (or someone else ?)

THANKS !
PM
Mariokiki
16
Years of Service
User Offline
Joined: 22nd Oct 2008
Location:
Posted: 13th Jan 2016 00:01
So, I tinkered a solution to make the difference when the object is visible or not... But I'm not sure it's the best solution...

First, I set the health to a value of 20 for the hidden objects.
I set the health to a value of 50 for visible objects.
Then, in my script, I add a condition to collect the object ONLY if this one is visible with "if PlayerDist < 50 and g_Entity[e]['health'] > 25 then..."

Works fine, but it's very complicated

Is there another solution ?

Thanks !
PM
Jerry Tremble
GameGuru TGC Backer
12
Years of Service
User Offline
Joined: 5th Nov 2012
Location: Sonoran Desert
Posted: 13th Jan 2016 04:48
My scripting knowledge is very limited and I have no idea what commands are currently available, but it looks like you have a nice workaround! It also doesn't seem any more complicated than it would be if there were a
Quote: "g_Entity [e] ['visibility'] == 1 "
.
MAME Cab PC: i7 4770@3.4Ghz (passmark 9945), 12GB RAM, Win 10/64, GeForce GTX645 (passmark 1898); Shiny new laptop: i7 4800MQ@2.7Ghz (passmark 8586), 16GB RAM, Win 10/64, GeForce GTX870M (passmark 3598); Old laptop: i5@2.3Ghz, 8GB RAM, Win 7/64, Intel 3000 graphics
PM
perelect
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 13th Jan 2016 11:10 Edited at: 13th Jan 2016 12:19
Hi Mariokiki,

There is no command that tracks an object visibility, as you have already noticed.
But what you would do if you wanted to track this, is to make a variable yourself, to do this.
Everytime you set Show(e) and Hide(e) change the variable to suit, and then you track that variable.

I have attached an example script for a collectable to show you this way.
The script should show you how to do the above.
But if you need any further help, post again and I will help you out if I can.

Cheers


Desktop: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz (8 CPUs), ~3.6GHz, Windows 8.1 64-bit, 16 GB Ram, NVIDIA GeForce GTX 750 Ti, Display Memory: 4018 MB. Resolution 1360x768, Passmark 3528.
Laptop: Pavilion dv6 Notebook, Intel(R) Core(TM) i5-2410M CPU @ 2.30 GHz, Win 7 64 bit, 16 GB Ram, Radeon (TM) HD 6490M, 2336 MB Memory. Resolution 1366x768, Intel(R) HD Graphics 3000. (WEI 5.8)
Mariokiki
16
Years of Service
User Offline
Joined: 22nd Oct 2008
Location:
Posted: 13th Jan 2016 13:24
Thanks guys,

@Perelect,
Is it possible to have a variable to define the visibility of an object from another script ?

I mean, all objects not visibles are already on the level. The player can't see them for the moment...
The player meet another character who gives him a quest to do : to collect some objects (using a script of quest for exemple)
When the player accept the quest, collectables objects appears and can be collected.

My idea is to change the variable to define the visibility of collectable objects from this script.
Do you think this is difficult to do ?

It's what I did using "g_Entity[e]['health']" value for the moment... but this method is very "heavy"...

Also, how can we use the following variables for spécific object ? I tried using them without success...
g_Entity[e]['obj'] = object;
g_Entity[e]['activated'] = act;
g_Entity[e]['collected'] = col;
g_Entity[e]['haskey'] = key;
g_Entity[e]['plrinzone'] = zon;
g_Entity[e]['entityinzone'] = ezon;
g_Entity[e]['plrvisible'] = plrvis;
g_Entity[e]['frame'] = frm;
g_Entity[e]['timer'] = tmr;
g_Entity[e]['plrdist'] = pdst;
g_Entity[e]['avoid'] = avd;
g_Entity[e]['limbhit'] = lmb;
g_Entity[e]['limbhitindex'] = lmi;

Sorry if I'm long in my explanation ...
English is not my native language, and it is very difficult for me ...
THANKS !
PM
perelect
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 13th Jan 2016 17:53 Edited at: 17th Jan 2016 20:30
Quote: "Is it possible to have a variable to define the visibility of an object from another script ?"


Yes, its very easy. A new version of the above script is attached.
As with all things in scripting there are many ways to do things to get the same result. I'm trying to keep things simple and comprehendible for you and others that read this, as these examples can be applied to just about any command in GG.

This version has a new global variable, 'item_group_one' so you need to set its variable in the other script you have to control items with this script.
So if you set:

item_group_one = 0 this will hide all the objects.
item_group_one = 1 this will show all the objects.

Note: don't use the spawn at start to NO option with this example as that is a different command set not controlled by Show(e) and Hide(e).



Quote: "Also, how can we use the following variables for spécific object ? I tried using them without success..."


These are all variable's that you can read their value, some have a corresponding set command that you use in pairs. some are set in the properties settings others are set within the engine.

g_Entity[e]['obj'] = Returns the object number of an entity. Its mainly used for character ai scripts its unique for each entity its the value shown in the status bar in {} brackets, when you hover the mouse pointer over an entity in the editor. eg: {70015} its the number next to the entity number in the status bar.
g_Entity[e]['activated'] it is set by SetActivated(e,v). example in door.lua
g_Entity[e]['collected'] it is set by Collected(e). so g_Entity[e]['collected'] =0 until you call Collected(e). Then g_Entity[e]['collected'] =1. example in key.lua
g_Entity[e]['haskey'] returns a value if a key is needed to activate an entity. Used for doors. example in door.lua
g_Entity[e]['plrinzone'] returns 0 if the player is outside of a trigger zone and returns 1 if the player is inside the zone. example in plrinzone.lua
g_Entity[e]['entityinzone'] returns the entity number of an entity that is within a trigger zone. an example is here https://forum.game-guru.com/thread/214219#msg2537091
g_Entity[e]['plrvisible'] returns 1 if the entity can see that player. example in door.lua. Set by GetEntityPlayerVisibility(e)
g_Entity[e]['frame'] returns the frame number of any animation frame playing.
g_Entity[e]['timer'] returns the timer value
g_Entity[e]['plrdist'] returns the distance between the player and the entity
g_Entity[e]['avoid'] used for character ai scripts its driven from within the engine as far as I can tell. returns 1 if the ai is obstructed/collision with an object.
g_Entity[e]['limbhit'] is the name of the character bone that has been hit by bullet
g_Entity[e]['limbhitindex'] is the index number of the bone that has been hit.

I find this manual very useful.
http://steamcommunity.com/sharedfiles/filedetails/?id=398177770&insideModal=1
and I also worked out a lot from looking at the scripts that come with GG.
I started with the smaller scripts like ammo.lua, health.lua, door.lua they are easy to follow once you play with them. Then work your way up to the ai scripts like ai_soldier.lua.

There is also notes on the new commands as they are added in the changelog.txt in the GG root folder.

Cheers,
Desktop: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz (8 CPUs), ~3.6GHz, Windows 8.1 64-bit, 16 GB Ram, NVIDIA GeForce GTX 750 Ti, Display Memory: 4018 MB. Resolution 1360x768, Passmark 3528.
Laptop: Pavilion dv6 Notebook, Intel(R) Core(TM) i5-2410M CPU @ 2.30 GHz, Win 7 64 bit, 16 GB Ram, Radeon (TM) HD 6490M, 2336 MB Memory. Resolution 1366x768, Intel(R) HD Graphics 3000. (WEI 5.8)
Mariokiki
16
Years of Service
User Offline
Joined: 22nd Oct 2008
Location:
Posted: 13th Jan 2016 22:30

I have to learn more about LUA system as soon as possible if I want to progress !
I didn't now the variable used in a script can have effect in another one. I thought that was only local variable in each script.

So, we have to use variable names carrefully to not make mistakes...

I understand better the system now.
Thank-you perelect for your help !
PM
perelect
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 14th Jan 2016 03:10 Edited at: 14th Jan 2016 08:34
Quote: "So, we have to use variable names carrefully to not make mistakes..."



Yes, you have to be really aware of this with global variables. Each global variable needs to be unique so they don't interfere with one another.
So everytime you place a new script in the game you should check its globals to make sure there will be no conflicts with the existing scripts.

Lee suggested a good way to control this is to create your variables with the script name in it. like...

item_group_one, would become

collectable_2_item_group_one

This way you know which script the variable is for and where it was created.

Cheers.
Desktop: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz (8 CPUs), ~3.6GHz, Windows 8.1 64-bit, 16 GB Ram, NVIDIA GeForce GTX 750 Ti, Display Memory: 4018 MB. Resolution 1360x768, Passmark 3528.
Laptop: Pavilion dv6 Notebook, Intel(R) Core(TM) i5-2410M CPU @ 2.30 GHz, Win 7 64 bit, 16 GB Ram, Radeon (TM) HD 6490M, 2336 MB Memory. Resolution 1366x768, Intel(R) HD Graphics 3000. (WEI 5.8)
Mariokiki
16
Years of Service
User Offline
Joined: 22nd Oct 2008
Location:
Posted: 14th Jan 2016 13:49
Thanks for the tips !

PM

Login to post a reply

Server time is: 2024-12-22 12:27:44
Your offset time is: 2024-12-22 12:27:44