golden apple cap

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the community!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

HexiKat

New Member
Jun 16, 2023
9
0
1
so im trying to make a cap for golden apples on a server but it no workie :sob:

every 5 tick:
loop all players:
loop all items in loop-player's inventory:
if loop-item is golden apple:
set loop-item to {_gapcap}
if {_gapcap} > 25:
give loop-player 25 golden apple
 
Code:
every 5 tick:
    loop all players:
        set {_gap434} to 0
        loop all items in loop-player's inventory:
            if loop-item is golden apple:
                add item amount of loop-item to {_gap434}
        if {_gap434} > 25:
            set {_whatsthislol} to {_gap434} - 25
            loop {_whatsthislol} times:
                remove 1 golden apple from loop-player's inventory
                drop 1 golden apple at loop-player's location
            send "&cno u cant get more than 25 gaps srry" to loop-player
 
Code:
every 5 tick:
    loop all players:
        set {_gap434} to 0
        loop all items in loop-player's inventory:
            if loop-item is golden apple:
                add item amount of loop-item to {_gap434}
        if {_gap434} > 25:
            set {_whatsthislol} to {_gap434} - 25
            loop {_whatsthislol} times:
                remove 1 golden apple from loop-player's inventory
                drop 1 golden apple at loop-player's location
            send "&cno u cant get more than 25 gaps srry" to loop-player
It would probably be best not to loop every player's inventory every 5 ticks (Could be laggy). When it comes to testing events like this, it's easier to only call upon them when needed. In this case, I made a check for when a player consumes an apple. Then without doing much math, you can simply set the player's tool to 25 gapples.

Code:
on consume:
  if player's tool is a golden apple:
    set {_n} to item amount of player's tool
    if {_n} >= 26:
      set {_a} to 25 golden apple
      set player's tool to {_a}
      send "Sorry! You cannot have more than 25 golden apples!" to player
(This cuts your previous code down by 5 lines and would be more efficient for a server).