2022-12-17 18:32:55 +00:00
|
|
|
-- name: Personal Star Counter EX+
|
|
|
|
-- description: See how many stars you collect!\nIdea by Mr.Needlemouse, created by Sunk\n\nModified by Demnyx.
|
2023-04-24 23:07:25 +00:00
|
|
|
-- incompatible: gamemode arena
|
|
|
|
|
2022-12-17 18:32:55 +00:00
|
|
|
if mod_storage_load("StarCounter") == nil then
|
2023-02-21 02:44:24 +00:00
|
|
|
mod_storage_save("StarCounter", "0")
|
2022-12-17 18:32:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local TotalStarCounter = tonumber(mod_storage_load("StarCounter"))
|
|
|
|
local StarCounter = 0
|
|
|
|
local prevNumStars = 0
|
|
|
|
|
|
|
|
local screenHeight = 0
|
|
|
|
local screenWidth = 0
|
|
|
|
|
|
|
|
local psToggle = 1
|
|
|
|
|
2023-04-24 23:07:25 +00:00
|
|
|
local fadeTimer = 0
|
|
|
|
|
|
|
|
-- junk --
|
|
|
|
cutscenes = {
|
|
|
|
[ACT_END_PEACH_CUTSCENE] = true,
|
|
|
|
[ACT_CREDITS_CUTSCENE] = true,
|
|
|
|
[ACT_END_WAVING_CUTSCENE] = true,
|
|
|
|
[ACT_INTRO_CUTSCENE] = true,
|
|
|
|
}
|
|
|
|
|
2022-12-17 18:32:55 +00:00
|
|
|
---@param m MarioState
|
|
|
|
--Increments an independent counter if a star is collected.
|
|
|
|
function localStarCounter(m, o, type)
|
2023-04-24 23:07:25 +00:00
|
|
|
if (m.playerIndex == 0) and (type == INTERACT_STAR_OR_KEY) then
|
|
|
|
--This ensures that it increments ONLY if a star is collected.
|
|
|
|
if get_id_from_behavior(o.behavior) ~= id_bhvBowserKey then
|
|
|
|
--The hook happens after the star count increments, so this allows the independent counter to increment ONLY when YELLOW star is collected.
|
|
|
|
if m.numStars ~= prevNumStars then
|
|
|
|
StarCounter = StarCounter + 1
|
2023-02-21 02:44:24 +00:00
|
|
|
TotalStarCounter = TotalStarCounter + 1
|
|
|
|
mod_storage_save("StarCounter", tostring(TotalStarCounter))
|
2023-04-24 23:07:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-12-17 18:32:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Hud alpha stuff from Agent X
|
|
|
|
function djui_hud_set_adjusted_color(r, g, b, a)
|
2023-04-24 23:07:25 +00:00
|
|
|
local multiplier = 1
|
|
|
|
if djui_hud_is_pause_menu_created() then multiplier = 0.57 end
|
|
|
|
djui_hud_set_color(r * multiplier, g * multiplier, b * multiplier, a)
|
2022-12-17 18:32:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function displayStarCounter()
|
2023-02-21 02:44:24 +00:00
|
|
|
local m = gMarioStates[0]
|
|
|
|
if psToggle ~= 1 then return end
|
2023-04-24 23:07:25 +00:00
|
|
|
--if cutscenes[m.action] ~= nil then return end
|
2023-02-21 02:44:24 +00:00
|
|
|
if obj_get_first_with_behavior_id(id_bhvActSelector) ~= nil
|
2023-04-24 23:07:25 +00:00
|
|
|
or cutscenes[m.action] ~= nil then
|
|
|
|
return
|
|
|
|
end
|
2022-12-17 18:32:55 +00:00
|
|
|
|
2023-02-21 02:44:24 +00:00
|
|
|
djui_hud_set_resolution(RESOLUTION_N64)
|
|
|
|
djui_hud_set_font(FONT_HUD)
|
2022-12-17 18:32:55 +00:00
|
|
|
|
2023-04-24 23:07:25 +00:00
|
|
|
--I don't want to put this in a seperate function, there's not enough code for it to be worth it.
|
|
|
|
if m.playerIndex == 0 then
|
2023-02-21 02:44:24 +00:00
|
|
|
prevNumStars = m.numStars
|
2023-04-24 23:07:25 +00:00
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
2022-12-17 18:32:55 +00:00
|
|
|
|
2023-04-24 23:07:25 +00:00
|
|
|
screenHeight = djui_hud_get_screen_height()
|
|
|
|
screenWidth = djui_hud_get_screen_width()
|
2022-12-17 18:32:55 +00:00
|
|
|
|
2023-02-21 02:44:24 +00:00
|
|
|
if a == nil then
|
|
|
|
a = 255
|
|
|
|
end
|
|
|
|
|
|
|
|
local timerValFrames = hud_get_value(HUD_DISPLAY_TIMER)
|
|
|
|
local timerX = 0
|
|
|
|
local timerY = 0
|
|
|
|
|
|
|
|
-- Move HUD graphics away from the TIMER HUD
|
|
|
|
if timerValFrames ~= 0 then
|
|
|
|
timerX = 60
|
|
|
|
timerY = 17
|
|
|
|
end
|
|
|
|
|
2023-04-24 23:07:25 +00:00
|
|
|
--Normal personal star counter (The red one)
|
2023-02-21 02:44:24 +00:00
|
|
|
if StarCounter >= 100 then
|
|
|
|
djui_hud_set_adjusted_color(255, 255, 255, a)
|
2023-04-24 23:07:25 +00:00
|
|
|
djui_hud_print_text(tostring(StarCounter), screenWidth - 60 - timerX, screenHeight - 208 - timerY, 1)
|
2023-02-21 02:44:24 +00:00
|
|
|
djui_hud_set_adjusted_color(232, 17, 35, a)
|
2023-04-24 23:07:25 +00:00
|
|
|
djui_hud_render_texture(gTextures.star, screenWidth - 76 - timerX, screenHeight - 208 - timerY, 1, 1)
|
2023-02-21 02:44:24 +00:00
|
|
|
else
|
|
|
|
djui_hud_set_adjusted_color(246, 246, 246, a)
|
2023-04-24 23:07:25 +00:00
|
|
|
djui_hud_print_text(tostring("X"), screenWidth - 60 - timerX, screenHeight - 208 - timerY, 1)
|
2023-02-21 02:44:24 +00:00
|
|
|
djui_hud_set_adjusted_color(255, 255, 255, a)
|
2023-04-24 23:07:25 +00:00
|
|
|
djui_hud_print_text(tostring(StarCounter), screenWidth - 46 - timerX, screenHeight - 208 - timerY, 1)
|
2023-02-21 02:44:24 +00:00
|
|
|
djui_hud_set_adjusted_color(232, 17, 35, a)
|
2023-04-24 23:07:25 +00:00
|
|
|
djui_hud_render_texture(gTextures.star, screenWidth - 76 - timerX, screenHeight - 208 - timerY, 1, 1)
|
|
|
|
end
|
2022-12-17 18:32:55 +00:00
|
|
|
|
2023-04-24 23:07:25 +00:00
|
|
|
--Total star counter (The green one)
|
2023-02-21 02:44:24 +00:00
|
|
|
if timerValFrames ~= 0 then
|
|
|
|
timerX = 0
|
|
|
|
timerY = -10
|
|
|
|
end
|
|
|
|
|
|
|
|
local perceived_total_counter = TotalStarCounter
|
|
|
|
local milestone_counter = 0
|
|
|
|
while perceived_total_counter >= 10000 do
|
|
|
|
perceived_total_counter = perceived_total_counter - 10000
|
|
|
|
milestone_counter = milestone_counter + 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if perceived_total_counter >= 100 then
|
|
|
|
djui_hud_set_adjusted_color(255, 255, 255, a)
|
2023-04-24 23:07:25 +00:00
|
|
|
djui_hud_print_text(tostring(perceived_total_counter), screenWidth - 60 - timerX, screenHeight - 190 - timerY, 1)
|
2023-02-21 02:44:24 +00:00
|
|
|
djui_hud_set_adjusted_color(50, 176, 40, a)
|
2023-04-24 23:07:25 +00:00
|
|
|
djui_hud_render_texture(gTextures.star, screenWidth - 76 - timerX, screenHeight - 190 - timerY, 1, 1)
|
2023-02-21 02:44:24 +00:00
|
|
|
if milestone_counter ~= 0 then
|
|
|
|
djui_hud_set_adjusted_color(255, 255, 255, a)
|
2023-04-24 23:07:25 +00:00
|
|
|
djui_hud_print_text(string.format("x%d", milestone_counter), screenWidth - 76 - timerX, screenHeight - 174 - timerY, 0.5)
|
2023-02-21 02:44:24 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
djui_hud_set_adjusted_color(246, 246, 246, a)
|
2023-04-24 23:07:25 +00:00
|
|
|
djui_hud_print_text(tostring("X"), screenWidth - 60 - timerX, screenHeight - 190 - timerY, 1)
|
2023-02-21 02:44:24 +00:00
|
|
|
djui_hud_set_adjusted_color(255, 255, 255, a)
|
2023-04-24 23:07:25 +00:00
|
|
|
djui_hud_print_text(tostring(perceived_total_counter), screenWidth - 46 - timerX, screenHeight - 190 - timerY, 1)
|
2023-02-21 02:44:24 +00:00
|
|
|
djui_hud_set_adjusted_color(50, 176, 40, a)
|
2023-04-24 23:07:25 +00:00
|
|
|
djui_hud_render_texture(gTextures.star, screenWidth - 76 - timerX, screenHeight - 190 - timerY, 1, 1)
|
2023-02-21 02:44:24 +00:00
|
|
|
if milestone_counter ~= 0 then
|
|
|
|
djui_hud_set_adjusted_color(255, 255, 255, a)
|
2023-04-24 23:07:25 +00:00
|
|
|
djui_hud_print_text(string.format("x%d", milestone_counter), screenWidth - 76 - timerX,
|
|
|
|
screenHeight - 174 - timerY, 0.5)
|
2023-02-21 02:44:24 +00:00
|
|
|
end
|
2023-04-24 23:07:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Trying some HUD trickery here..
|
|
|
|
if is_transition_playing() == true then
|
|
|
|
fadeTimer = 5
|
|
|
|
else
|
|
|
|
if fadeTimer >= 1 then
|
|
|
|
fadeTimer = fadeTimer - 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if fadeTimer > 0
|
|
|
|
or is_game_paused() == true then
|
|
|
|
djui_hud_set_render_behind_hud(true)
|
|
|
|
else
|
|
|
|
djui_hud_set_render_behind_hud(false)
|
|
|
|
end
|
|
|
|
--StarCounter = 120 (Debug thingie)
|
2022-12-17 18:32:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function PSToggle(msg)
|
2023-02-21 02:44:24 +00:00
|
|
|
if msg == string.lower("On") or msg == "1" then
|
|
|
|
psToggle = 1
|
|
|
|
return true
|
|
|
|
elseif msg == string.lower("Off") or msg == "0" then
|
|
|
|
psToggle = 0
|
|
|
|
return true
|
|
|
|
end
|
2022-12-17 18:32:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
---------
|
|
|
|
--Hooks--
|
|
|
|
---------
|
|
|
|
hook_event(HOOK_ON_INTERACT, localStarCounter)
|
|
|
|
hook_event(HOOK_ON_HUD_RENDER, displayStarCounter)
|
2023-04-24 23:07:25 +00:00
|
|
|
hook_chat_command('pstarcount', 'On|Off - Displays stars you"ve collected. Default is On.', PSToggle)
|
2023-04-30 12:46:47 +00:00
|
|
|
|
|
|
|
_G.PersonalStarCounter = {
|
|
|
|
get_star_counter = function ()
|
|
|
|
return StarCounter
|
|
|
|
end,
|
|
|
|
|
|
|
|
get_total_star_counter = function ()
|
|
|
|
return TotalStarCounter
|
|
|
|
end,
|
|
|
|
|
|
|
|
hide_star_counters = function (hide)
|
|
|
|
if hide then psToggle = 0 else psToggle = 1 end
|
|
|
|
end,
|
|
|
|
}
|