Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AFK Display app #373

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions programs/survival/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" <[email protected]>
Reimplementation of Angel Blocks from RandomThings mod in scarpet 1.4.
Expand Down Expand Up @@ -443,4 +449,5 @@ Various scripts that modify various game elements, often replicating popular mod
Xendergo
ch-yx
Crec0
akaikagaribi
(Many more hopefully!)
60 changes: 60 additions & 0 deletions programs/survival/afk_display.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
__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);
);

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('afkScore', _, scoreboard('afkScore', _) + 1),
scoreboard('afkScore', _, 0);
);
if(scoreboard('afkScore', _) >= global_afk_timeout,
if(_~'team' == 'afk_players', continue());
akaikagaribi marked this conversation as resolved.
Show resolved Hide resolved
delete(global_teams, _);
global_teams:_ = _~'team';
team_add('afk_players', _),

if(_~'team' != 'afk_players', continue());
if(global_teams:_,
team_add(global_teams:_, _),
team_leave(_);
);
);
);
schedule(20, 'check_afk');
);

__on_start()->(
check_afk();
);

__on_close()->(
write_file('teams.json', 'json', global_teams);
);