Hi GraPhix .. I am not sure you can do it the wauy you started..
but here is one way .. there are probably 1000 ways...
I have done 2 scripts... one for the light models and one for the timer switch...
Light model script... light_on_off.lua
--
-- light_on_off.lua
-- by J_C
--
-- attach to each light entity named "light_on" or "light_off"
--
-- important --
-- set the "light_off" models to physics = OFF
-- because if both on and off models have physics set = ON
-- then they will be forced apart and will spoil the illusion
-- of a single model.
-- our global light switch var that controls the light models
-- this var is set by the "light_timer_switch.lua" script
g_my_light_switch = 0
-- declare local var array to hold all entity light names
-- remember they must be named "light_on" or "light_off"
local myname = {}
-- you can change the names here if needed
local chkname_on = "light_on"
local chkname_off = "light_off"
function light_on_off_init_name(e, name)
-- get and keep the entities name
myname[e] = name
end
function light_on_off_main(e)
if g_my_light_switch == 1 then
if myname[e] == chkname_on then
Show(e)
elseif myname[e] == chkname_off then
Hide(e)
end
else
if myname[e] == chkname_on then
Hide(e)
elseif myname[e] == chkname_off then
Show(e)
end
end
end
timer switch script... light_timer_switch.lua
--
-- light_timer_switch.lua
-- by J_C
--
-- attach to flower/barrel
-- any background non static entity - set to always active
--
-- global var that can be seen by light_on_off script
g_my_light_switch = 0
-- change to any value you want
-- remember 1 sec = 1000 ticks
-- set time delay to 5 secs
local my_wait_time = 5000
function light_timer_switch_init_(e)
-- set the timer to zero
StartTimer(e)
end
function light_timer_switch_main(e)
-- check timer elapsed
if GetTimer(e) >= my_wait_time then
if g_my_light_switch == 0 then
g_my_light_switch = 1
else
g_my_light_switch = 0
end
-- reset the timer to zero
StartTimer(e)
end
end