So I have this datapack for that everyones level added up is the border size on the world. But upon them leaving the game it will update and decrease the border to the people that are only on. How could I like have a system that instead keeps the border size upon leaving, and only decreases it instead when they actually lose the levels
#Issue with storing everyone's XP
1 messages · Page 1 of 1 (latest)
<@&1201956957406109788>
Someone will come and help soon!
💬 While you wait, take this time to provide more context and details.
🙇 After a while, hit the Summon Helpers button to ping the helper team. They'll be happy to help you
✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve
This is a toughie. How are you currently making the worldborder the sum of everyone's levels?
It's definitely doable but would help to understand what the foundation is first
Here ill send the code on how it works since its a little hard to explain since i'm new at making datapacks and someone helped me with this.
At the start it makes these two scoreboards a level scoreboard and a dummy
the load function will also call this function which sets up on how it all works
this runs the set border function which adds it by 1 if a level is increased by one of the players
Nvm, I see that's a scheduled function
Trying to parse why this wouldn't just continually increase the worldborder even if players' levels don't change 🤔
Well, certainly what I would do rather than add the sum of all players' level score to the worldborder, is make a new dummy score that is level_temp or something.
Then for each player, run a function that:
- Runs a scoreboard operation that subtracts their level score from their level_temp score, and saves it to their level_temp score
- Then adds their level_temp score to the worldborder. (If it's negative, that will subtract it with no extra effort, and if it's 0 then nothing happens)
- THEN, sets their level_temp equal to their level
I'm on mobile so details a little more limited, apologies
well it makes sense its like adding all the players xp levels that are on the game currently to the world border and once someone leaves it doesn't detect that player in the scoreboard anymore and updates with only the players that are currently on with their xp levels
No yeah I understand what you described the problem to be
For some reason I just don't see why that would be happening, but either way my proposed solution would resolve that
Oh yea im not sure lol
All good! I'll be honest though I may need some more details to know exactly how this is gonna work
Maybe @tardy scaffold could help since he originally helped me make the functionality of this? I don't know if he has a different approach to this issue or not.
I'm on mobile so I can't easily get much more detailed, but if it doesn't get resolved by the time I'm at my computer I'll see what I can do
Okay!
its because youre basically just reseting the score and then adding all players' scores (using @a, which only detects online players 🙁)
it is kinda a tricky problem, but i think essentially what you want to do is something similar to what kano said
youll need to have a 2nd level score for every player that basically just stores what they had last time the world border updated (1 second ago at max ofc)
and rather than resetting the border have all players - the score they had added to the world border last time, then add their current level
that will prevent it from removing the levels of anybody who is offline
interesting idea btw, i like it :)
i basically just resaid exactly what kano said actually but had you add then subtract rather than subtract then add 💀 but hopefully i elaborated a bit more maybe
Thanks!
That does make sense yea I may need some help though implementing it since I’m still not super knowledgeable you don’t have to give the like exact commands because yk it would probably be good if I learned as I was making it.
What specifically do you need more details on?
I would say just the general commands on how I’m gonna do this. Just talk to me like I’m a beginner and like my knowledge of data packs / most commands are small because it is
I mean that does sound like you want me to write the commands for you, which I'm not going to be in a position to do. What specific part would you like more detail on?
Right now, I just need help with knowing whether I should change and delete some lines of the preexisting code, because I assume I need to with adding this new system.
I mean, to implement my suggestion, yes you'd need to change some lines
Yea i'm trying to say that i'm not confident on which lines should be removed.
would it just be the ones I highlighted here
and then the rest would just be kinda tweaked
I'm really not sure as I was super carried in making this, and its a little confusing on my side.
Add a new dummy scoreboard in your load function and call it something like prev_level.
You are correct in your assumption to change the highlighted lines but only the first one.
Replace it with a score operation (similar to line two) that uses the -= operator to subtract @a prev_level from $border diameter.
Leave line two unchanged.
Then add a new command in line 3 that executes a score operation as every player. It uses the = operator to set the players prev_level to the current level.
If you need some code examples, let me know.
change score to $border and then it's correct
alright
Is this correct?
Because with what I currently newly added the border seems just keep expanding constantly when you load in the world.
It's not correct, no
Could you please elaborate on what i'm doing wrong?
You're still adding the sum of all players' levels to the fake player, not the change in their levels. Furthermore, you're setting the fake player's prev_level score to every player's level score, which isn't doing anything
You need to do this
Sorry, I was just trying to follow what HeDeAn was trying to tell me
Would this be correct for "Runs a scoreboard operation that subtracts their level score from their level_temp score, and saves it to their level_temp score"
Almost, except you are subtracting all players level score from the fake player's prev_level score
You need to run a function from this function that's being executed as all players
Which then subtracts their own level score (@s) from their own prev_level score
And then all the rest of the stuff I said
so run a function in this function with execute as @a run function (whatever)
I hope i'm correct on that
Correct
Alright great
"And then add the level_prev score to the world border"
"THEN sets the previous level equal to their level"
Imma go test and see what happens with this but I likely did it wrong.
Yea it does like the exact same thing before where it just increases the border constantly :(
Yes because you still have mistakes
This is still using the fake player where you should have an @s
And so is this third command
Additionally, you can remove the line after the previouslevel function here, because that's now getting handled in the previouslevel function
2nd line of this function, swap prev_level and diameter.
Saving to the border's prev_level doesn't do anything useful, and the player doesn't have a diameter score set (presumably)
still isn't working, it is not even doing anything with the border when I open the world now
Well it shouldn't do anything when you open the world, just when someone's level changes.
If that isn't working, I can't tell from a cursory glance what the cause is at this time. I would recommend trying to troubleshoot in-game. Check what your level and prev_level scores are, what the fake player's scores are, then change levels and see if they've changed as expected. Etc.
Well no i was saying like the border size isn't even set to my level when I start the world which it should
Ah I see, yeah it isn't going to be set to your level anymore. The way this system will have to work is when the world/server is started for the first time (and therefore when any new players are at 0 levels), the worldborder will need to be set to some initial diameter (probably in the load function), and then it will only change when a player gains or loses levels
We've forgone dynamic updating to a set value (the sum of all player's levels) in favor of only updating when a change occurs
Well I do have it initially to add 5 levels when a player joins for the first time
Gotcha, so that is good in that you won't need to make the initial value set in the load function, BUT it does mean that the worldborder will probably always increase by 5 whenever a new player joins for the first time
yea that is the point so then the bigger the world border size is the more people you play with
Then it sounds like that works great 🙂
yup! The only issue is that the world border doesn't seem to exist even when the levels update
lol
Can you elaborate?
So even with my level being instantly set to 5 when creating a world the world border doesn't seem to go to 5
like visibly it doesn't do anything at all
OK, did you check the scores of yourself and the fake player like I suggested?
So that's clearly an issue higher up the food chain
I wonder if something is messed up in like the main function that's preventing all of it to run
Very possibly, you can help identify that by trying to run each function in-game. If any don't appear, they failed to validate
Okay so the level and prev level are both 5 as they should
the border diameter is -5?
Ah, that's a little surprising but I can see how
Go ahead and give yourself 10 levels real quick, just to confirm other stuff is working right
it goes to -15 diameter
Try changing the += on the second line here to a -=
Yeah I think that was my bad, that's what I get for trying to go into detail on mobile
I just gotta test and make sure the main issue with the leaving and joining problem is fixed
Thank you so much for helping me it works perfectly with leaving and joining now it saves the border size and only decreases when someone actually dies and loses levels
ill be honest though I still don't fully get how it works though lol
I can kinda run through the code in plain language in a bit
okay
Also I was kinda thinking for the border to always increase or decrease a block per second. To do this I would likely need to do previous level - level I just don't know how i'd do it for this part
Sorry, was a long game
Basically what you're doing is this:
- Every player is already tracking their current level
- Every second, each player is checking if their level score, which is tracking what the player's level is constantly, is equal to the last value that the data pack recorded their level was (prev_level score)
- If that score is different from their current level, the difference gets added to or subtracted from the worldborder
- Then, their new current level is saved as the prev_level value, to be checked again the next second
I would imagine you can probably just do some math and use macros to define the time argument of the worldborder command
But that is outside of the scope of this help thread and my familiarity
I see that makes much more sense
Alright I appreciate the help thanks so much again
Question Closed
Your question, #1202760099060392036 (Issue with storing everyone's XP), was resolved!
Original Message
So I have this datapack for that everyones level added up is the border size on the world. But upon them leaving the game it will update and decrease the border to the people that are only on. How could I like have a system that instead keeps the border size upon leaving, and only decreases it instead when they actually lose the levels
Duration open
1d7h25m
🗑️ Recycling Thread
This thread has been inactive for some time, so I'm going to archive it.
If you're still using the thread, just send a message and it'll pop back on the thread list.
🗑️ Recycling Thread
This thread has been inactive for some time, so I'm going to archive it.
If you're still using the thread, just send a message and it'll pop back on the thread list.