So I'm trying to be modder so I can post the smb3 pmeter I just made. And so people can use it.
And the code is right below.
And the code is right below.
LUA:
-- name: SMB3 Momentum P-Meter
-- description: Builds running momentum smoothly like SMB3 with a 5-arrow P-Meter.
local momentum = 0.0
local function before_phys_step(m)
if m.playerIndex ~= 0 then return end
if m.action == ACT_WALKING and m.intendedMag > 16.0 then
-- Build momentum steadily once Mario starts running
if m.forwardVel > 12.0 then
momentum = math.min(momentum + 0.35, 52.0)
end
-- Multiply ground velocity inside HOOK_BEFORE_PHYS_STEP to beat the 32.0 speed cap
if momentum > 32.0 and m.forwardVel > 28.0 then
local speedScale = momentum / 32.0
m.vel.x = m.vel.x * speedScale
m.vel.z = m.vel.z * speedScale
end
else
-- Keep momentum in the air, drain smoothly when stopping on the ground
if (m.action & ACT_FLAG_AIR) == 0 then
momentum = math.max(momentum - 1.5, 0.0)
end
end
end
local function mario_update(m)
if m.playerIndex ~= 0 then return end
-- Keep Mario's normal running animation, just speed up his leg movement when sprinting
if m.action == ACT_WALKING and momentum > 32.0 then
local speedScale = momentum / 32.0
m.marioObj.header.gfx.animInfo.animAccel = math.floor(0x10000 * speedScale)
end
end
local function on_hud_render()
if obj_get_first_with_behavior_id(id_bhvActSelector) ~= nil then return end
if gNetworkPlayers[0].currActNum == 99 then return end
djui_hud_set_resolution(RESOLUTION_N64)
djui_hud_set_font(FONT_HUD)
local m = gMarioStates[0]
local speed = math.max(math.abs(m.forwardVel), momentum)
local filled = 0
-- Arrows 1 to 3: Regular run
if speed > 6.0 then filled = 1 end
if speed > 18.0 then filled = 2 end
if speed >= 30.0 then filled = 3 end
-- Arrows 4 and 5: Sprint momentum buildup
if speed >= 36.0 then filled = 4 end
if speed >= 43.0 then filled = 5 end
-- Full P-Speed sprint
local pMaxed = speed >= 49.0
local x = 14
local y = 212
local scale = 0.8
for i = 1, 5 do
if i <= filled then
djui_hud_set_color(255, 255, 255, 255)
else
djui_hud_set_color(80, 80, 80, 180)
end
djui_hud_print_text(">", x + (i - 1) * 8, y, scale)
end
if pMaxed and (get_global_timer() % 8 < 4) then
djui_hud_set_color(255, 60, 60, 255)
elseif pMaxed then
djui_hud_set_color(255, 255, 255, 255)
else
djui_hud_set_color(80, 80, 80, 180)
end
djui_hud_print_text("P", x + 44, y, scale)
end
hook_event(HOOK_BEFORE_PHYS_STEP, before_phys_step)
hook_event(HOOK_MARIO_UPDATE, mario_update)
hook_event(HOOK_ON_HUD_RENDER_BEHIND, on_hud_render)