How can I keep a specific item in my inventory when I die?

Started by CBJaxxx on Wed, 03/08/2023 - 17:48

Topic category: Help with modding (Java Edition)

Last seen on 05:52, 3. Jun 2023
Joined Mar 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How can I keep a specific item in my inventory when I die?
Wed, 03/08/2023 - 17:48

I have a coin pouch that holds coins but I want to make it so that if the player dies they will keep their coin pouch and the coins in it, this may have something to do with itemstacks but there is very little documentation on how to use them especially for this purpose. can someone please make my week and help me solve this issue?

Last seen on 18:11, 31. May 2023
Joined Mar 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
To do that, I see one…
Fri, 03/31/2023 - 21:37

To do that, I see one solution :

Create a number variable type (I call [nb_item]) in PLAYER_PERSISTENT, set on 0.

Then create the following procedures :

- get the number of coin

Every tick of the player
if have [event/target entity] in his inventory [coin]
	set [nb_coin] to [get item's number in [coin]]

- remove coin from the world

When player death
remove [coin] from [event/target entity] inventory

- give the coin to the player when he reappear

When player reappear
repeat [nb_coin] times :
	Add [coin] to [event/target entity] inventory