Certainly! Below is an example code for The Modding Tree (TMT) that creates a new layer where the player can select a stat to train: damage, defense, or health. This layer will allow the player to invest resources to improve one of these stats.
// Add this to your layers.js file in The Modding Tree project
addLayer("S", {
name: "Stats", // This is optional, only used in a few places, if absent it just uses the layer id.
symbol: "S", // This appears on the layer's node. Customize it to your liking.
position: 0, // The horizontal position within a row. By default, layers are spread out evenly in a row.
startData() { return {
unlocked: true,
points: new Decimal(0),
selectedStat: "None",
damage: new Decimal(1),
defense: new Decimal(1),
health: new Decimal(10),
}},
color: "#4BDC13",
requires: new Decimal(10), // Can be a function that takes requirement increases into account
resource: "stat points", // Name of prestige currency
baseResource: "points", // Name of resource prestige is based on
baseAmount() {return player.points}, // Get the current amount of baseResource
type: "normal", // normal: cost to gain currency depends on amount gained; static: cost depends on amount already owned
exponent: 0.5, // Prestige currency exponent
gainMult() { // Calculate the multiplier for main currency from bonuses
let mult = new Decimal(1)
return mult
},
gainExp() { // Calculate the exponent on main currency from bonuses
return new Decimal(1)
},
row: 1, // Row the layer is in on the tree (0 is the first row)
hotkeys: [
{key: "s", description: "S: Reset for stat points", onPress(){if (canReset(this.layer)) doReset(this.layer)}},
],
layerShown(){return true},
tabFormat: {
"Main": {
content: [
"main-display",
["display-text", function() { return `Currently selected stat: ${player.S.selectedStat}` }],
"blank",
["row", [
["clickable", "selectDamage"],
["clickable", "selectDefense"],
["clickable", "selectHealth"],
]],
"blank",
["upgrades", [1,2,3]],
],
},
},
clickables: {
selectDamage: {
display() { return "Select Damage" },
canClick() { return true },
onClick() {
player.S.selectedStat = "Damage"
},
},
selectDefense: {
display() { return "Select Defense" },
canClick() { return true },
onClick() {
player.S.selectedStat = "Defense"
},
},
selectHealth: {
display() { return "Select Health" },
canClick() { return true },
onClick() {
player.S.selectedStat = "Health"
},
},
},
upgrades: {
1: {
title: "Increase Damage",
description: "Increase your damage stat.",
cost: new Decimal(1),
unlocked() { return player.S.selectedStat === "Damage" },
onPurchase() {
player.S.damage = player.S.damage.plus(1)
},
},
2: {
title: "Increase Defense",
description: "Increase your defense stat.",
cost: new Decimal(1),
unlocked() { return player.S.selectedStat === "Defense" },
onPurchase() {
player.S.defense = player.S.defense.plus(1)
},
},
3: {
title: "Increase Health",
description: "Increase your health stat.",
cost: new Decimal(1),
unlocked() { return player.S.selectedStat === "Health" },
onPurchase() {
player.S.health = player.S.health.plus(5)
},
},
},
});
Explanation:
How It Works:
-
Selecting a Stat:
- The player uses the clickable buttons to select which stat they want to train.
- The
selectedStat property updates accordingly.
-
Training the Stat:
- Once a stat is selected, the corresponding upgrade becomes available.
- The player can spend stat points to purchase the upgrade, which increases the stat.
- For example, if Damage is selected, the Increase Damage upgrade is unlocked.
-
Gaining Stat Points:
- The player can perform a reset in this layer to gain stat points, using the standard TMT prestige mechanics.
- The amount of stat points gained depends on the base resource (points) and the layer's settings.
Notes:
- This setup uses clickables to allow the player to select a stat.
- The upgrades are conditionally displayed based on the
selectedStat.
- The stats (
damage, defense, health) are stored in the player's data and can be used elsewhere in your game logic (e.g., in combat systems or other layers).
Feel free to customize the layer further to fit the specifics of your game, such as adjusting costs, effects, or integrating with other layers and features.