Event Supply Drop Not Working!

  • 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!

SoloHandCoder

Member
Jan 10, 2026
2
0
1
I was working on an event and i tried making a supply drop.
i wanted it to set a random slot in the chest to something i want but the chest is always empty and it doesnt say anything like that there isnt a chest that loaded or that it finished thanks heres my function :

code_language.skript:
function EventSpawnLootDrop(x: number, z: number):

  send "&c[Function : ""SpawnLootDrop""] &2: Spawning Supply Drop!" to {Event.Owner}
  send "&c[Function : ""SpawnLootDrop""] &2: %{_x}% %{_z}%" to {Event.Owner}

  set {_chunkloc} to location({_x}, 64, {_z}, world "Event")
  load chunk at {_chunkloc}

  wait 0.1 seconds

  set {_loc} to location({_x}, 255, {_z}, world "Event")
    
  set {_topLoc} to highest block at {_loc}
    
  set {_chestLoc} to block above {_topLoc}
 
  set block at {_chestLoc} to chest

  wait 10 ticks
 
  set {_inv} to inventory of block at {_chestLoc}

  if {_inv} is not set:
    send "&c[Function : ""SpawnLootDrop""] &2: Couldnt Spawn Loot Drop : Loot drop's inventory varible has been deleted or null!" to {Event.Owner}
    stop
 
  clear {_inv}

  set {_r} to random integer between 3 and 6
 
  loop {_r} times:
    wait 1 ticks

    if {_inv} is not set:
      stop
    
    chance of 20%:
      set {_slot} to random integer between 0 and 26
      
      while slot {_slot} of {_inv} is not air:
        wait 2 ticks
        set {_slot} to random integer between 0 and 26
      set {_amt} to random integer between 1 and 5
      EventAbilitySlot({_slot}, {_amt}, {_inv})
      wait 3 tick
      
    chance of 100%:
      set {_slot} to random integer between 0 and 26
      
      while slot {_slot} of {_inv} is not air:
        wait 2 ticks
        set {_slot} to random integer between 0 and 26
      set {_amt} to random integer between 1 and 5
      set slot {_slot} of {_inv} to {_amt} of iron ingot
      wait 3 tick
      
    chance of 20%:
      set {_slot} to random integer between 0 and 26

      while slot {_slot} of {_inv} is not air:
        wait 2 ticks
        set {_slot} to random integer between 0 and 26
      set {_amt} to random integer between 5 and 20
      set slot {_slot} of {_inv} to {_amt} of cooked beef
      wait 3 tick
      
    chance of 10%:
      set {_slot} to random integer between 0 and 26

      while slot {_slot} of {_inv} is not air:
        wait 3 ticks
        set {_slot} to random integer between 0 and 26
      set {_amt} to random integer between 1 and 5
      set slot {_slot} of {_inv} to {_amt} of golden apple
      wait 5 tick

  send "&c[Function : ""SpawnLootDrop""] &2: Spawned Loot Drop!" to {Event.Owner}
 
  wait 0.2 seconds
 
  EventChat("&2Supply drop at : %{_x}% %y-coordinate of {_chestLoc}% %{_z}%")


Im on 1.21.10 Paper
I have skript 2.13.2

and these are my addons for skript :

skript-simple-voice-chat = 1.0.3
skRayFall = 1.9.28
skNoise = 1.0
SkBee = 3.13.2
skript-logs = 0.1.3
SkJson = 5.4.1
Skent = 3.4.0
SkQuery = 4.3.2
 
There's mutliple things wrong I think, but the main issue I believe is that you are setting {inv} to a copy of inventory of the chest, when you modify that it doesn't automatically change the chest's inventory. I am not sure whatsoever, but I've been checking for half an hour an seems like it. Remember you can also ask for help directly on the discord, and will probably be easier and faster.
 
There's mutliple things wrong I think, but the main issue I believe is that you are setting {inv} to a copy of inventory of the chest, when you modify that it doesn't automatically change the chest's inventory. I am not sure whatsoever, but I've been checking for half an hour an seems like it. Remember you can also ask for help directly on the discord, and will probably be easier and faster.
oh okay thanks ill try that and next time ill ask on the discord thanks <3
 
oh okay thanks ill try that and next time ill ask on the discord thanks <3
code_language.skript:
# --- Main Function ---
function EventSpawnLootDrop(x: number, z: number):
    # 1. Coordinate & Chunk Preparation
    send "&c[System] &2Preparing Supply Drop at %{_x}%, %{_z}%..." to {Event.Owner}
    
    set {_loc} to location({_x}, 255, {_z}, world "Event")
    load chunk at {_loc}
    
    # 2. Block Placement
    set {_topLoc} to highest block at {_loc}
    set {_chestLoc} to block above {_topLoc}
    
    set block at {_chestLoc} to chest
    
    # Give the server a tiny moment to register the TileEntity (Chest State)
    wait 2 ticks
    
    set {_inv} to inventory of block at {_chestLoc}
    
    # Validation check
    if {_inv} is not set:
        send "&c[Error] Could not find inventory at %{_chestLoc}%!" to {Event.Owner}
        stop

    clear {_inv}

    # 3. Loot Generation Logic
    # We do the "rolls" instantly without waits to prevent the inventory reference from breaking.
    set {_rolls} to random integer between 3 and 6
    
    loop {_rolls} times:
        
        # Roll for Iron Ingots (100% chance per loop)
        set {_slot} to getEmptySlot({_inv})
        if {_slot} is not -1:
            set slot {_slot} of {_inv} to (random integer between 1 and 5) of iron ingot
            
        # Roll for Cooked Beef (20% chance)
        if chance of 20%:
            set {_slot} to getEmptySlot({_inv})
            if {_slot} is not -1:
                set slot {_slot} of {_inv} to (random integer between 5 and 20) of cooked beef
                
        # Roll for Golden Apples (10% chance)
        if chance of 10%:
            set {_slot} to getEmptySlot({_inv})
            if {_slot} is not -1:
                set slot {_slot} of {_inv} to (random integer between 1 and 5) of golden apple

        # Roll for Custom Ability (20% chance)
        if chance of 20%:
            set {_slot} to getEmptySlot({_inv})
            if {_slot} is not -1:
                # Ensure this function does not contain 'waits'
                EventAbilitySlot({_slot}, 1, {_inv})

    # 4. Final Notification
    send "&c[System] &2Supply Drop spawned successfully!" to {Event.Owner}
    EventChat("&2Supply drop landed at: %{_x}%, %y-coord of {_chestLoc}%, %{_z}%")

# --- Helper Function: Safely find an empty slot ---
# This prevents the "While" loop from hanging your server if the chest fills up.
function getEmptySlot(inv: inventory) :: number:
    set {_attempts} to 0
    while {_attempts} < 50:
        set {_s} to random integer between 0 and 26
        if slot {_s} of {_inv} is air:
            return {_s}
        add 1 to {_attempts}
    return -1 # Returns -1 if no slot found in 50 tries