Page 1 of 1

playerSymbols.lua

Posted: Thu Apr 16, 2020 3:12 pm
by DigitalDetective47
playerSymbols.lua is a script that replaces the usual ‘1UP’ sprite next to the level counter with a custom emblem specific to each character. These character emblems are accessed under the name pattern ‘icon-#.png’, where # is the character ID of the current character. This is also compatible with lifeCountPlus.lua, as long as player head icons are disabled. But at that point, why not just replace the player head graphics yourself? This can be better than lifeCountPlus.lua in certain situations, however. Firstly, it does not override the standard SMBX life counter, which greatly increases its compatibility with other scripts that involve the life counter. Secondly, it has support for all additional characters, and will have built‐in support for any character added in the future.
Images:
Spoiler: show
Image
Image
To use it, simply add this line to luna.lua and map.lua.

Code: Select all

playerSymbols=API.load("playerSymbols")
Download playerSymbols.lua here: https://drive.google.com/file/d/1f5CvSW ... sp=sharing
Dowloads for older versions:
Spoiler: show
Thanks to Enjl for some code used in v1.1 and above.
(Also, could someone make some icons for the extra characters? I have a Wario icon, but couldn't put together anything that looks good for the other characters.)

Re: playerSymbols.lua

Posted: Thu Apr 16, 2020 3:21 pm
by Emral
This is a pretty wasteful way to handle this... Aside from the fact that players don't exist before onStart, images are already inherently loaded on demand, so there's no harm in simply using a lookup table to save some loading headaches:

Code: Select all

local symbols = {}

symbols.icons = {}
for i=1, 16 do
	symbols.icons[i] = Graphics.loadImageResolve("playerSymbols-"..i..".png")
end

function symbols.onInitAPI()
	registerEvent(symbols, "onTickEnd")
end

local lastPlayerCharacters = {}

function onTickEnd()
	for k,v in ipairs(Player.get()) do
		if lastPlayerCharacters[k] then
			if v.character ~= lastPlayerCharacters[k] then
				if k == 1 then
					Graphics.sprites.hardcoded["33-3"].img = symbols.icons[v.character] --nil will always just be the default
				elseif k == 2 then -- there can be more than 2 with the supermarion cheats
					Graphics.sprites.hardcoded["33-7"].img = symbols.icons[v.character]
				end
			end
		else
			if k == 1 then
				Graphics.sprites.hardcoded["33-3"].img = symbols.icons[v.character]
			elseif k == 2 then -- there can be more than 2 with the supermarion cheats
				Graphics.sprites.hardcoded["33-7"].img = symbols.icons[v.character]
			end
		end
		lastPlayerCharacters[k] = v.character
	end
end

return

Re: playerSymbols.lua

Posted: Tue Apr 28, 2020 4:58 am
by lan vuhoang
How am I supposed to use it?

Added in 13 minutes 29 seconds:
Now I know. Just add it into the episode folder.