SMBX Create a cheat code

General discussion about Super Mario Bros. X.

Moderator: Userbase Moderators

Superfrancybros
Swooper
Swooper
Posts: 60
Joined: Sat May 23, 2020 5:44 am

SMBX Create a cheat code

Postby Superfrancybros » 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)

SuperAlex
2025 Egg Hunter
2025 Egg Hunter
Posts: 226
Joined: Mon Nov 02, 2020 3:02 pm
Flair: Spriting
Pronouns: He/Him
Contact:

Re: SMBX Create a cheat code

Postby SuperAlex » Wed Oct 06, 2021 12:57 pm

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.
Last edited by SuperAlex on Wed Oct 06, 2021 4:10 pm, edited 1 time in total.

Superfrancybros
Swooper
Swooper
Posts: 60
Joined: Sat May 23, 2020 5:44 am

Re: SMBX Create a cheat code

Postby Superfrancybros » Wed Oct 06, 2021 3:30 pm

Ok :(

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

Re: SMBX Create a cheat code

Postby Emral » 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.
Last edited by Emral on Wed Oct 06, 2021 4:20 pm, edited 1 time in total.

SuperAlex
2025 Egg Hunter
2025 Egg Hunter
Posts: 226
Joined: Mon Nov 02, 2020 3:02 pm
Flair: Spriting
Pronouns: He/Him
Contact:

Re: SMBX Create a cheat code

Postby SuperAlex » Wed Oct 06, 2021 4:12 pm

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.

Superfrancybros
Swooper
Swooper
Posts: 60
Joined: Sat May 23, 2020 5:44 am

Re: SMBX Create a cheat code

Postby Superfrancybros » 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?

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

Re: SMBX Create a cheat code

Postby Emral » Thu Oct 07, 2021 12:16 pm

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.

Superfrancybros
Swooper
Swooper
Posts: 60
Joined: Sat May 23, 2020 5:44 am

Re: SMBX Create a cheat code

Postby Superfrancybros » 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)?

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

Re: SMBX Create a cheat code

Postby Emral » Thu Oct 07, 2021 2:35 pm

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.


Return to “General”

Who is online

Users browsing this forum: No registered users and 2 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari