#Stats system
1 messages · Page 1 of 1 (latest)
<@&1201956957406109788>
💬 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
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 ?
yep correct
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 ?
execute store result score ... run xp query @s levels
ok great, thx you !
what are the 3 dots for ?
the score name
Replace that with your scoreboard and a fake player
dam you're fast Sila
So like score .current_levels some_scoreboard
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 ?
You need to, in each tick, run a function as all players which does this:
- store the current_level
- check if it is higher than the previous_level and if it is then do something
- set previous_level to current_level
Do this in a separate function then in the tick function run that function as @a
Np
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"}}
Thx you !
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
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 ...
Learn how to set up/enable the /trigger command in this Minecraft command tutorial for 1.16+ (working in 1.19). I'll show you how to avoid "you cannot trigger this objective yet" (that's where most people get stuck.) /trigger is the closest thing we've got to custom commands in vanilla Minecraft. It's used a lot in /tellraw and books, whenever y...
Really ? I played a CTM named Final Paradox where you could unlock abilities by spending a "perk point" by clicking a button in the chat
I wanted to do something similar :(
Yes - /trigger fixes this
Any player can run /trigger
But only players with op can run /function
Ok tysm, I'm going to learn how to do that now
All /trigger does is it lets a player set their own score on a scoreboard
Then you can detect the change in that scoreboard and do something, like this
so, I'd have to constantly check the scoreboard value in tick.mcfunction ?
yea
oh I get it
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 ?
oh that's legitimoose, this guy saved me with scoreboards x)
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
You also need to check that the player actually has point(s) to spend when they click the button
I have a system in mind for that
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
each time he levels up, it adds +1 to a scoreboard, and I check if the scoreboard value is >=1
yea
and then, I remove 1 from the value
thatll do it
yea
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 ?
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
oh yeah, that was the fundamental thing I was misunderstanding
so I will have 1 scoreboard for each stat then ?
one for strength, another one for health, etc etc ?
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)
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)
wdym?
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
so hp = xp levels + points in a specific stat?
yeah
then yeah you will
:(
It's not too hard tho:```ansi
[30m# Get player's xp level
[35mexecute [34mstore result score [36m.hp [0msome_objective [34mrun [35mxp [34mquery [36m@s [34mlevels
[30m# Add stats point
[35mscoreboard [34mplayers operation [36m.hp [0msome_objective [34m+= [36m@s [0m<stat scoreboard>
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
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
I don't really know how to do this tho
a tick function that works every 20 ticks or something ?
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
so, I'll also have to run this function in load.mcfunction to start the cycle right ?
yeah just to set it going
np
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
it's not
alright where is it being run?
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
and do you run stats.mcfunction in chat?
I didn't try that, I just typed the command manually in chat
hm
= is used for comparing two scoreboards
You just want to check if it is more than 1, so use matches 1..
ok, thx you for the explanation ! :)
or an interval ?
yea
Yeah I had that thought in my mind, but I dont know too much about scoreboard operations
well fixed value being the range of numbers in this case
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
It made perfect sense
thx you so much :)
now, I just need to figure out how to make clickable text
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
This has a good tellraw editor for that
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
That’s fair, though in reality, advanced datapack developers just use the editor for convenience
But basically lemme explain
Yeah, from what I learned, it's annoying json stuff. I just want to understand the tool before using it
The JSON text in /tellraw can have a click_event field, like so: ```ansi
/tellraw @s {"text":"click me!!",[2;32m[2;34m[2;32m"click_event":{"action":"run_command","value":"/whatever_command"}[0m[2;34m[0m[2;32m[0m[2;33m[0m}
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
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)
Use an array of JSON text components
ok I'm going to look into it
Maybe I did something wrong, but I typed
/tellraw @s {"text":"click me!!","click_event":{"action":"run_command","value":"/kill @p"}} (your command but I just put a command instead of nothing)
and it doesn't do anything ?
did I do something wrong ?
I get the message in the chat !
but when I click on it, nothing happens
Gimme a sec
yeah sure !
Mb it's clickEvent and not click_event
So from what I understand,
/tellraw @s [{...},{...},...] ?
Ok thx you :)
Yeah basically
it worked ! :)
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 ["",{...},{...}]
why is it a thing tho ? x)
but ty for the tips, I know I would've pulled all my hair out because of this x)
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)
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 ?
and this part just doesn't work ?
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
this one is better (but still broken)
when i manually start the function, it does nothing
What if points is more than 1?
it doesn't do anything...
I have to replace ..1 by 1.. ?
nah dw, it's always confusing
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)
it still doesn't seem to work ?
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
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
No
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 :/
Just in the stats function, run a execute as @a run function <something>
And in that function, you can do the scoreboard stuff
wait I'm having a hard time understanding this
Stats function itself needs to run a different function, because /schedule can't execute a function as a player
so I have to create a loop between 2 function ?
Function A stats function B which starts function A ?
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
ok I understand this
Nice
and about this ?
What's in your load function?
Line 7 doesn't do anything but that's not the issue
Really ? What would be the default value if I don't set it up ?
nothing I would guess
The issue is the same as the issue before - this function is executed as the server, so @s doesnt exist
Also what's in the tick function?
oh yeah you are right
What's in the levelup detection function? :P
It looks fine to me
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 ?
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?
yeah sure, but I think it shouldn't
I don't understand
You said that reloading resets the scores
I'm probably not clear at all, I'm sorry
let me rephrase it, I think I got confused somewhere in my explanation
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
Hmm
I think that's what happens and the reason why I lose a part of the progress
So HP needs to equal the player's level + however many points they spent on HP?
yeah
Okay
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
You still only really need the one scoreboard just to track how many points have been spent on HP
yeah
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
I don't know how to make temporary fake player
even worse if there are multiple players using the datapack
I wrote a guide on that a couple of hours ago, lemme find it
That's not an issue - the function is ran once per person, not at the same time
ok :)
The page is very in-dev and I'm not technically meant to share it yet but I make the rules so oh well
x)
So basically just exactly how you would do anything with normal players but instead of a selector just put #temp or smth
@s and @a are selectors
They select players or entities
Hence the name
I should've guessed that
I get it now !
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
It will work but I don't think it will be any easier
You don't need a scoreboard to track the players level because you can access it at any time with the xp command
I don't want to track the players level, I want to track the number of points spent in each stat
using more scoreboard*
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
Basically just try and minimise all the scoreboard you use otherwise it'll get confusing real quick
it works perfectly ! :)
thx you so much
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)
ok
also
this stays even after disabling the gamerule
is there a way not to have it ?
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
ok ty ! :)
is there a way to modify a player attribute accordingly to the value of a scoreboard ? I have found nothing about it ?
I found something, apparently I have to learn macros !
If your question is resolved, that's great to hear! Make sure to run /resolve or click the Resolve Question button. Otherwise, feel free to continue asking for help! :D
I recommend closing it until you have a different problem
ok sorry
This threads getting very long and it's easier to just ask each time you have a specific issue :P
Your question, #1321902874216763472 (Stats system), was resolved!
#1321902874216763472 message
2d38m