Solved Drop a certain amount of item upon death

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

    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!

R1_Derakhti

Member
Mar 15, 2025
3
0
1
25
Hello everyone I'm a Skript rookie. I've been trying to code a script when a player dies it drops half of his nether stars ( along with his other items ) and keeps the other half after respawning.
I have faced 2 errors and couldn't get any help from AI.

Code:
on death of player:
  set {_count} to number of nether star in victim's inventory  # <-- Use SINGULAR "nether star"
  if {_count} > 0:
    # Calculate halves
    set {_kept} to ({_count} + 1) div 2  # Rounded up for kept
    set {_dropped} to {_count} - {_kept} # Rounded down for dropped
    # Remove stars, drop half, keep half
    clear nether star from victim's inventory  # <-- Singular "nether star" here too
    drop {_dropped} of nether star at victim's location
    set {netherstar::%victim's uuid%} to {_kept}

on respawn:
  if {netherstar::%player's uuid%} is set:
    give {netherstar::%player's uuid%} of nether star to player
    delete {netherstar::%player's uuid%}

1742082269986.png


I appreciate any kind of help, Thanks.
 
Code:
on death of player:
    set {_count} to amount of nether stars in victim's inventory
    if {_count} > 0:
        set {_kept} to floor({_count} / 2)
        set {_dropped} to {_count} - {_kept}
        loop {_dropped} times:
            remove 1 nether star from victim's inventory
        drop {_dropped} of nether star at victim's location

this is another way to do it, pretty sure there's easier but this worked for me
 
  • Like
Reactions: R1_Derakhti
Code:
on death of player:
    set {_count} to amount of nether stars in victim's inventory
    if {_count} > 0:
        set {_kept} to floor({_count} / 2)
        set {_dropped} to {_count} - {_kept}
        loop {_dropped} times:
            remove 1 nether star from victim's inventory
        drop {_dropped} of nether star at victim's location

this is another way to do it, pretty sure there's easier but this worked for me
Your code REALLY helped me out get a few things done, thanks, but the default drop still happens, whether removing is with loop or "remove all nether star from victim's inventory"

right now it gives half of the amount when respawned, but it does nothing to the dropped amount, even I removed the drop function.
here is the code:

Code:
on death of player:
    set {_count} to number of nether star in victim's inventory
    if {_count} > 0:
        # Calculate halves
        set {_kept} to ceil({_count} / 2)
        set {_dropped} to {_count} - {_kept}

        remove all nether star from victim's inventory
        # Store the kept amount for respawn
        set {netherstar::%victim's uuid%} to {_kept}

on respawn:
    if {netherstar::%player's uuid%} is set:
        give {netherstar::%player's uuid%} of nether star to player
        delete {netherstar::%player's uuid%}
 
Hi, I think Ive found a solution for your problem. Try this and let me know :emoji_wink:
Code:
on death of player:
    set {_count} to number of nether stars in inventory of victim
    if {_count} > 1:
        remove all nether stars from the drops
        if {_count} is divisible by 2:
            set {_kept} to {_count} / 2
            drop {_kept} of nether stars at victim's location
        else:
            set {_kept} to ({_count} - 1) / 2
            drop ({_kept} + 1) of nether stars at victim's location
        set {netherstar::%victim's uuid%} to {_kept}

on respawn:
    if {netherstar::%player's uuid%} is set:
        give {netherstar::%player's uuid%} of nether star to player
        delete {netherstar::%player's uuid%}
I dont know how exactly do you want it, but i made it so if player has only 1 nether star it will drop it and the player will have nothing after respawn
And if player has odd number of nether stars (5, 7, 9, etc..) it will drop the bigger half and give him the smaller half so for example if he has 9 nether stars it will drop 5 and after respawn he gets 4
 
  • Like
Reactions: R1_Derakhti
Hi, I think Ive found a solution for your problem. Try this and let me know :emoji_wink:
Code:
on death of player:
    set {_count} to number of nether stars in inventory of victim
    if {_count} > 1:
        remove all nether stars from the drops
        if {_count} is divisible by 2:
            set {_kept} to {_count} / 2
            drop {_kept} of nether stars at victim's location
        else:
            set {_kept} to ({_count} - 1) / 2
            drop ({_kept} + 1) of nether stars at victim's location
        set {netherstar::%victim's uuid%} to {_kept}

on respawn:
    if {netherstar::%player's uuid%} is set:
        give {netherstar::%player's uuid%} of nether star to player
        delete {netherstar::%player's uuid%}
I dont know how exactly do you want it, but i made it so if player has only 1 nether star it will drop it and the player will have nothing after respawn
And if player has odd number of nether stars (5, 7, 9, etc..) it will drop the bigger half and give him the smaller half so for example if he has 9 nether stars it will drop 5 and after respawn he gets 4
Wow! This works like a charm! that is a nice approach. Actually it is just like how I wanted it to be. Thanks for your time problem solved :emoji_smile::emoji_ok_hand: