playerSymbols.lua

Share and discuss custom LunaLua code and content packs for SMBX2.

Moderator: Userbase Moderators

DigitalDetective47
Hoopster
Hoopster
Posts: 49
Joined: Fri Mar 27, 2020 10:12 pm
Pronouns: they/them
Contact:

playerSymbols.lua

Postby DigitalDetective47 » Thu Apr 16, 2020 3:12 pm

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.)
Last edited by DigitalDetective47 on Fri Apr 17, 2020 2:50 pm, edited 3 times in total.

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

Re: playerSymbols.lua

Postby Emral » Thu Apr 16, 2020 3:21 pm

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

lan vuhoang
Swooper
Swooper
Posts: 67
Joined: Wed Jul 03, 2019 7:31 am

Re: playerSymbols.lua

Postby lan vuhoang » Tue Apr 28, 2020 4:58 am

How am I supposed to use it?

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


Return to “LunaLua”

Who is online

Users browsing this forum: Alexx0612, arthur4272 and 2 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari