Give a predetermined number as the amount of experience



  • I'm creating a datapack to give players experience for doing all kinds of stuff. As I am expanding, I've come to a point where it would be easier to keep track of the scores by having all the different amounts of experience stored in a single place. But I give the experience using a loop, as follows:

    execute as @a  
    run execute if score @s Cutting_Count = @s Cutting_XP 
    run experience add @s 1
    

    Is there a way to give a predetermined amount?



  • After a lot of research, I think there's no way of doing that directly. A solution would be making a function to check if a given score matches an interger.

    First create a dummy scoreboard:

    scoreboard objectives add XP_Amount dummy
    

    Then set a value and make it clear that it has limitations:

    # Min = 1 | Max = 10
    execute as @a run scoreboard players set @s XP_Amount 1
    

    Then run a function to check if it matches the given value:

    execute as @a run function skelun/give_xp
    

    The function would look like this:

    execute if score @s XP_Amount matches 1 run experience add @s 1
    execute if score @s XP_Amount matches 2 run experience add @s 2
    execute if score @s XP_Amount matches 3 run experience add @s 3
    execute if score @s XP_Amount matches 4 run experience add @s 4
    execute if score @s XP_Amount matches 5 run experience add @s 5
    execute if score @s XP_Amount matches 6 run experience add @s 6
    execute if score @s XP_Amount matches 7 run experience add @s 7
    execute if score @s XP_Amount matches 8 run experience add @s 8
    execute if score @s XP_Amount matches 9 run experience add @s 9
    execute if score @s XP_Amount matches 10 run experience add @s 10
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2