Page 1 of 1

SMBX Create a cheat code

Posted: Wed Oct 06, 2021 12:00 pm
by Superfrancybros
That's possible create a cheat code for SMBX?
(I want to create codes for change the background and the music of a level)

Re: SMBX Create a cheat code

Posted: Wed Oct 06, 2021 12:57 pm
by SuperAlex
Actually SMBX already has enough cheat codes, check the Handbook for example if you want to change the background and the music in water mode, just write "wetwater".
Like me:
"thirstquencher": Creates a desert background with desert music.
"confrontation": Creates a castle background with castle music.
"merryxmas": Creates a snowy background with snow music.
"ghosthly": Creates a Ghost house background with ghost house music.
"breaktime": Creates a Toad house background with SMRPG music.
"brinstar": Creates a Super Metroid background with metroid music.
"livinlavidaloca" Creates a bonus background with fleet guide music.
"inrelax" Creates a beach waterfalls background with TADPOLE POND music.
"blackhole": Creates a black background without music.

Re: SMBX Create a cheat code

Posted: Wed Oct 06, 2021 3:30 pm
by Superfrancybros
Ok :(

Re: SMBX Create a cheat code

Posted: Wed Oct 06, 2021 4:05 pm
by Emral
To create a new cheat, you can use newcheats.lua

Code: Select all

local newcheats = require("game/newcheats")

-- when the cheat "mycustomcheat" is typed on the keyboard, set the background of the section player 1 is in to the smb3 pipe background and sets the music to smb3 cave
newcheats.register("mycustomcheat", {onActivate = function()
	player.sectionObj.backgroundID = 5 
	player.sectionObj.musicID = 4
end})
You can look at newcheats.lua to see all the basegame cheats and how they're implemented. There are different events like onActivate, onToggle, onTick and onKeyDown for the cheats, which trigger under different circumstances as long as the cheat is active. Making the cheat logic will require some knowledge of lua though - like with that player.sectionObj stuff up there.
I derive the background IDs from the editor (they are the same numbers as in the section settings there) and the music ids from the data/_templates/music.ini file.

The code above would go into a file called luna.lua, located in your episode or level folder.

Re: SMBX Create a cheat code

Posted: Wed Oct 06, 2021 4:12 pm
by SuperAlex
Superfrancybros wrote:
Wed Oct 06, 2021 12:00 pm
That's possible create a cheat code for SMBX?
(I want to create codes for change the background and the music of a level)
Ok I'm so confused at the first time. Sorry for acomplishes.

Re: SMBX Create a cheat code

Posted: Thu Oct 07, 2021 10:44 am
by Superfrancybros
Enjl wrote:
Wed Oct 06, 2021 4:05 pm
To create a new cheat, you can use newcheats.lua

Code: Select all

local newcheats = require("game/newcheats")

-- when the cheat "mycustomcheat" is typed on the keyboard, set the background of the section player 1 is in to the smb3 pipe background and sets the music to smb3 cave
newcheats.register("mycustomcheat", {onActivate = function()
	player.sectionObj.backgroundID = 5 
	player.sectionObj.musicID = 4
end})
You can look at newcheats.lua to see all the basegame cheats and how they're implemented. There are different events like onActivate, onToggle, onTick and onKeyDown for the cheats, which trigger under different circumstances as long as the cheat is active. Making the cheat logic will require some knowledge of lua though - like with that player.sectionObj stuff up there.
I derive the background IDs from the editor (they are the same numbers as in the section settings there) and the music ids from the data/_templates/music.ini file.

The code above would go into a file called luna.lua, located in your episode or level folder.
Ok but if i put this code on newcheats.lua smbx dosn't work so well
What i must to edit on the code?

Re: SMBX Create a cheat code

Posted: Thu Oct 07, 2021 12:16 pm
by Emral
Superfrancybros wrote:
Thu Oct 07, 2021 10:44 am
Enjl wrote:
Wed Oct 06, 2021 4:05 pm
To create a new cheat, you can use newcheats.lua

Code: Select all

local newcheats = require("game/newcheats")

-- when the cheat "mycustomcheat" is typed on the keyboard, set the background of the section player 1 is in to the smb3 pipe background and sets the music to smb3 cave
newcheats.register("mycustomcheat", {onActivate = function()
	player.sectionObj.backgroundID = 5 
	player.sectionObj.musicID = 4
end})
You can look at newcheats.lua to see all the basegame cheats and how they're implemented. There are different events like onActivate, onToggle, onTick and onKeyDown for the cheats, which trigger under different circumstances as long as the cheat is active. Making the cheat logic will require some knowledge of lua though - like with that player.sectionObj stuff up there.
I derive the background IDs from the editor (they are the same numbers as in the section settings there) and the music ids from the data/_templates/music.ini file.

The code above would go into a file called luna.lua, located in your episode or level folder.
Ok but if i put this code on newcheats.lua smbx dosn't work so well
What i must to edit on the code?
Please double-check the last line of my message. You merely load newcheats and use its features, you shouldn't modify it directly. If you paste the code I wrote into your luna.lua, it should just kinda work.

Re: SMBX Create a cheat code

Posted: Thu Oct 07, 2021 2:16 pm
by Superfrancybros
Works! Thanks!
One last thing, It is possible to put this luna.lua for the game in general (for in genera i mean for the other episodies without putting the luna.lua in each folder)?

Re: SMBX Create a cheat code

Posted: Thu Oct 07, 2021 2:35 pm
by Emral
Superfrancybros wrote:
Thu Oct 07, 2021 2:16 pm
Works! Thanks!
One last thing, It is possible to put this luna.lua for the game in general (for in genera i mean for the other episodies without putting the luna.lua in each folder)?
Nope, there is no system that allows for custom code to run for every episode. You COULD modify your basegame install, but I don't recommend it because it may make it incompatible with certain episodes and levels in unexpected ways. Copying the piece of code into the luna.lua of every episode you want it in is safer.