-- name: Smb3 P-Meter -- description: Builds running momentum smoothly like SMB3 with a 5-arrow P-Meter. local momentum = 0.0 local extraFrameAccum = 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 if m.forwardVel > 12.0 then momentum = math.min(momentum + 0.35, 52.0) end 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 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 if m.action == ACT_WALKING and momentum > 32.0 and m.marioObj ~= nil then local boost = ((momentum - 32.0) / 20.0) * 1.5 extraFrameAccum = extraFrameAccum + boost if extraFrameAccum >= 1.0 then local framesToAdd = math.floor(extraFrameAccum) extraFrameAccum = extraFrameAccum - framesToAdd local animInfo = m.marioObj.header.gfx.animInfo if animInfo.curAnim ~= nil then local loopEnd = animInfo.curAnim.loopEnd if loopEnd > 0 then animInfo.animFrame = (animInfo.animFrame + framesToAdd) % loopEnd end end end else extraFrameAccum = 0.0 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 if speed > 6.0 then filled = 1 end if speed > 18.0 then filled = 2 end if speed >= 30.0 then filled = 3 end if speed >= 36.0 then filled = 4 end if speed >= 43.0 then filled = 5 end 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)