#execute if entity @s[predicate=survivalplus:targetinrange4] run function survivalplus:tools/stealth/gomelee
#execute if entity @s[predicate=survivalplus:targeted,predicate=!survivalplus:targetinrange4,scores={timer=1..}] run function survivalplus:tools/stealth/gorange
execute if entity @s[predicate=survivalplus:targetinrange4] run scoreboard players set @s timer 100
execute if entity @s[predicate=survivalplus:targetinrange4] run function survivalplus:tools/stealth/clear_invis
execute if entity @s[predicate=survivalplus:targeted,predicate=!survivalplus:targetinrange4,scores={timer=1..}] run function survivalplus:tools/stealth/reinvis

execute if entity @s[predicate=!survivalplus:targeted] run function survivalplus:tools/stealth/reinvis
execute as @s[scores={timer=0},predicate=!survivalplus:targetinrange4] run function survivalplus:tools/stealth/reinvis

execute if entity @s[nbt={HurtTime:10s}] run function survivalplus:tools/stealth/clear_invis

execute as @s[scores={timer=1..}] run scoreboard players remove @s timer 1


attribute @s[tag=!hide,nbt={active_effects:[{id:"minecraft:invisibility"}]}] movement_speed base set .1
data merge entity @s[tag=!hide,nbt={active_effects:[{id:"minecraft:invisibility"}]}] {Silent:0b}
tag @s[nbt={active_effects:[{id:"minecraft:invisibility"}]}] add hide
attribute @s[tag=hide,nbt=!{active_effects:[{id:"minecraft:invisibility"}]}] movement_speed base set .23
data merge entity @s[tag=hide,nbt=!{active_effects:[{id:"minecraft:invisibility"}]}] {Silent:0b}
tag @s[nbt=!{active_effects:[{id:"minecraft:invisibility"}]}] remove hide