-- LUA Script - precede every function and global member with lowercase name of script + '_main' -- smallg script which will damage the player if he doesn't finish the level before a certain time limit -- DESCRIPTION: [TIMELIMIT=300] (time until player takes damage (in seconds)) -- DESCRIPTION: [DAMAGE=1] (how much damage to do per second if time limit is reached) -- DESCRIPTION: (i.e. to kill the player set a very high value) -- DESCRIPTION: [SHOWTIMER!=1] (show the remaining time on screen?) -- DESCRIPTION: (Colour of the text when time is ok) -- DESCRIPTION: [TIMERNORMALRED=255] -- DESCRIPTION: [TIMERNORMALGREEN=255] -- DESCRIPTION: [TIMERNORMALBLUE=255] -- DESCRIPTION: [FLASHBELOW=25] (timer will flash when below % of time remaining) -- DESCRIPTION: [FLASHSPEED=4] (how quickly the text will flash (higher = faster)) -- DESCRIPTION: (Colour of the text when time is low) -- DESCRIPTION: [TIMERLOWRED=255] -- DESCRIPTION: [TIMERLOWGREEN=0] -- DESCRIPTION: [TIMERLOWBLUE=0] -- DESCRIPTION: [TIMERX=50] (x position of the timer text) -- DESCRIPTION: [TIMERY=1] (y position of the timer text) -- DESCRIPTION: [TIMERSIZE=5] (size of the timer text) local timer1 = nil local timer2 = nil local timer3 = nil local lowtime = nil local damagetick = false g_escape_timer = {} local flash_dir = "ON" function escape_timer_properties(e, timelimit, damage, showtimer, timernormalred, timernormalgreen, timernormalblue, flashbelow, flashspeed, timerlowred, timerlowgreen, timerlowblue, timerx, timery, timersize) local et = g_escape_timer[e] et.timelimit = timelimit et.damage = damage et.showtimer = showtimer et.timernormalred = timernormalred et.timernormalgreen = timernormalgreen et.timernormalblue = timernormalblue et.flashbelow = flashbelow et.flashspeed = flashspeed et.timerlowred = timerlowred et.timerlowgreen = timerlowgreen et.timerlowblue = timerlowblue et.timerx = timerx et.timery = timery et.timersize = timersize end function escape_timer_init(e) g_escape_timer[e] = {} local et = g_escape_timer[e] et.timelimit = 300 et.damage = 100 et.showtimer = 1 et.timernormalred = 255 et.timernormalgreen = 255 et.timernormalblue = 255 et.flashbelow = 25 et.flashspeed = 4 et.timerlowred = 255 et.timerlowgreen = 255 et.timerlowblue = 255 et.timerx = 50 et.timery = 1 et.timersize = 5 end function escape_timer_main(e) local function round(num, numDecimalPlaces) local mult = 10^(numDecimalPlaces or 0) return math.floor(num * mult + 0.5) / mult end local function SecondsToClock(seconds) local seconds = tonumber(seconds) if seconds <= 0 then return "00:00:00"; else hours = string.format("%02.f", math.floor(seconds/3600)); mins = string.format("%02.f", math.floor(seconds/60 - (hours*60))); secs = string.format("%02.f", math.floor(seconds - hours*3600 - mins *60)); return hours..":"..mins..":"..secs end end local et = g_escape_timer[e] if timer1 == nil then timer1 = g_Time + (et.timelimit*1000) timer3 = g_Time + (1000/et.flashspeed) timer2 = g_Time+1000 lowtime = (et.timelimit*1000)*(et.flashbelow/100) end local timeremaining = timer1 - g_Time if timeremaining <= 0 then timeremaining = 0 if damagetick == false then HurtPlayer(e,et.damage) damagetick = true end if g_Time > timer2 then timer2 = g_Time+1000 damagetick = false end end if et.showtimer == 1 then local timetoshow = SecondsToClock(timeremaining/1000) if timeremaining > lowtime then TextCenterOnXColor(et.timerx, et.timery, et.timersize, timetoshow, et.timernormalred, et.timernormalgreen, et.timernormalblue) else if flash_dir == "ON" then TextCenterOnXColor(et.timerx, et.timery, et.timersize, timetoshow, et.timerlowred, et.timerlowgreen, et.timerlowblue) if g_Time > timer3 then timer3 = g_Time+(1000/et.flashspeed) flash_dir = "OFF" end else --need to show blank text cos there's a bug with text not being removed TextCenterOnXColor(et.timerx, et.timery, et.timersize, " ", et.timerlowred, et.timerlowgreen, et.timerlowblue) if g_Time > timer3 then timer3 = g_Time+(1000/et.flashspeed) flash_dir = "ON" end end end end --Prompt(flash_dir) end