Reduce amount of HUD updates for visibility
The code shown here can be optimized by adding another check for a custom player attribute holding the status of the visibility as discussed here. The if clause can be extended by
and is_yes(visible) and
visible being the stored visibility.
else part of the clause needs another check for the HUD being showed already.