#Stats system

1 messages · Page 1 of 1 (latest)

gleaming mesa
#

I want to make a datapack where players level = their stats. But I don't really understand how I should detect when a player levels up (it's for a map that I will surely never make, I just want to learn)

minor stoneBOT
#

<@&1201956957406109788>

Someone will come and help soon!

💬 While you wait, take this time to provide more context and details.

🙇 If nobody has answered you by <t:1735238406:t>, feel free to use the Summon Helpers button to ping our helper team.

✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve

gleaming mesa
#

From what I have been told, I think I have to create 2 scoreboards, 1 that store the player's xp, and another that store the xp during the next tick

#

and compare them ?

brittle owl
#

yep correct

gleaming mesa
#

Ok, but the thing I struggle at rn, is storing the xp value

#

I think I have to use the xp query @s levels command

#

but how do I put it in a scoreboard ?

tough thunder
gleaming mesa
#

ok great, thx you !

gleaming mesa
brittle owl
#

the score name

tough thunder
#

Replace that with your scoreboard and a fake player

brittle owl
#

dam you're fast Sila

tough thunder
#

So like score .current_levels some_scoreboard

gleaming mesa
#

Thx you, also, how can I make it so there is a 1 tick delay between the time the 2 scoreboards pick up the xp value ?

#

The tick function runs every tick, so if I put them inside the tick function, won't they basically run at the same time ?

tough thunder
#

Do this in a separate function then in the tick function run that function as @a

gleaming mesa
#

ok I understand !

#

tysm !

tough thunder
#

Np

gleaming mesa
#

what's the issue here

#

I don't get it

slow minnow
#

you didn't specify that it is a score. you only gave it the score properties.

#

that's how it has to look

{"score":{"objective":"my_objective","name":"@s"}}
gleaming mesa
#

Rn, what I have is
-I detect when a player levels up
-I increase his stats depending on his level

#

Now, I want to make something in the chat so that when he levels up, he gets a point he can use to increase one of his stats

#

what I chose to do this

  • I have a scoreboard that makes all the stats the level of the player
  • I have a scoreboard with multiple "variables" that would increase when the player click a button in the chat in exchange of the points he got
  • I add the values of the 2 scoreboards and this would be the real stats of the player
#

but the thing is, is there a way to do the second point without creating a new function for each "variable" ?

#

It's very possible that I'm not clear at all or I probably forgot to tell some informations that I don't know that are important to get help

#

Stats system

tough thunder
#

Firstly, you can't use /function in chat UIs anyway - only OPed players will be able to click the buttons.

#

I suggest you create a /trigger command - this way, the button can run the command /trigger spend_point set <value> and you can detect what <value> is and change a scoreboard based on it

#

So for example, Button 1 would run /trigger spend_point set 1, etc. Then you can can do execute if score @s spend_point matches 1 run function ... execute if score @s spend_point matches 2 run function ...

gleaming mesa
#

I wanted to do something similar :(

tough thunder
#

Any player can run /trigger

#

But only players with op can run /function

gleaming mesa
#

Ok tysm, I'm going to learn how to do that now

tough thunder
#

All /trigger does is it lets a player set their own score on a scoreboard

tough thunder
gleaming mesa
tough thunder
#

yea

gleaming mesa
#

that's smart

#

depending on the button, a scoreboard will take a specific value which will trigger a specific function ?

#

right ? or am I dumb ?

gleaming mesa
tough thunder
#

yea - the button runs a trigger command which will set the score on the player's scoreboard to a specific value, and then you can check what value that is and run a function

gleaming mesa
#

yeah ok I get it ! :)

#

thank you so much

tough thunder
#

You also need to check that the player actually has point(s) to spend when they click the button

gleaming mesa
#

I have a system in mind for that

tough thunder
#

So you will need a scoreboard to track how many points a player has available to spend - each time they click a button, subtract 1 from that scoreboard, and if they try to click a button when they have no points available then dont let them

gleaming mesa
#

each time he levels up, it adds +1 to a scoreboard, and I check if the scoreboard value is >=1

tough thunder
#

yea

gleaming mesa
#

and then, I remove 1 from the value

tough thunder
#

thatll do it

gleaming mesa
#

nice !

#

I have another question about scoreboards

tough thunder
#

yea

gleaming mesa
#

from what I understand, I can create as many fake players I want in a scoreboard and track the value associated to these fake players

#

can't I do everything with a single scoreboard then ?

#

or am I misunderstanding something very fundamental ?

tough thunder
#

I mean, if you want, yeah. I often just have a big scoreboard which I use for all the internal values I need to store

#

But in this case, you need to store a value per player so you will need multiple scoreboards

#

A trigger command also needs to be its own scoreboard

gleaming mesa
#

so I will have 1 scoreboard for each stat then ?

#

one for strength, another one for health, etc etc ?

tough thunder
#

In your case, you will need

  • the trigger scoreboard
  • one scoreboard to track how many points the player has available
  • one scoreboard per stat (yes)
gleaming mesa
#

that's a nightmare

#

because since all stats change depending on the level of the player, I need an intermediate scoreboard where it's just the stats related to the level

#

another one which is related to the spent points

#

and another one which is the total

#

(for just 1 stat)

gleaming mesa
#

For example, the player will get 1 HP for each level he has

#

and he will have 1 HP for each spent point in this stat

#

I need 2 scoreboards to track that

#

and another one which is going to be the "effective stat" which is basically the sum

tough thunder
gleaming mesa
#

yeah

tough thunder
#

then yeah you will

gleaming mesa
#

:(

ebon torrentBOT
#

It's not too hard tho:```ansi
# Get player's xp level
execute store result score .hp some_objective run xp query @s levels

# Add stats point
scoreboard players operation .hp some_objective += @s <stat scoreboard>

tough thunder
#

If you're doing a lot of maths, I'd recommend doing it in a slower loop (like every second or half a second) so it doesn't lag as much

gleaming mesa
#

oh yeah that's true :/

#

I wanted to do the math each time the player levels up or click in the chat, but the second half isn't possible anymore

gleaming mesa
#

a tick function that works every 20 ticks or something ?

tough thunder
#

in your load function, run the function you want to run on a slow loop, then in that function, just put schedule function <this function> 1s so it schedules it to run the next second

#

the next time it gets run, it will schedule itself again, and so on

gleaming mesa
#

so, I'll also have to run this function in load.mcfunction to start the cycle right ?

tough thunder
#

yeah just to set it going

gleaming mesa
#

yeah ok, perfect !

#

thx you so much

tough thunder
#

np

gleaming mesa
#

I'm struggling with something that might be simple
I want to do a /execute that only works if a score from a scoreboard >=1

#

but I can't get it to work ?

#

nvm I think I got it working

#

I don't know why it worked when I typed
execute if score @s points matches 1.. run say yes
but it doesn't work when I try to use the >= symbol tho

fathom rain
#

is that in your tick function?

#

if it is, i know your issue

gleaming mesa
#

it's not

fathom rain
#

alright where is it being run?

gleaming mesa
#

in a random function I created to check if the player is allowed to get 1 stat point

#

I'm new, it's my first datapack, so maybe I can't provide the right information for you

#

if so, you could tell me what I should tell you x)

#

it's there

fathom rain
#

and do you run stats.mcfunction in chat?

gleaming mesa
#

I didn't try that, I just typed the command manually in chat

fathom rain
#

hm

gleaming mesa
#

the game isn't happy

#

and here, it's happy

#

I don't understand why tho

tough thunder
#

You just want to check if it is more than 1, so use matches 1..

gleaming mesa
#

ok, thx you for the explanation ! :)

tough thunder
#

matches is for a fixed value

#

no

#

problem

#

:)

gleaming mesa
tough thunder
#

yea

fathom rain
#

Yeah I had that thought in my mind, but I dont know too much about scoreboard operations

tough thunder
#

well fixed value being the range of numbers in this case

gleaming mesa
#

yeah since it's not continuous ig ?

#

idk, I'm on holidays x)

#

f math rn

tough thunder
#

I probably used the wrong term

#

matches is used for when you know what you want to compare it to

#

The other operators are for comparing two scoreboard values

gleaming mesa
#

thx you so much :)

#

now, I just need to figure out how to make clickable text

modern bridgeBOT
#
Minecraft Tools
About

Minecraft Tools has a really intuitive and easy GUI editor for JSON text and tellraw editor which makes creating nice-looking tellraw messages super easy

tough thunder
#

This has a good tellraw editor for that

gleaming mesa
#

I want to learn how to do it tho

#

that's the whole point, my datapack will never be used, I just want to learn

#

I'm sure there are people who already made what I'm doing 10000 times better

tough thunder
#

That’s fair, though in reality, advanced datapack developers just use the editor for convenience

#

But basically lemme explain

gleaming mesa
tough thunder
#

The JSON text in /tellraw can have a click_event field, like so: ```ansi
/tellraw @s {"text":"click me!!","click_event":{"action":"run_command","value":"/whatever_command"}}

#

The action can be a variety of things, such as run_command, suggest_command (which autofills the command in chat but doesn’t run it unless the player hits send), and copy_text

gleaming mesa
#

Ok, and how can I make a part of a tellraw message use the run_command action for example, and another part of the message use no action, etc ?

#

I don't think I'm clear x)

#

I hope you understand, if not I can try to rephrase it x)

tough thunder
gleaming mesa
#

ok I'm going to look into it

gleaming mesa
#

did I do something wrong ?

#

I get the message in the chat !

#

but when I click on it, nothing happens

tough thunder
#

Gimme a sec

gleaming mesa
#

yeah sure !

tough thunder
#

Mb it's clickEvent and not click_event

gleaming mesa
gleaming mesa
tough thunder
gleaming mesa
tough thunder
#

Bear in mind that all the items in the array will inherit styles from the first item, so it can be handy to set the first item to be blank:```
/tellraw @s ["",{...},{...}]

gleaming mesa
#

but ty for the tips, I know I would've pulled all my hair out because of this x)

tough thunder
#

Sometimes it's handy

gleaming mesa
#

yeah I understand why it could be handy, in cases where you want to apply the same style for everything I guess

#

but it's still weird imo x)

gleaming mesa
#

so I have this that generates a message that gives set the value of a scoreboard named selector to 1 (it works)

#

and then, every second, it does this function

#

that's the reset function

#

and for some reason, it doesn't work ?

gleaming mesa
#

And I really don't understand why, it doesn't seem to get the function working even tho I run it in the load function

gleaming mesa
#

when i manually start the function, it does nothing

tough thunder
gleaming mesa
#

I have to replace ..1 by 1.. ?

tough thunder
#

..1 means one or less

#

1.. means one or more

gleaming mesa
#

x)

#

I'm that dumb

#

crazy

tough thunder
#

nah dw, it's always confusing

gleaming mesa
#

I mean

#

with the next execute

#

I shoul've seen that something was wrong x)

#

one was for {1, 2, ..., +inf}, and the other one {0, 1, 2, ..., +inf}

#

I mean, not inf 27something or whatever x)

gleaming mesa
#

the function does work when I level up (when I level up, I call for the stats function)

#

which means the issue is either in the schedule fnction stats:stats 1s

#

or I'm completely lost

tough thunder
#

Oh yeah I see

#

You don't run the stats function as a player

#

You need to, in the stats function, run the function with the current code as @a

gleaming mesa
#

schedule function stats:stats as @a 1s ?

#

vscode doesn't seem happy with it

tough thunder
#

No

gleaming mesa
#

and also, I noticed another issue that I don't know how to tackle at all, when I /reload, I lose all the stats I got thanks too the points :/

tough thunder
#

Just in the stats function, run a execute as @a run function <something>

#

And in that function, you can do the scoreboard stuff

gleaming mesa
#

wait I'm having a hard time understanding this

tough thunder
#

Stats function itself needs to run a different function, because /schedule can't execute a function as a player

gleaming mesa
#

so I have to create a loop between 2 function ?

#

Function A stats function B which starts function A ?

tough thunder
#

So you need to schedule a function to run every second (stats.mcfunction), which should just

  • schedule itself to run in 1s
  • run a function B as all players

In function B, you put all the code you have currently in stats function (excluding the schedule command)

#

This is because the stats function will be executed as the server and not as a player, so you cant use @s

gleaming mesa
#

ok I understand this

tough thunder
#

Nice

tough thunder
gleaming mesa
#

the last line was to start the loop

#

I have to change it

tough thunder
#

Line 7 doesn't do anything but that's not the issue

gleaming mesa
#

nothing I would guess

tough thunder
#

Also what's in the tick function?

gleaming mesa
tough thunder
#

What's in the levelup detection function? :P

gleaming mesa
#

and that's the levelup_annoucement

tough thunder
#

It looks fine to me

gleaming mesa
#

yeah but

#

when I use a point to increase a stat

#

I lose it

#

and when I first start my stats function

#

it starts by setting up my hp, etc at the same value as my level

#

I think I should make another scoreboard (that I already made, I didn't use it)

#

to track the hp I get through the points

#

and make my real hp the hp + hp_p

#

would this work ?

tough thunder
#

Is the issue definitely caused by reloading? Can you set the points scoreboard to show on the sidebar and then /reload and see if it resets?

gleaming mesa
#

yeah sure, but I think it shouldn't

tough thunder
#

I don't understand

tough thunder
gleaming mesa
#

I'm probably not clear at all, I'm sorry

gleaming mesa
#

so, what happens is, let's say I hate 1 point

#

I use it, to increase health

#

hp = hp + 1

#

I lose the point

#

and when I first load stats.mcfunction, I have no point, so it doesn't increase my stat or anything

#

and it sets my hp to be the same as my level

tough thunder
#

Hmm

gleaming mesa
#

I think that's what happens and the reason why I lose a part of the progress

tough thunder
#

So HP needs to equal the player's level + however many points they spent on HP?

gleaming mesa
#

yeah

tough thunder
#

Okay

gleaming mesa
#

but I'm not too sure how to fix it, my guess would be that using a scoreboard that increases with the spent point

#

and make a sum with it and the hp I got with the level

tough thunder
#

You still only really need the one scoreboard just to track how many points have been spent on HP

gleaming mesa
#

yeah

tough thunder
#

That scoreboard should only ever increase when the player spends a point on it

#

Don't set it to level

#

Instead, set something else (like a temporary fake player) to the xp level, then add the points spent to that temporary score, then set the player's actual health to that score

gleaming mesa
#

I don't know how to make temporary fake player

#

even worse if there are multiple players using the datapack

tough thunder
gleaming mesa
#

oh nice ! :)

#

I would love it

tough thunder
gleaming mesa
#

ok :)

gleaming mesa
#

thank you very much ! :)

#

you are helping me a lot

tough thunder
#

The page is very in-dev and I'm not technically meant to share it yet but I make the rules so oh well

gleaming mesa
#

x)

tough thunder
#

So basically just exactly how you would do anything with normal players but instead of a selector just put #temp or smth

gleaming mesa
#

I'll have to do some research x)

#

I don't know what a selector is

tough thunder
#

They select players or entities

#

Hence the name

gleaming mesa
#

I should've guessed that

gleaming mesa
#

thx you so much

#

I want to give a shot to my 2 scoreboards solution too

#

and i'm going to try to learn the method you talked about

tough thunder
#

You don't need a scoreboard to track the players level because you can access it at any time with the xp command

gleaming mesa
#

I don't want to track the players level, I want to track the number of points spent in each stat

gleaming mesa
tough thunder
#

Assuming that the HP scoreboard tracks how many points have been spent on the HP stat, this should work:```
execute store result score #temp HP run xp query @s levels
scoreboard players operation #temp HP += @s HP

gleaming mesa
#

yeah this is just better :/

#

you are right

tough thunder
#

Basically just try and minimise all the scoreboard you use otherwise it'll get confusing real quick

gleaming mesa
#

you are right !

#

this is 1000x better

gleaming mesa
#

thx you so much

gleaming mesa
#

Is there a way to disable the output from the /trigger option, because the only option I find is disabling a gamerule (but it also disables other commands feedbacks)

twin horizon
#

Just the gamerule

#

You can enable it again after if you want

gleaming mesa
#

ok

#

also

#

this stays even after disabling the gamerule

#

is there a way not to have it ?

twin horizon
#

No, even with the gamerule disabled, any failed commands still send failure messages

#

If you want you could remove it with a resource pack, by overwriting the lang file

#

But frankly I wouldn't call it a big deal for must usecases

gleaming mesa
#

ok ty ! :)

gleaming mesa
#

is there a way to modify a player attribute accordingly to the value of a scoreboard ? I have found nothing about it ?

gleaming mesa
#

I found something, apparently I have to learn macros !

minor stoneBOT
tough thunder
#

I recommend closing it until you have a different problem

gleaming mesa
#

ok sorry

tough thunder
#

This threads getting very long and it's easier to just ask each time you have a specific issue :P

gleaming mesa
#

you are right, I apologize

#

I'm closing it rn

minor stoneBOT
#
Question Closed

Your question, #1321902874216763472 (Stats system), was resolved!

Original Message

#1321902874216763472 message

Duration open

2d38m