I have to ask, "What does math.huge exactly mean?" I googled it in relationship to lua but I couldn't understand the explanations given. Is it a number type such as double precision? I have found out that lua only supports seconds for the timer. Lee would need to create more resolution using 'C' which he uses for the game engine. I did notice the command 'Timer' as in 'x=Timer()' to get the time in milliseconds since the system started. I believe this is used for 'g_time'? I'm still not sure how this all works together.
I've tried various ways (mainly positioning of commands within the 'main' function to no avail. My cloudy/fuzzy brain just can't comprehend I'm afraid. For your info, this is one of the many scripts I tried.
entity_state = {}
local timeToWait = 0
function theinvokeddemon_init(e)
LoadGlobalSound ( "audiobank\\My_Audio\\Intro\\me01a.wav", 1 )
LoadGlobalSound ( "audiobank\\My_Audio\\Intro\\me02.wav", 2 )
LoadGlobalSound ( "audiobank\\My_Audio\\Intro\\me03.wav", 3 )
LoadGlobalSound ( "audiobank\\My_Audio\\Intro\\me04.wav", 4 )
LoadGlobalSound ( "audiobank\\My_Audio\\Intro\\demon5b.wav", 5 )
SetActivated(e, 1)
entity_state[e] = 0
end
function theinvokeddemon_main(e)
PlayerDist = GetPlayerDistance(e)
if PlayerDist < 75 and g_PlayerHealth > 0 then
RotateToPlayer(e)
entity_state[e] = 1
FreezePlayer()
else
entity_state[e] = 0
end
if entity_state[e] == 1 and g_Entity[e]['activated'] == 1 then
PlaySound(e,1)
timeToWait = g_Time + 2 * 1000 -- 2 seconds wait
waittime(timeToWait)
end
if entity_state[e] == 2 and g_Entity[e]['activated'] == 1 then
PlayGlobalSound ( 1 )
timeToWait = g_Time + 3 * 1000 -- 3 seconds wait
waittime(timeToWait)
end
if entity_state[e] == 3 and g_Entity[e]['activated'] == 1 then
UnfreezePlayer()
end
end
function waittime(timeToWait)
if g_Time > timeToWait then
if entity_state[e] == 1 then
entity_state[e] = 2
elseif entity_state[e] == 2 then
entity_state[e] = 3
end
end
end
When in doubt -- C4 :heh, heh, heh:
-Jamie Hyneman