death give item

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

jstn_7

Member
Jan 16, 2024
2
0
1
I want to give an item to a player if they have an item in their inventory when they die

My Full Code is

on load:
set {item::bcake} to cake named "&9&lBlindness Cake"
set {item::lcake} to cake named "&e&lLightning Cake"
set {item::rcake} to cake named "&d&lRegeneration Cake"

on death:
if victim's inventory contains {item::rcake}:
give victim {item::rcake}
 
2 problems with that code:
1) dead players can't have items
2) if you have 2 cakes its gonna give 1

instead you should make a list of items when they die
Code:
on death:
  victim is a player   # so we don't apply it to other mobs
  loop {item::*}:   # loop all cakes
    set {_amount} to amount of loop-value in player's inventory
    add ({_amount} of loop-value) to {respawn.items::%player's uuid%::*}
and then give the items on respawn
Code:
on respawn:
  give player {respawn.items::%player's uuid%::*}
  delete {respawn.items::%player's uuid%::*}
 
it says an error of cant loop my item because item is only a single value

2 problems with that code:
1) dead players can't have items
2) if you have 2 cakes its gonna give 1

instead you should make a list of items when they die
Code:
on death:
  victim is a player   # so we don't apply it to other mobs
  loop {item::*}:   # loop all cakes
    set {_amount} to amount of loop-value in player's inventory
    add ({_amount} of loop-value) to {respawn.items::%player's uuid%::*}
and then give the items on respawn
Code:
on respawn:
  give player {respawn.items::%player's uuid%::*}
  delete {respawn.items::%player's uuid%::*}
 
2 problems with that code:
1) dead players can't have items
2) if you have 2 cakes its gonna give 1

instead you should make a list of items when they die
Code:
on death:
  victim is a player   # so we don't apply it to other mobs
  loop {item::*}:   # loop all cakes
    set {_amount} to amount of loop-value in player's inventory
    add ({_amount} of loop-value) to {respawn.items::%player's uuid%::*}
and then give the items on respawn
Code:
on respawn:
  give player {respawn.items::%player's uuid%::*}
  delete {respawn.items::%player's uuid%::*}
/gamerule keepinventory true
also smh imagine spoonfeeding