How do you spawn an entity that can be linked to the player that spawned it in Minecraft 1.13?

Solution 1:

You could try to make a command chain where after the area effect cloud is spawned it summons a perminate, imobile, indistructable, invisible entity such as a armor stand next to or under or above the area effect cloud that has a tag which can then activate a command block with the sequence:

execute if entity @e[type=armor_stand,tag=...] run ...

Idk if this will work or helps at all but I hope it does.

Solution 2:

The best way I can think of is to assign a unique id to every player using the scoreboard system and then copy that id to the area of effect cloud.

To set this up, create the following objectives:

/scoreboard objectives add index dummy

/scoreboard objectives add global_temp dummy

initialize the global index: /scoreboard players set global index 1

and then, paste these into a command block chain (1 repeating and 3 chain command blocks):

enter image description here

execute as @a unless entity @s[scores={index=1..}] run scoreboard players set @s index 0

execute store success score global global_temp run scoreboard players operation @a[limit=1,sort=arbitrary,scores={index=0}] index = global index

execute if score global global_temp matches 1 run scoreboard players add global index 1

scoreboard players reset global global_temp

here is how the system works. When a player joins, the value of the global index is copied into the players index objective. Then, the value of "global_index" is increased by 1 so the next player who joins gets a higher number than the previous player. The first player will have an index of 1, the second an index of 2 and so on...

now you can store the index of the player to the area of effect cloud like this:

/execute as <area_of_effect_cloud> store result score @s index run scoreboard players get @p[distance=..5,limit=1,sort=nearest] index