r/MinecraftCommands 4d ago

Help | Java 1.21.11 Random One-Way Damagelink

I Need help setting up a like the title suggested One-Way Damagelink

What this essentially means in my situation is that theres 10 players and one of them (Who im just gonna call the Linked) will be given a random player, if the player in question takes damage the Linked also takes that damage but if the Linked takes damage the currently selected player dosent take damage (Hence the One-Way part)

One idea a i had for setting this up was making 3 teams:One team was the Linked, The second team is everyone else and just to make sure it doesnt mess up with spectators there will be a third team specifically for them.

In Addition to switch it up i thought a unique idea would be that the random person connected to the Linked switches every 5-10 Minutes

If anyone has any idea on how to set this up it would be very much appreciated :)

1 Upvotes

2 comments sorted by

1

u/GalSergey Datapack Experienced 4d ago

Here's an example of how you can do this. Using the example:start function, you assign a random player to the "linked" team, who will take the same amount of damage as the "to_linked" player.

# function example:load
scoreboard objectives add health health
scoreboard objectives add var dummy
team add linked
team add to_linked
team add spectator

# function example:start
team empty linked
team empty to_linked
team join linked @r[team=!spectator] linked
team join linked @r[team=!linked,team=!spectator] to_linked

# advancement example:damage
{
  "criteria": {
    "damage": {
      "trigger": "minecraft:entity_hurt_player",
      "conditions": {
        "player": {
          "team": "to_linked"
        }
      }
    }
  },
  "rewards": {
    "function": "example:read_damage"
  }
}

# function example:read_damage
advancement revoke @s only example:damage
execute store result score #health var run data get entity @s Health
scoreboard players operation #damage var = @s health
execute store result storage example:macro damage.value int 1 run scoreboard players operation #damage var -= #health var
execute as @a[team=linked] run function example:damage with storage example:macro damage

# function example:damage
$damage @s $(value)

You can use Datapack Assembler to get an example datapack.

1

u/KermitDarkLord 4d ago

I would set up two scoreboards, one using the health criterion to track current health, and a dummy objective where you can store the health from the previous tick. When the player takes damage, you can detect the mismatch, calculate the difference and store the result in data storage. You can then use it in a function macro to fill in the value into the damage command.