From 0f7b1c7b28629608e9ec81b23c7bc52c3beffe87 Mon Sep 17 00:00:00 2001 From: Kagari Date: Thu, 27 Apr 2023 13:45:55 +0300 Subject: [PATCH 1/7] Add afk_display.sc description --- programs/survival/README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/programs/survival/README.md b/programs/survival/README.md index ca1f4169..f5649395 100644 --- a/programs/survival/README.md +++ b/programs/survival/README.md @@ -3,6 +3,12 @@ Various scripts that modify various game elements, often replicating popular mod ## Survival scarpet apps in alphabetical order with creator: +### [afk_display.sc](https://github.com/gnembon/scarpet/blob/master/programs/survival/afk_display.sc): +#### By akaikagaribi + 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. + ### [angel_block.sc](https://github.com/gnembon/scarpet/blob/master/programs/survival/angel_block.sc): #### By "Pegasus Epsilon" Reimplementation of Angel Blocks from RandomThings mod in scarpet 1.4. @@ -443,4 +449,5 @@ Various scripts that modify various game elements, often replicating popular mod Xendergo ch-yx Crec0 + akaikagaribi (Many more hopefully!) From 3a632149070b27866e4a93261f2916fd2e3f1f26 Mon Sep 17 00:00:00 2001 From: Kagari Date: Thu, 27 Apr 2023 13:46:50 +0300 Subject: [PATCH 2/7] Add AFK Display app --- programs/survival/afk_display.sc | 52 ++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 programs/survival/afk_display.sc diff --git a/programs/survival/afk_display.sc b/programs/survival/afk_display.sc new file mode 100644 index 00000000..818ac0a1 --- /dev/null +++ b/programs/survival/afk_display.sc @@ -0,0 +1,52 @@ +__config()->{ + 'scope'->'global', + 'stay_loaded'->true +}; + +global_teams = read_file('teams.json', 'json'); +if(global_teams == null, global_teams = write_file('teams.json', 'json', {}); global_teams = read_file('teams.json', 'json')); + +// Change these values to your liking +global_afk_prefix = ''; +global_afk_suffix = ''; +global_afk_timeout = 180; // seconds + +if(scoreboard('afkX') == null, scoreboard_add('afkX')); +if(scoreboard('afkY') == null, scoreboard_add('afkY')); +if(scoreboard('afkZ') == null, scoreboard_add('afkZ')); +if(scoreboard('afkScore') == null, scoreboard_add('afkScore')); +if(team_list('afk_players') == null, + team_add('afk_players'); + team_property('afk_players', 'color', 'gray'); + team_property('afk_players', 'prefix', global_afk_prefix); + team_property('afk_players', 'suffix', global_afk_suffix); +); + +// To run this only each second +global_tick = 0; +__on_tick()->( + if((global_tick + 1) % 20 != 0, global_tick += 1; return(), global_tick = 0); + for(player('*'), + //run('say ' + global_teams:0); + if(and( + scoreboard('afkX', _) == scoreboard('afkX', _, _~'pos':0), + scoreboard('afkY', _) == scoreboard('afkY', _, _~'pos':1), + scoreboard('afkZ', _) == scoreboard('afkZ', _, _~'pos':2); + ), + scoreboard('afkScore', _, scoreboard('afkScore', _) + 1), + scoreboard('afkScore', _, 0); + ); + if(scoreboard('afkScore', _) >= global_afk_timeout, + if(_~'team' == 'afk_players', continue()); + global_teams:_ = _~'team'; + write_file('teams.json', 'json', global_teams); + team_add('afk_players', _), + + if(_~'team' != 'afk_players', continue()); + if(global_teams:_, + team_add(global_teams:_, _), + team_leave(_); + ); + ); + ); +); From 104fb7a26087399a66e01f6c1c52a492b3634396 Mon Sep 17 00:00:00 2001 From: Kagari Date: Thu, 27 Apr 2023 13:52:37 +0300 Subject: [PATCH 3/7] Update afk_display.sc --- programs/survival/afk_display.sc | 1 - 1 file changed, 1 deletion(-) diff --git a/programs/survival/afk_display.sc b/programs/survival/afk_display.sc index 818ac0a1..16bb5428 100644 --- a/programs/survival/afk_display.sc +++ b/programs/survival/afk_display.sc @@ -27,7 +27,6 @@ global_tick = 0; __on_tick()->( if((global_tick + 1) % 20 != 0, global_tick += 1; return(), global_tick = 0); for(player('*'), - //run('say ' + global_teams:0); if(and( scoreboard('afkX', _) == scoreboard('afkX', _, _~'pos':0), scoreboard('afkY', _) == scoreboard('afkY', _, _~'pos':1), From c4738ef27252026c690c8687db6b730dd3d33ac7 Mon Sep 17 00:00:00 2001 From: Kagari Date: Thu, 27 Apr 2023 15:41:02 +0300 Subject: [PATCH 4/7] Get rid of __on_tick(), move write_file() --- programs/survival/afk_display.sc | 34 ++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/programs/survival/afk_display.sc b/programs/survival/afk_display.sc index 16bb5428..c0470cf4 100644 --- a/programs/survival/afk_display.sc +++ b/programs/survival/afk_display.sc @@ -1,15 +1,18 @@ -__config()->{ - 'scope'->'global', - 'stay_loaded'->true +__config() -> { + 'scope' -> 'global', + 'stay_loaded' -> true }; global_teams = read_file('teams.json', 'json'); -if(global_teams == null, global_teams = write_file('teams.json', 'json', {}); global_teams = read_file('teams.json', 'json')); +if(global_teams == null, + global_teams = write_file('teams.json', 'json', {}); + global_teams = read_file('teams.json', 'json'); +); // Change these values to your liking global_afk_prefix = ''; global_afk_suffix = ''; -global_afk_timeout = 180; // seconds +global_afk_timeout = 5; // seconds if(scoreboard('afkX') == null, scoreboard_add('afkX')); if(scoreboard('afkY') == null, scoreboard_add('afkY')); @@ -22,15 +25,12 @@ if(team_list('afk_players') == null, team_property('afk_players', 'suffix', global_afk_suffix); ); -// To run this only each second -global_tick = 0; -__on_tick()->( - if((global_tick + 1) % 20 != 0, global_tick += 1; return(), global_tick = 0); +check_afk() -> ( for(player('*'), if(and( - scoreboard('afkX', _) == scoreboard('afkX', _, _~'pos':0), - scoreboard('afkY', _) == scoreboard('afkY', _, _~'pos':1), - scoreboard('afkZ', _) == scoreboard('afkZ', _, _~'pos':2); + scoreboard('afkX', _) == scoreboard('afkX', _, _~'pos':0), + scoreboard('afkY', _) == scoreboard('afkY', _, _~'pos':1), + scoreboard('afkZ', _) == scoreboard('afkZ', _, _~'pos':2); ), scoreboard('afkScore', _, scoreboard('afkScore', _) + 1), scoreboard('afkScore', _, 0); @@ -38,7 +38,6 @@ __on_tick()->( if(scoreboard('afkScore', _) >= global_afk_timeout, if(_~'team' == 'afk_players', continue()); global_teams:_ = _~'team'; - write_file('teams.json', 'json', global_teams); team_add('afk_players', _), if(_~'team' != 'afk_players', continue()); @@ -48,4 +47,13 @@ __on_tick()->( ); ); ); + schedule(20, 'check_afk'); +); + +__on_start()->( + check_afk(); +); + +__on_close()->( + write_file('teams.json', 'json', global_teams); ); From 478b32834a65257e1fb2fceea16867bc3c6e1fb7 Mon Sep 17 00:00:00 2001 From: Kagari Date: Thu, 27 Apr 2023 15:44:37 +0300 Subject: [PATCH 5/7] Fix timeout --- programs/survival/afk_display.sc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/survival/afk_display.sc b/programs/survival/afk_display.sc index c0470cf4..e34e9493 100644 --- a/programs/survival/afk_display.sc +++ b/programs/survival/afk_display.sc @@ -12,7 +12,7 @@ if(global_teams == null, // Change these values to your liking global_afk_prefix = ''; global_afk_suffix = ''; -global_afk_timeout = 5; // seconds +global_afk_timeout = 180; // seconds if(scoreboard('afkX') == null, scoreboard_add('afkX')); if(scoreboard('afkY') == null, scoreboard_add('afkY')); From 86bb1effb13a891bb3f017a111cb404e6b9cca61 Mon Sep 17 00:00:00 2001 From: Kagari Date: Thu, 27 Apr 2023 21:48:53 +0300 Subject: [PATCH 6/7] Fix getting "returned" in the wrong team --- programs/survival/afk_display.sc | 1 + 1 file changed, 1 insertion(+) diff --git a/programs/survival/afk_display.sc b/programs/survival/afk_display.sc index e34e9493..b89319d9 100644 --- a/programs/survival/afk_display.sc +++ b/programs/survival/afk_display.sc @@ -37,6 +37,7 @@ check_afk() -> ( ); if(scoreboard('afkScore', _) >= global_afk_timeout, if(_~'team' == 'afk_players', continue()); + delete(global_teams, _); global_teams:_ = _~'team'; team_add('afk_players', _), From f51fe5a7390cf5635efa33effa79ac32f319f8e5 Mon Sep 17 00:00:00 2001 From: Kagari Date: Fri, 28 Apr 2023 11:24:00 +0300 Subject: [PATCH 7/7] Get rid of I/O whatsoever --- programs/survival/afk_display.sc | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/programs/survival/afk_display.sc b/programs/survival/afk_display.sc index b89319d9..dc25db1b 100644 --- a/programs/survival/afk_display.sc +++ b/programs/survival/afk_display.sc @@ -3,16 +3,15 @@ __config() -> { 'stay_loaded' -> true }; -global_teams = read_file('teams.json', 'json'); -if(global_teams == null, - global_teams = write_file('teams.json', 'json', {}); - global_teams = read_file('teams.json', 'json'); -); +global_teams = {}; // Change these values to your liking global_afk_prefix = ''; global_afk_suffix = ''; global_afk_timeout = 180; // seconds +global_afk_color = 'gray'; +global_afk_fake_players = true; // Mark fake players as AFK +global_afk_shadow_players = true; // Mark shadow players as AFK if(scoreboard('afkX') == null, scoreboard_add('afkX')); if(scoreboard('afkY') == null, scoreboard_add('afkY')); @@ -20,13 +19,15 @@ if(scoreboard('afkZ') == null, scoreboard_add('afkZ')); if(scoreboard('afkScore') == null, scoreboard_add('afkScore')); if(team_list('afk_players') == null, team_add('afk_players'); - team_property('afk_players', 'color', 'gray'); + team_property('afk_players', 'color', global_afk_color); team_property('afk_players', 'prefix', global_afk_prefix); team_property('afk_players', 'suffix', global_afk_suffix); ); check_afk() -> ( for(player('*'), + if(and(_~'player_type' == 'fake', !global_afk_fake_players), continue()); + if(and(_~'player_type' == 'shadow', !global_afk_shadow_players), continue()); if(and( scoreboard('afkX', _) == scoreboard('afkX', _, _~'pos':0), scoreboard('afkY', _) == scoreboard('afkY', _, _~'pos':1), @@ -51,10 +52,16 @@ check_afk() -> ( schedule(20, 'check_afk'); ); -__on_start()->( +__on_start() -> ( check_afk(); ); -__on_close()->( - write_file('teams.json', 'json', global_teams); +__on_player_disconnects(player, reason) -> ( + if(player~'team' == 'afk_players', + scoreboard('afkScore', player, 0); + if(global_teams:player, + team_add(global_teams:player, player), + team_leave(player); + ); + ); );