How can I make a level system with my current xp system?

I have a mongodb database with an xp system already in place. I want to make it so if someone has 100 xp they level up.

My schema looks like:

const mongoose = require('mongoose');

const yenSchema = mongoose.Schema({
    guildID: String,
    guildName: String,
    name: String,
    userID: String,
    lb: String,
    yen: Number,
    daily: Number,
    xp: Number,
    level: Number,
    rank: Number,
    gear: String,
    class: String,
})

module.exports = mongoose.model("Yen", yenSchema)

So basically, I get xp between 1 and 3 when I use the daily command and so every 100 xp I want to make it so it says that I leveled up. So, when the xp reaches 100 it levels up then when Im level two it costs 200 and then the xp resets and so on…

Every time they get xp, do something like

if (user.xp == 100) {
 user.xp++;
user.xp = 0;
}

Or, instead of hard coding all the numbers, try:

const levelMultipler = 100

if (user.xp = levelMultiplier * user.level) {
user.xp++
}

Basically, 100xp to level 1, 200xp to level 2, etc

Where would I put this though? In a file called levels.js, then call that in the ready event in index?

Uhhh sure…? I do not know if the MVC paradigm applies to discord bots, but probably in a controller file. Also, I assume by index you mean index.js - make sure you split up your files so you don’t have to wade through 1000 lines of code.

If you send your file tree here, I can help you more I guess.

Like

.
./folder
./folder/file
./folder2/file
./package.json

Ahh, I understand what your saying, thanks. Is there any way you can explain it in more detail? Like how I would make the command with my mongodb.

Put the leveling script in the file where you change user’s information in the database. Like if you have a file that updates number of commands sent or name, put that there too.

Sorry if it’s kind of confusing.

I structured my backend app like

.
./views
./views/scripts
./views/styles
./views/
...
...
Bunch of EJS files
...
...
./create.js
./update.js
./static.js
...
...
so on, so forth
...
...
./package.json

So I would put the leveling script inside of ./update.js

Very confusing, lmao

I think I understand a bit tho.

I have no clue how to structure this… is there anyone that can give me a video or something? I use mongodb.

2 Likes

What’s your current file structure? Expand all the folders and send a screenshot

Im working on the levels folder rn

how about in ./game/daily.js? Or in ./game/profile.js? It might be more practical to make a user update folder - for like claiming dailies, getting levels, getting Xp, gifts, etc.

I want to make a leveling system, those are for coins and exp.

You get between 1-3 exp every time you use the daily command.

Yeah, move the leveling thing into the game folder.

The whole folder?

The current structure is now:

Btw, I call the levels folder in index.js

image

Get rid of the levels folder, you won’t need it anymore. Make levels into ./game/levels.js