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).
-- an example to show how to make a variable to track the state of Show(e) and Hide(e)
-- scripted by perelect. 13.01.2016
-- any object with this script assigned to it will be controlled by the global variable item_group_one, all at the same time.
-- In this example item_group_one is a global variable. This variable can be set from any script.
-- global variables
item_group_one = 0 -- this is a global variable that is accessible by all scripts, created in this script and set to zero.
item_group_two = 0 -- this is a global variable that is accessible by all scripts, created in this script and set to zero.
item_visibility = {} -- this is now an array.
-- local variables
local onetime = 0 -- this is a 'local' variable that only works within this script. the word 'local' at the start defines it as a local.
local PlayerDist
function collectable_2_init(e)
item_visibility[e] = 0 -- This sets the initial value of the variable to zero and binds it to the entity e that has this script.
end
function collectable_2_main(e)
PlayerDist = GetPlayerDistance(e)
-- every time you use Show(e) or Hide(e) use a variable to track it.
-- So here item_group_one is zero so it will hide the object.
-- You can set the value of item_group_one from any other script, because it is a global variable
if item_group_one == 0 then
Hide(e) -- every time you set Hide(e) set thee item_visibility as well, to track its state.
CollisionOff(e) -- when you hide an object turn collision off, if needed
item_visibility[e] = 0 -- you can use this variable to check if the item is visible. 0 is hidden.
onetime = 0
end
-- So here item_group_one is one so it will show the object.
if item_group_one == 1 then
Show(e) -- every time you set Show(e) set thee item_visibility as well, to track its state.
CollisionOn(e) -- when you show an object turn collision on.
item_visibility[e] = 1 -- you can use this variable to check if the item is visible. 1 is visible.
end
-- This is just an example of how you would use the item_visibility.
-- if the item is visible it plays a sound
if item_visibility[e] == 1 then
if onetime == 0 then
PlaySound(e,0)
onetime = 1
end
else
-- this is an if, then, else case
-- the item is not visible. ie: item_visibility = 0
-- this section is the same as using...
-- if item_visibility[e] == 0 then
-- do nothing
-- end
end
if PlayerDist < 100 and g_Entity[e]['collected'] == 0 then
Prompt("Press E to pick up item")
if g_KeyPressE == 1 then
PromptDuration("Item collected",2000)
PlaySound(e,0)
Collected(e)
ActivateIfUsed(e)
Destroy(e)
item_visibility[e] = 0
end
end
--Prompt(item_group_one.." : "..g_Entity[e]['activated'])
end
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)