How to Display Star Coin Count at Player's Convenience

Post here for help and support regarding LunaLua and SMBX2's libraries and features.

Moderator: Userbase Moderators

Unknown68D
Spiny
Spiny
Posts: 26
Joined: Tue Feb 05, 2019 8:47 pm
Flair: Mindfulness
Pronouns: he/him/his
Contact:

How to Display Star Coin Count at Player's Convenience

Postby Unknown68D » Wed Jul 08, 2020 8:28 pm

Hello! I'm the creator of an episode that makes use of the new Star Coin NPCs to keep track of a player's Star Coin progress. Unfortunately, I haven't been able to determine an effective, player-friendly way to display a player's Star Coin progress, meaning that they'd currently have to enter every single level to check their progress.

In the HUD of a level, its Star Coin Counter and index positioning are displayed.

Image

#1. Is there a way to show this counter on the World Map on a per-level basis. There is obviously code that executes in order to display a level's title when a player walks over its corresponding level icon. Is there a way I could display exactly this on its corresponding level so that the player just has to walk on a level's icon to check their Star Coin progress for that level, just like in NSMB?

#2. Are there any even more convenient methods to display Star Coin totals and progress, such as keeping track of a player's overall Star Coin count on the World Map & in levels?

#3. What are the files/variables in which this information is stored in an episode's save file, & how would I be able to access them, extract them, and apply them where appropriate for the reasons stated above?

I would appreciate any type of response, specifically detailed ones. Thank you!

Cedur
Link
Link
Posts: 7073
Joined: Tue Jun 28, 2016 10:14 am
Flair: I'm gone, for chess and minesweeper
Pronouns: he/him

Re: How to Display Star Coin Count at Player's Convenience

Postby Cedur » Thu Jul 09, 2020 7:25 am

#4. What do we need to do in order to have star coins saved upon checkpoints (I mean they technically are but we want to make it such that collecting all 5 star coins in a level gives a star, and by basic layer+event, the already collected star coins would stay in the layer and not be removed from it when restarting from a checkpoint)

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9865
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: How to Display Star Coin Count at Player's Convenience

Postby Emral » Thu Jul 09, 2020 7:37 am

#1 HUDOverride.drawStarcoins is the function that draws the star coin display. With a bit of effort you may be able to get it to work on the overworld.

#2 SMBX2 already keeps track of that. SaveData._basegame.starcoinCounter. See starcoin.lua in npcs/ai.

#3 See 2.

#4 Easiest way is probably to check if starcoin.getLevelCollected()'s return value is equal to the number of star coins in the level ( starcoin.getLevelList(Level.filename()).maxID ) and then do something. IDK what you mean with all that layer-event thing, since what you seem to describe is not how layers and events work.

Unknown68D
Spiny
Spiny
Posts: 26
Joined: Tue Feb 05, 2019 8:47 pm
Flair: Mindfulness
Pronouns: he/him/his
Contact:

Re: How to Display Star Coin Count at Player's Convenience

Postby Unknown68D » Thu Jul 09, 2020 6:53 pm

Cedur wrote:
Thu Jul 09, 2020 7:25 am
#4. What do we need to do in order to have star coins saved upon checkpoints (I mean they technically are but we want to make it such that collecting all 5 star coins in a level gives a star, and by basic layer+event, the already collected star coins would stay in the layer and not be removed from it when restarting from a checkpoint)
I was actually able to find a fix after asking around in the Codehaus Discord server! Here is the code below. This code exists somewhere in these forums, but I found out this code from @Lusho#9233. This allows a Star at the end of a level to be saved even with dying after a checkpoint. This code has one slight issue where the star layer would instantly be shown only upon loading a level for the very first time. I've decided to go with a work-around in which the Star layer would be hidden upon entering a level and starting at the beginning. However, this means that if a player decides to collect all 5 Star Coins & reach the exit without collecting the SMW collectible star, then they must collect a checkpoint I placed at the end of each level right next to the goal, lose a life and re-collect the star then. Not a huge deal & would really only cause an issue if someone accidentally/actively decided to skip a collectible.

Code:
Spoiler: show
local starcoin = require("npcs/ai/starcoin")
local collected = false

function onTick()
if starcoin.getLevelCollected(Level.filename()) >= starcoin.count() and not collected then
triggerEvent("Show Star")
collected = true
end
end


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 2 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari