#Issue with storing everyone's XP

1 messages · Page 1 of 1 (latest)

crude cairn
#

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

gusty solarBOT
#

<@&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

ruby flame
#

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

crude cairn
#

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

ruby flame
#

Nvm, I see that's a scheduled function

ruby flame
# crude cairn

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

crude cairn
ruby flame
#

For some reason I just don't see why that would be happening, but either way my proposed solution would resolve that

crude cairn
#

Oh yea im not sure lol

crude cairn
#

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.

ruby flame
#

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

crude cairn
#

Okay!

fluid trout
#

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)

fluid trout
#

that will prevent it from removing the levels of anybody who is offline

#

interesting idea btw, i like it :)

fluid trout
crude cairn
crude cairn
ruby flame
#

What specifically do you need more details on?

crude cairn
#

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

ruby flame
#

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?

crude cairn
#

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.

ruby flame
#

I mean, to implement my suggestion, yes you'd need to change some lines

crude cairn
#

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.

tardy scaffold
#

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.

crude cairn
#

Would this be correct for what you said for changing the first line

tardy scaffold
#

change score to $border and then it's correct

crude cairn
#

alright

crude cairn
#

Because with what I currently newly added the border seems just keep expanding constantly when you load in the world.

ruby flame
#

It's not correct, no

crude cairn
ruby flame
#

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

crude cairn
#

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"

ruby flame
#

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

crude cairn
#

so run a function in this function with execute as @a run function (whatever)

#

I hope i'm correct on that

ruby flame
#

Correct

crude cairn
#

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 :(

ruby flame
#

Yes because you still have mistakes

ruby flame
# crude cairn

This is still using the fake player where you should have an @s

ruby flame
ruby flame
# crude cairn

Additionally, you can remove the line after the previouslevel function here, because that's now getting handled in the previouslevel function

crude cairn
#

Alright I got it

#

all test it out now

#

alright well I did something wrong again

ruby flame
#

What behavior are you experiencing now?

#

Oh I see

ruby flame
# crude cairn

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)

crude cairn
#

still isn't working, it is not even doing anything with the border when I open the world now

ruby flame
#

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.

crude cairn
ruby flame
#

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

crude cairn
#

Well I do have it initially to add 5 levels when a player joins for the first time

ruby flame
#

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

crude cairn
#

yea that is the point so then the bigger the world border size is the more people you play with

ruby flame
#

Then it sounds like that works great 🙂

crude cairn
#

yup! The only issue is that the world border doesn't seem to exist even when the levels update

#

lol

crude cairn
#

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

ruby flame
#

OK, did you check the scores of yourself and the fake player like I suggested?

crude cairn
#

ill check rn

#

they are all at 0 lol

ruby flame
#

So that's clearly an issue higher up the food chain

crude cairn
#

I wonder if something is messed up in like the main function that's preventing all of it to run

ruby flame
#

Very possibly, you can help identify that by trying to run each function in-game. If any don't appear, they failed to validate

crude cairn
#

Okay so the level and prev level are both 5 as they should

#

the border diameter is -5?

ruby flame
#

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

crude cairn
#

it goes to -15 diameter

ruby flame
crude cairn
#

omg

#

the border is actually here now

ruby flame
#

Yeah I think that was my bad, that's what I get for trying to go into detail on mobile

crude cairn
#

I just gotta test and make sure the main issue with the leaving and joining problem is fixed

crude cairn
#

ill be honest though I still don't fully get how it works though lol

ruby flame
#

I can kinda run through the code in plain language in a bit

crude cairn
#

okay

crude cairn
#

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

ruby flame
#

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
ruby flame
#

But that is outside of the scope of this help thread and my familiarity

crude cairn
crude cairn
gusty solarBOT
#
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

gusty solarBOT
#
🗑️ 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.

gusty solarBOT
#
🗑️ 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.