Remake of Speedrun Timer • speedruntimer.lua

Share and discuss custom LunaLua code and content packs for SMBX2.

Moderator: Userbase Moderators

LooKiCH
Blooper
Blooper
Posts: 159
Joined: Tue Jun 13, 2017 11:28 am
Pronouns: he/him
Contact:

Remake of Speedrun Timer • speedruntimer.lua

Postby LooKiCH » Wed Mar 29, 2023 6:45 pm

I've decided to competely rewrite the speedrun timer script, make it more optimized (including when the сamera is splitted), and also expand the timer settings. And I've also added the ability of change opacity when an NPC or a player intersects the text (turned off defaultly)
gifs: show
ImageImageImageImageImage

DOWNLOAD THIS SCRIPT 1.1

how to use: show
1) First you save the script:
• in episode/level folder (if only for episode/level)
• in "scripts" or "scripts\base" folder (if for all episodes/levels)
(you can also in subfolders, but you will need to finish writing the path)
2) Load the script in file:
• if for all episodes/levels: scripts\base\game\lunabase.lua (at the end of the file)
• if only for episode/level: luna.lua (and map.lua if for episode) (create file(s) yourself)

Code: Select all

local spt = require("speedruntimer") -- "spt": you can set any variable name
3) You can also set up the timer:
settings: show
Is ignored by system:

Code: Select all

-- any text in line
Not include these brackets with content when insert:
<> - is optional setting
** - is necessarily setting

Insert instead of
• boolean: true or false
• timerType: may be "global", "level" or "best"
• isFull: boolean (for global timer anyway)
if false: data will be cleared for only current level
if true: data will be cleared for all levels
• unitTable: "tmr.unit.*timerType*" list
• settingTable: "tmr.settings.layout.*timerType*" list
• fontPath: path to font ini file (full path or path from "scripts", "scripts\base", episode's or level's folder)
• color: {R,G,B,A} or Color
settable settings: show

Code: Select all

tmr.settings.layout.*timerType*.format = {*formatString*,value1,value2,...}
Read more here (string.format)

Code: Select all

tmr.settings.layout.*timerType*.color = *color* -- Text color
tmr.settings.layout.*timerType*.font = *fontPath* -- Text font
tmr.settings.layout.*timerType*.x = *number* -- Text offset by X
tmr.settings.layout.*timerType*.y = *number* -- Text offset by Y
tmr.settings.layout.*timerType*.priority = *number* -- Text priority (how much ahead of other pictures)
tmr.settings.layout.*timerType*.scaleX = *number* -- Text scale by X
tmr.settings.layout.*timerType*.scaleY = *number* -- Text scale by Y
tmr.settings.layout.*timerType*.opacity = *number* -- Text opacity (from 0 to 1)
tmr.settings.layout.*timerType*.alignX = *number* -- Text align by X (by left side: 0 or ALIGN_LEFT; by center: 0.5 or ALIGN_CENTER; by right side: 1 or ALIGN_RIGHT)
tmr.settings.layout.*timerType*.alignY = *number* -- Text align by Y (by top side: 0 or ALIGN_TOP; by center: 0.5 or ALIGN_CENTER; by bottom side: 1 or ALIGN_BOTTOM)
tmr.settings.layout.*timerType*.scene = *boolean* -- Text offset relative to the scene? If false then text offset will be relative to the hud
tmr.settings.layout.*timerType*.target = *boolean* -- Text offset relative to the scene? If false then text offset will be relative to the hud
tmr.settings.layout.*timerType*.shader = *shader* -- Text shader
tmr.settings.layout.*timerType*.uniforms = *table* -- Shader uniforms to supply
tmr.settings.layout.*timerType*.smooth = *boolean* -- If true then will use crisp scaling as long as no shader is applied, if false then it will use bilinear filtering
Read more about layout here

Code: Select all

tmr.settings.intersectingOpacityChanging.enable = *boolean* -- Enable text opacity changing if NPC or Player intersects the text
tmr.settings.intersectingOpacityChanging.opacitySpeed = *number* -- Speed of opacity changing (1 = 0.1 units per tick)
tmr.settings.intersectingOpacityChanging.changedOpacity = *number* -- Minimum opacity when NPC or Player intersecting the text
default values: show

Code: Select all

if tmr.unit.*timerType*.hours > 0 then
	tmr.settings.layout.*allTimerTypes*.format = {"%.1d:%.2d:%.2d.%.3d",u.fullhours,u.minutes,u.seconds,u.milleseconds}
else
	tmr.settings.layout.*allTimerTypes*.format = {"%.1d:%.2d.%.3d",u.minutes,u.seconds,u.milleseconds}
end
tmr.settings.layout.global.color = Color.white
tmr.settings.layout.level.color = Color.lightgrey
tmr.settings.layout.best.color = Color.lightgreen
tmr.settings.layout.*allTimerTypes*.font = "textplus/font/6.ini"
tmr.settings.layout.*allTimerTypes*.x = 400
tmr.settings.layout.global.y = 600
tmr.settings.layout.level.y = 600 - tmr.text.*timerType*.layout.width    -- =582
tmr.settings.layout.best.y = 600 - tmr.text.*timerType*.layout.width * 2 -- =564
tmr.settings.layout.*allTimerTypes*.priority = 9
tmr.settings.layout.*allTimerTypes*.scaleX = 2
tmr.settings.layout.*allTimerTypes*.scaleY = 2
tmr.settings.layout.*allTimerTypes*.opacity = 1
tmr.settings.layout.*allTimerTypes*.alignX = ALIGN_CENTER -- =0.5
tmr.settings.layout.*allTimerTypes*.alignY = ALIGN_BOTTOM -- =1
read-only: show

Code: Select all

tmr.text.*timerType*.visible -- Text visible
tmr.text.*timerType*.layout.width -- Text width
tmr.text.*timerType*.layout.height -- Text height
tmr.text.*timerType*.x -- Text offset by X (align is taken into account)
tmr.text.*timerType*.y -- Text offset by Y (align is taken into account)

tmr.unit.*timerType*.ticks
tmr.unit.*timerType*.milleseconds
tmr.unit.*timerType*.centiseconds
tmr.unit.*timerType*.deciseconds
tmr.unit.*timerType*.seconds
tmr.unit.*timerType*.minutes
tmr.unit.*timerType*.hours
tmr.unit.*timerType*.days

tmr.unit.*timerType*.fullticks
tmr.unit.*timerType*.fullmilleseconds
tmr.unit.*timerType*.fullcentiseconds
tmr.unit.*timerType*.fulldeciseconds
tmr.unit.*timerType*.fullseconds
tmr.unit.*timerType*.fullminutes
tmr.unit.*timerType*.fullhours
functions: show

Code: Select all

tmr:pause()
tmr:resume()
tmr:clear(<timerType>,*isFull*)
events: show

Code: Select all

function tmr.formatSettings(*unitTable*,*timerType*,*settingTable*)
function tmr.*timerType*FormatSettings(*unitTable*,*timerType*,*settingTable*)
examples: show

Code: Select all

tmr.settings.layout.global.color = Color.white -- Set color to white for global timer
tmr:clear("global",true) -- Clear only global data
tmr:clear(true) -- Clear all data for all levels
function tmr.globalFormatSettings(u,t,v) -- Event only for global timer format
	if u.hours * 0 then
		v.format = {"%.1d:%.2d:%.2d.%.3d",u.fullhours,u.minutes,u.seconds,u.milleseconds} -- tmr.settings.layout[t].format = v.format
	else
		v.format = {"%.1d:%.2d.%.3d",u.minutes,u.seconds,u.milleseconds}
	end
end
tmr:set({hours = *number*, minutes = *number*, seconds = *number*, ticks = *number*, milleseconds = *number*} or {*hours*,*minutes*,*seconds*,*milleseconds*} (ONE of tables without "or"), *type of timer*) — sets the timer values for certain type of timer
tmr:updateBestTime(*to stop timer (true or false)*) — changes best time to current level timer
• Added ability to use SPT or SpeedrunTimer for using functions instead of require("speedrunTimer")
Last edited by LooKiCH on Tue Feb 06, 2024 3:17 pm, edited 3 times in total.

LooKiCH
Blooper
Blooper
Posts: 159
Joined: Tue Jun 13, 2017 11:28 am
Pronouns: he/him
Contact:

New version 1.1 is out!

Postby LooKiCH » Mon Nov 27, 2023 2:24 pm

Changelog:
• Fixed bug with update best time and other bugs
• By default turned off NPC/Player intersect opacity changing
• By default opacity was set to 0.5
• Added new functions:
SPT:set({hours = *number*, minutes = *number*, seconds = *number*, ticks = *number*, milleseconds = *number*} or {*hours*,*minutes*,*seconds*,*milleseconds*} (ONE of tables without “or”), *type of timer*) — sets the timer values for certain type of timer
SPT:updateBestTime(*to stop timer (true or false)*) — changes best time to current level timer
• Added ability to use SPT or SpeedrunTimer for using functions instead of require("speedrunTimer")


Return to “LunaLua”

Who is online

Users browsing this forum: Semrush [Bot] and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari