gnembon / scarpet

Public Repository of scarpet programs for Minecraft
Creative Commons Zero v1.0 Universal
359 stars 162 forks source link

Add AFK Display app #373

Open akaikagaribi opened 1 year ago

akaikagaribi commented 1 year ago

Grays out a player's name if they're not moving for 3 minutes (configurable). The functionality of this script is identical to that of Vanilla Tweaks' AFK Display datapack, but it saves what team a player was on before moving them to the AFK team, and puts them back in that team when they return.

We discovered that thing with AFK Display datapack when we started using teams, so I decided to write my own version in scarpet and publish it, because it may be useful for other people.

Ghoulboy78 commented 1 year ago

This looks like a really cool app, which could possibly be moved to useful category instead of survival, but idk.

akaikagaribi commented 1 year ago

Thank you for your feedback!

You can use __on_close() event to avoid writing to file each tick, which is rather slow and compute-expensive

That's a good suggestion, I've done it out of concern that it won't let it save in case of crash, but it seems that it will.

This works, but you could also use the entity_event('on_move') to detect when the player starts moving again. So basically, you have a map which is updated each time a player moves with the last time they move, and then uses schedule() to check if they still haven't moved after X ticks, and if so then mark them as afk.

This is also great, but despite trying to get better at scarpet by writing absurd scripts (with my main goal being to make poisonous potato the most OP item), I still can't get my head around the entity_event(). But this gave me an idea, so instead of using __on_tick() event and skipping 19 calls out of 20, I rewrote it that check_afk() runs on start and it also schedule()s for 20 ticks after, which is clearly more performance friendly way of doing this.

About moving it to useful category, I believe you meant utilities, and I personally think it belongs more to survival, but I can move it anywhere else for sure if necessary.

akaikagaribi commented 1 year ago

I've found a way to get rid of any I/O operations, which is to return a player to their team whenever they leave, also I've added a few settings, such as whether to mark fake players, shadow players, and the color of the afk_players team.