0

I want to make a PvP data pack for a Minecraft server, and I want it to function as follows: if a player is killed within half a minute of him hitting another player, they should drop all their items, but if they're killed without hitting another player they should keep their inventory. Is this possible? Also, if possible, I would want to do this without using command blocks.

2 Answers 2

3

The gamerule keepInventory can only be applied to the whole Minecraft world. But luckily there's also the /clear command. You can set /gamerule keepInventory true and then handle the inventory clearing with commands:

You can detect players who hit someone/got hit like this: Detect when player attacks another player

Then you can use a scoreboard of the deathCount type to find players who have died (and respawned) and use /clear to clear their inventory.

If you also want to clear their XP, you can use /xp set <player> 0.

4
  • Thanks, but I'm trying to do this without the use of command blocks, and even then I want them to drop their items, not delete them. Feb 13, 2019 at 15:54
  • Without using commands or without using command blocks? You can of course just make a function with the same commands. Without commands, it's impossible, just like keeping the inventory in general. Feb 14, 2019 at 9:22
  • I was thinking about doing that with a data pack and I'm pretty sure it is possible, but I don't know how. Feb 14, 2019 at 18:32
  • Yes, functions, as I said. They are part of data packs. But what's your reason for not wanting to use command blocks? Performance? Feb 14, 2019 at 18:37
2

I currently am working on a server-side Fabric mod which would entirely focus on such a matter. And even though it still only is in beta, you can still set a config to make it work properly, since making it work properly at first was the alpha version challenge.

You can actually find that mod right here. I'd also soon be publishing updates, as soon as I'll reach some real step in the development.

Here is a helpful description from the mod:

When any player dies, if the keepInventory vanilla gamerule is set to true, and the death matches any condition set in the blacklist, the player's inventory drops anyway. If set to false, the mod searches for matching death into the whitelist, and if it finds any, the player gets to keep its inventory. But here comes the second gamerule, conditionalDoVanishing, which makes it so that, when the player gets to keep its inventory despite the vanilla keepInventoory, and this gamerule is set to true, all the items with the Curse of Vanishing in their inventory still get to disappear in thin air.  Finally, when the server stops, the mod saves the config to the config file to make sure it matches the gamerules.

1
  • 3
    We are sorry that your post was deleted and restored. We would like to inform you that you need to be more careful about promoting your content on our sites: we don't tolerate users that are here just to drive traffic to their content. Please read our helpful guide on how to promote your content without being considered a spammer.
    – One 2 Many
    Sep 13, 2021 at 3:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .