Apply For Modder Status

Status
Not open for further replies.

Tigrito64

Member
Feb 21, 2026
3
0
130
Pronouns
Tigrito
My Mod Star = Speed
Link:Star=Speed

Code Lua:
-- name: \\#FFD700\\Star = Speed V1.0
-- description: Each star you collect increases your speed! +0.5 per star.
-- category: gameplay
-- pausable: true

-- Variables to track stars per player
local starCount = {}

-- Configuration
local SPEED_PER_STAR = 0.5 -- Speed boost per star
local MAX_SPEED = 200.0 -- Maximum speed cap
local HUD_UPDATE_RATE = 15 -- Frames per second for HUD update (for performance)

--- @param m MarioState
local function star_speed_update(m)
local pid = m.playerIndex

-- Initialize player data if needed
if starCount[pid] == nil then
starCount[pid] = 0
end

-- Apply speed boost if Mario is moving
if starCount[pid] > 0 and m.forwardVel ~= 0 then
local speedBoost = starCount[pid] * SPEED_PER_STAR
m.forwardVel = math.min(m.forwardVel + speedBoost, MAX_SPEED)
end
end

--- Handle star interaction
--- @param m MarioState
--- @param o Object
--- @param interactType number
local function on_star_interact(m, o, interactType)
-- Check if the interacted object is a star or key
if interactType == INTERACT_STAR_OR_KEY then
local pid = m.playerIndex

if starCount[pid] == nil then
starCount[pid] = 0
end

-- Increment the star counter for the session
starCount[pid] = starCount[pid] + 1
end
end

--- Function to render the HUD
local function on_hud_render()
-- Only render for the local player
local m = gMarioStates[0]
local pid = m.playerIndex

-- Ensure data exists
if starCount[pid] == nil then
starCount[pid] = 0
end

-- Set font and scale
djui_hud_set_font(DJUI_FONT_NORMAL)
local scale = 1.0

-- Calculate total extra speed
local totalExtraSpeed = starCount[pid] * SPEED_PER_STAR
local extraSpeedStr = string.format("%.1f", totalExtraSpeed) -- Format with one decimal

-- Prepare display text
local starsText = "Stars/Estrellas: " .. tostring(starCount[pid])
local speedText = "Speed extra/Velocidad extra: +" .. extraSpeedStr

-- Get screen dimensions
local screenWidth = djui_hud_get_screen_width()
local screenHeight = djui_hud_get_screen_height()

-- Position at bottom-left corner
local x = 10
local yStart = screenHeight - 60

-- Draw Star count text
djui_hud_set_color(255, 215, 0, 255) -- Gold Color (#FFD700)
djui_hud_print_text(starsText, x, yStart, scale)

-- Draw Extra Speed text (slightly below)
djui_hud_set_color(100, 255, 100, 255) -- Light Green Color
djui_hud_print_text(speedText, x, yStart + 25, scale)
end

-- Register Hooks
hook_event(HOOK_MARIO_UPDATE, star_speed_update)
hook_event(HOOK_ON_INTERACT, on_star_interact)
hook_event(HOOK_ON_HUD_RENDER, on_hud_render)
 
Status
Not open for further replies.

Users who are viewing this thread