Page 1 of 1

How to Display Star Coin Count at Player's Convenience

Posted: Wed Jul 08, 2020 8:28 pm
by Unknown68D
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!

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

Posted: Thu Jul 09, 2020 7:25 am
by Cedur
#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)

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

Posted: Thu Jul 09, 2020 7:37 am
by Emral
#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.

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

Posted: Thu Jul 09, 2020 6:53 pm
by Unknown68D
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