diff --git a/programs/survival/README.md b/programs/survival/README.md index 12a9c144..8776709f 100644 --- a/programs/survival/README.md +++ b/programs/survival/README.md @@ -418,10 +418,10 @@ Various scripts that modify various game elements, often replicating popular mod I suppose you could use it with TNT to send it smashing into things as a powerful and volatile weapon ### [waypoints.sc](https://github.com/gnembon/scarpet/blob/master/programs/survival/waypoints.sc): -#### By Firigion and boyenn - Adds a server-side waypoints system, where any player can add and teleport to waypoints that any player - creates. Permissions to teleport are highly customizable (see https://youtu.be/OF_hY1sTRYY). It also - features the ability to render a line in direction of a waypoint (see https://youtu.be/0N2qVahMD7s). +#### By Firigion, boyenn and foospils + Adds a server-side waypoints system that allows any player to add, list, track and teleport to waypoints that any player creates. + Permissions to teleport are highly customizable (see https://youtu.be/OF_hY1sTRYY). + Tracking is visualized via a floating sphere in the direction of the destination and/or the actionbar. ### [world_map.sc](https://github.com/gnembon/scarpet/blob/master/programs/survival/world_map.sc): #### By gnembon @@ -452,4 +452,5 @@ Various scripts that modify various game elements, often replicating popular mod ch-yx SurfingDude Crec0 + foospils (Many more hopefully!) diff --git a/programs/survival/waypoints.sc b/programs/survival/waypoints.sc index 506b9d7f..5fb757ce 100644 --- a/programs/survival/waypoints.sc +++ b/programs/survival/waypoints.sc @@ -1,349 +1,547 @@ +// Waypoints - Server wide waypoint system +// Originally by Firigion and boyenn +// Reworked by Rocka84 (foospils) +// v1.4.1 + global_waypoint_config = { - // Config option to allow players to tp to the waypoints ( Either via `/waypoint list` or `/waypoint tp` ) - // 0 : NEVER - // 1 : CREATIVE PLAYERS - // 2 : CREATIVE AND SPECTATOR PLAYERS - // 3 : OP PLAYERS - // 4 : ALWAYS - 'allow_tp' -> 2 + // Config option to allow players to tp to the waypoints ( Either via `/waypoint list` or `/waypoint tp` ) + // 0 : NEVER + // 1 : CREATIVE PLAYERS + // 2 : CREATIVE AND SPECTATOR PLAYERS + // 3 : OP PLAYERS + // 4 : ALWAYS + 'allow_tp' -> 1, + 'track_ticks' -> 1 }; -_can_player_tp() -> ( - global_waypoint_config:'allow_tp' == 4 || - ( global_waypoint_config:'allow_tp' == 3 && player()~'permission_level' > 1) || - ( global_waypoint_config:'allow_tp' == 1 && player()~'gamemode'=='creative') || - ( global_waypoint_config:'allow_tp' == 2 && player()~'gamemode_id'%2) -); -_is_tp_allowed() -> global_waypoint_config:'allow_tp'; // anything but 0 will give boolean true +config_file = read_file('config', 'JSON'); +if (config_file != null, ( + global_waypoint_config = global_waypoint_config + config_file; +)); -waypoints_file = read_file('waypoints','JSON'); -saveSystem() -> ( - write_file('waypoints', 'JSON', global_waypoints); -); -global_authors = {}; -global_dimensions = {'overworld'}; // so we only show waypoints in dimensions that have any; shoud also support custom ones -if(waypoints_file == null, - global_waypoints = {'Origin' ->[[0,100,0], 'Default waypoint', null, 'overworld']}; saveSystem(), - global_waypoints = waypoints_file; - map(values(global_waypoints), - if( (auth = _:2) != null, global_authors += auth); - global_dimensions += _:3 - ); +_set_config(key, value) -> ( + if (player()~'permission_level' < 2, _error('not allowed')); + if (!has(global_waypoint_config, key), _error('unknown config key')); + + if (value == null, ( + print(player(), format('bd\ \ ' + key, 'f \ \ » ', 'q ' + global_waypoint_config:key)); + return(); + )); + + global_waypoint_config:key = number(value); + write_file('config', 'JSON', global_waypoint_config); + run('/script load ' + global_app_name); ); + +global_default_settings = { + 'track_autodisable' -> -1, + 'track_indicator' -> 'both', + 'list_show_author' -> false, + 'list_default_dimension' -> 'current', + 'list_sort_by' -> 'name', +}; + global_settings=read_file('settings', 'JSON'); if(global_settings==null, global_settings={}); +_set_setting(key, value) -> ( + splayer = str(player()); + if(!has(global_settings, splayer), global_settings:splayer = {}); + + if (value == global_default_settings:key, + delete(global_settings:splayer, key), + global_settings:splayer:key = value + ); + write_file('settings', 'JSON', global_settings); +); + +_get_setting(player, key) -> ( + splayer = str(player()); + if(!has(global_settings, splayer), global_settings:splayer = {}); + if(has(global_settings:splayer, key), global_settings:splayer:key, global_default_settings:key); +); + +global_authors = {}; +global_dimensions = {}; global_track = {}; +global_to_delete = null; +global_app_name = system_info('app_name'); + +global_waypoints = read_file('waypoints', 'JSON'); +if(global_waypoints == null, ( + global_waypoints = {}; +),( + for(values(global_waypoints), ( + global_authors += _:2; + global_dimensions += _:3 + )); +)); -_get_list_item(name, data, tp_allowed, player) -> ( - desc = if(data:1, '^g ' + data:1); - cond_desc = if(!tp_allowed, desc); - selected = if(global_track:player == name, 'd X', 'd \ \ '); - if(global_track:player == name, - sel_action = str('!/%s track disable', system_info('app_name')); - sel_hover = str('^g Click to stop tracking'), - sel_action = str('!/%s track %s', system_info('app_name'), name); - sel_hover = str('^g Click to start tracking') - ); - item = ['w [', selected, sel_hover, sel_action, 'w ] ', 'by '+name , desc, str('w : %s %s %s ', map(data:0, round(_)))]; - if(tp_allowed, - item += str('!/%s tp %s', system_info('app_name'), name); - item += '^g Click to teleport!', - // if tp is not allowed, append descripti/read_fileon tooltip - item += desc - ); - if(data:2, - item += 'g by '; - item += cond_desc; - item += 'gb '+data:2; - //if(!_is_tp_allowed(), item += desc) - item += cond_desc; - ); - item +_save_waypoints() -> ( + write_file('waypoints', 'JSON', global_waypoints); ); -list(author) -> ( - player = player(); - if(author != null && !has(global_authors, author), _error(author + ' has not set any waypoints')); - print(player, format('bc === List of current waypoints ===')); - tp_allowed = _can_player_tp(); - for(global_dimensions, - current_dim = _; - dim_already_printed = false; - for(pairs(global_waypoints), - [name, data]= _; - if(current_dim== data:3 && (author == null || author==data:2), - if(!dim_already_printed, print(player, format('l in '+current_dim)); dim_already_printed=true); // to avoid printing dim header when filtering authors - print(player, format( _get_list_item(name, data, tp_allowed, player))) - ) - ) - ) +_can_player_tp() -> ( + global_waypoint_config:'allow_tp' == 4 || + ( global_waypoint_config:'allow_tp' == 3 && player()~'permission_level' > 1) || + ( global_waypoint_config:'allow_tp' == 1 && player()~'gamemode'=='creative') || + ( global_waypoint_config:'allow_tp' == 2 && player()~'gamemode_id'%2) ); +_is_tp_allowed() -> global_waypoint_config:'allow_tp'; // anything but 0 will give boolean true -del_prompt(name) -> ( - global_to_delete = name; - print(player(), format( - 'y Are you sure you want to delete ', - 'yb '+name, - 'y ? ', - 'lb [YES] ', - str('!/%s confirm_del', system_info('app_name')), - 'rb [NO]', - str('!/%s cancel_del', system_info('app_name')), - )) + +_distance(a, b) -> ( + segment = b - a; + sqrt((segment:0 * segment:0) + (segment:1 * segment:1) + (segment:2 * segment:2)); ); -confirm_del() -> ( - if(global_to_delete, - del(global_to_delete); - global_to_delete = null, - _error('No deletion to confirm') - ) + +_get_list_item(name, data, tp_allowed, show_author, player) -> ( + desc = if(data:1, '^g ' + data:1); + + selected = if(global_track:player == name, 'e ➡', 'w ●'); + if(global_track:player == name, ( + sel_action = str('!/%s track disable', global_app_name); + sel_hover = str('^g Stop tracking') + ), ( + sel_action = str('!/%s track %s', global_app_name, name); + sel_hover = str('^g Track') + )); + + coords = str('%s %s %s', map(data:0, round(_))); + + item = [ + selected, sel_hover, sel_action, + ]; + + if(tp_allowed, ( + put(item, null, [ + 't ⭇', str('!/%s tp %s', global_app_name, name), '^g Teleport' + ], 'extend'); + )); + + put(item, null, [ + 'yb '+name, sel_hover, sel_action, + desc, + 'w : ' + coords + ' (' + round(_distance(player~'pos', data:0)) + 'm)', '&' + coords, '^g Copy coords', + ], 'extend'); + + if(show_author && data:2, ( + put(item, null, [ + 'g by ', desc, + 'gb '+data:2, desc, + ], 'extend'); + )); + + item ); -cancel_del() -> ( - if(global_to_delete, - print(player(), str('Deletion of %s was cancelled', global_to_delete)); - global_to_delete = null, - _error('No deletion to confirm') - ) + +list(dimensions, author) -> ( + player = player(); + print(player, format([' \n', 'c ━═= ', 'bc Waypoints ','c =═━'])); + + if (length(global_waypoints) < 1, ( + print(player, '\nThere aren\'t any waypoints yet.'); + print(player, format('w Use ', 'be /' + global_app_name + ' add', '?/' + global_app_name + ' add', 'w to create the first one!')); + return(); + )); + + if ( + author == 'all', author = null, + author == 'myself', author = str(player) + ); + if (author != null, ( + if(!has(global_authors, author), ( + print(player, format('w \n Player ', 'bi ' + author, 'w has not set any waypoints yet.')); + return(); + )); + show_author = false; + ),( + show_author = _get_setting(player, 'list_show_author'); + )); + + if (dimensions == null || dimensions == 'null', dimensions = _get_setting(player, 'list_default_dimension')); + if ( + dimensions == 'current', dimensions = [player~'dimension'], + dimensions == 'all', dimensions = global_dimensions, + type(dimensions) != 'list', dimensions = split(',', dimensions) + ); + + tp_allowed = _can_player_tp(); + + if (_get_setting(player, 'list_sort_by') == 'distance', ( + waypoint_names = sort_key(keys(global_waypoints), _distance(player~'pos', global_waypoints:_:0)); + ),( + waypoint_names = sort(keys(global_waypoints)); + )); + + for (dimensions, ( + if (!has(global_dimensions, _), ( + print(player, format('r \nThere are no waypoints in dimension ', 'br ' + _)); + continue(); + )); + current_dim = _; + dim_already_printed = false; + for(waypoint_names, ( + if (current_dim == global_waypoints:_:3 && (author == null || author == global_waypoints:_:2), ( + if (!dim_already_printed, ( + print(player, format('l \n🌍 '+current_dim)); + dim_already_printed=true; + )); + print(player, format(_get_list_item(_, global_waypoints:_, tp_allowed, show_author, player))); + )); + )); + )); + print(player, ''); ); -del(name) -> ( - if(delete(global_waypoints,name), - global_track:player() = null; - print(player(), 'Waypoint ' + name + ' deleted.'), - //else, failed - _error('Waypoint ' + name + ' does not exist')); - saveSystem(); +delete_waypoint(name) -> ( + if (name == null, ( + if (global_to_delete != null, print(player(), format('w Waypoint ', 'b ' + global_to_delete, 'y not deleted.'))); + global_to_delete = null; + + ), global_to_delete == name, ( + global_to_delete = null; + delete(global_waypoints, name); + _save_waypoints(); + _exit('w Waypoint ', 'b ' + name, 'r deleted.'); + + ), !has(global_waypoints, name), ( + global_to_delete = null; + _exit('w Waypoint ', 'b ' + name, 'r does not exist.'); + + ), player()~'permission_level' < 2 && global_waypoints:name:2 != str(player()), ( + global_to_delete = null; + _exit('w Waypoint ', 'b ' + name, 'r is not your\'s.'); + + ), ( + global_to_delete = name; + + print(player(), format( + 'y Are you sure you want to delete ', 'yb '+name, 'y ? ', + 'lb [YES] ', str('!/%s delete %s', global_app_name, name), + 'rb [NO]', str('!/%s delete', global_app_name), + )); + )); ); add(name, poi_pos, description) -> ( - if( - name=='disable', - _error('That name is not available, it has a special funciton'), - - has(global_waypoints, name), - _error('You are trying to overwrite an existing waypoint. Delete it first.'), - // else, add new one - player = player(); - if(poi_pos==null, poi_pos=player~'pos'); - global_waypoints:name = [poi_pos, description, str(player), player~'dimension']; - global_authors += str(player); - global_dimensions += player~'dimension'; - print(player, format( - 'g Added new waypoint ', - str('bg %s ', name), - str('g at %s %s %s', map(poi_pos, round(_))), - )); - saveSystem(); - ); + if (name=='disable', ( + _error('That name is not available, it has a special function') + ), has(global_waypoints, name), ( + _exit('w Waypoint ', 'b ' + name, 'r already exists.', 'w Delete it first.'); + )); + + player = player(); + if (poi_pos==null, poi_pos = map(player~'pos', floor(_)) + [0.499, 0, 0.499]); // snap to center of block under player + global_waypoints:name = [poi_pos, description, str(player), player~'dimension']; + global_authors += str(player); + global_dimensions += player~'dimension'; + print(player, format( + 'g Added new waypoint ', + str('bg %s ', name), + str('g at %s %s %s', map(poi_pos, round(_))), + )); + _save_waypoints(); ); edit(name, description) -> ( - if(!has(global_waypoints, name), _error('That waypoint does not exist')); - global_waypoints:name:1 = description; - print(player(), format('g Edited waypoint\'s description')) + if(!has(global_waypoints, name), ( + _exit('w Waypoint ', 'b ' + name, 'r does not exist.'); + ), player()~'permission_level' < 2 && global_waypoints:name:2 != str(player()), ( + _exit('w Waypoint ', 'b ' + name, 'r is not your\'s.'); + )); + global_waypoints:name:1 = description; + print(player(), format('g Edited waypoint\'s description')) ); tp(name) -> ( - if(!_can_player_tp(), _error(str('%s players are not allowed to teleport', player()~'gamemode')) ); //for modes 1 and 2 - loc = global_waypoints:name:0; - dim = global_waypoints:name:3; - if(loc == null, _error('That waypoint does not exist')); - print('Teleporting ' +player()+ ' to ' + name); - run(str('execute in %s run tp %s %s %s %s', dim, player(), loc:0, loc:1, loc:2)); + if(!_can_player_tp(), _error(str('Teleporting not allowed in %s mode', player()~'gamemode')) ); + loc = global_waypoints:name:0; + dim = global_waypoints:name:3; + if(loc == null, _exit('w Waypoint ', 'b ' + name, 'r does not exist.')); + print('Teleporting ' +player()+ ' to ' + name); + run(str('execute in %s run tp %s %s %s %s', dim, player(), loc:0, loc:1, loc:2)); ); track(name) -> ( - player = player(); - if( - name==null , - print(player, format('g Stopped tracking direction')), - has(global_waypoints, name), - print(player, format(str('g Started tracking direction to %s', name))), - // else, not a name nor null - _error('Waypoint ' + name + ' does not exist') - ); - - global_track:player = name; - _track_tick(player); + player = player(); + if(name == null, ( + if (global_track:player != null, print(player, format('g Stopped tracking direction to ', 'gb ' + global_track:player))); + global_track:player = null; + + ), !has(global_waypoints, name), ( + _exit('w Waypoint ', 'b ' + name, 'r does not exist.'); + + // ), global_waypoints:(name):3 != player~'dimension', ( + // _exit('w Waypoint ', 'b ' + name, 'r is in another dimension.'); + + ), global_track:player != name, ( + print(player, format('g Tracking direction to ', 'gb ' + name)); + if (global_track:player == null, ( + global_track:player = name; + _track_tick(player); + ), ( + global_track:player = name; + )); + )); ); +// __on_player_changes_dimension(player, from_pos, from_dimension, to_pos, to_dimension) -> ( +// if (global_track:player, run('execute as ' + player + ' run ' + global_app_name + ' track disable')); +// ); + _track_tick(player) -> ( - splayer = str(player); - if(global_track:player, - schedule(1, '_track_tick', player), - display_title(player, 'clear'); - exit(); - ); - - if( (dim = global_waypoints:(global_track:player):3) == player~'dimension', - ppos = player~'pos'; - voffset = player~'eye_height'*0.6; - - width = if(!has(global_settings:splayer, 'width'), 2, global_settings:splayer:'width'); - length = if(!has(global_settings:splayer, 'length'), 2, global_settings:splayer:'length'); - - voff = [0,voffset,0]; - from = ppos + voff; - destination = global_waypoints:(global_track:player):0; - - to = destination-from; // vector joining form with destination - distance = sqrt(reduce(to, _*_+_a, 0)); - length = min(length, distance); - if(length==-1, length=distance); - - to = to * length/distance; - if(global_settings:splayer:'flat', to = to * [1, 0, 1] + voff); - - //create direction marker - if( global_settings:splayer:'particles', - particle_line('item spectral_arrow 0.8 0.1 1 4', ppos + player~'motion', ppos + to, 2, player), - draw_shape('line', 1, 'from', player~'motion' + voff, 'to', to, 'follow', player(), 'player', player, 'line', width) - ); - - // show distance and handkle auto turn off - if(global_settings:splayer:'distance', display_title(player, 'actionbar', str('Distance to %s: %.0fm', global_track:player, distance))); - if( (d = global_settings:splayer:'autodisable')!=-1 && distance <= d, - print(player, format('g You reached your destinaton!')); - global_track:player = null - ), - // else, print bad dimension - display_title(player, 'actionbar', str('Tracking %s in %s', global_track:player, dim) ) - ) + splayer = str(player); + if(global_track:player, ( + schedule(global_waypoint_config:'track_ticks', '_track_tick', player); + ),( + display_title(player, 'clear'); + exit(); + )); + + if(global_waypoints:(global_track:player):3 != player~'dimension', return()); + + track_ticks = global_waypoint_config:'track_ticks'; + + ppos = player~'pos'; + look = player~'look'; + eyes = [0, player~'eye_height', 0]; + destination = global_waypoints:(global_track:player):0; + + shape_distance = player~'eye_height'; + autodisable = _get_setting(player, 'track_autodisable'); + indicator = _get_setting(player, 'track_indicator'); + + distance = _distance(ppos, destination); //distance from players feet to destination + + if(autodisable > -1 && distance <= autodisable, ( + display_title(player, 'actionbar', format('g You reached your destination!')); + global_track:player = null; + return(); + )); + + segment = destination - (ppos + eyes); //vector from players eyes to the destination + direction = segment / sqrt((segment:0 * segment:0) + (segment:1 * segment:1) + (segment:2 * segment:2)); //vector divided by its length + + + if (indicator == 'rendered' || indicator == 'both', ( + if(distance <= shape_distance, ( + shape_pos = destination - ppos; + ),( + shape_pos = (shape_distance * direction) + eyes; //draw in _direction_ with _shape_distance_ relative to players _eyes_. + )); + + shapes = [ + [ + 'sphere', + track_ticks, + 'player', player, + 'follow', player, + 'center', shape_pos, + 'radius', 0.03, + 'color', 0x000000FF, + 'fill', 0xEE00FF44, + ], + [ + 'label', + track_ticks, + 'player', player, + 'follow', player, + 'pos', shape_pos, + 'height', 0.3, + 'text', format(['y ' + global_track:player]), + 'size', 3, + ], + ]; + if (indicator == 'rendered', ( + shapes += [ + 'label', + track_ticks, + 'player', player, + 'follow', player, + 'pos', shape_pos, + 'height', -0.3, + 'text', '(' + round(distance) + 'm)', + 'size', 2, + ], + )); + draw_shape(shapes); + )); + + if (indicator == 'text' || indicator == 'both', ( + dy = look:1 - direction:1; + char_y = if(dy > 0.05, '↓', dy < -0.05, '↑', ' '); + + if (floor(ppos:1) == floor(destination:1), char_y = '🚩'); + display_data = ['lb ']; + + if (indicator == 'text', display_data += 'y ' + global_track:player + ' '); + display_data += 'w ' + round(distance) + 'm '; + + scalar_xz = (look:0 * direction:2) - (look:2 * direction:0); + if(floor(ppos:0) == floor(destination:0) && floor(ppos:2) == floor(destination:2), ( + display_data:0 = 'lb 🚩'+char_y+' '; + display_data += 'lb '+char_y+'🚩'; + ), scalar_xz < -0.05, ( + display_data:0 = 'lb <'+char_y+' '; + display_data += 'lb '; + ), scalar_xz > 0.05, ( + display_data += 'lb '+char_y+'>'; + ), ( + display_data:0 = 'lb '+char_y+' '; + display_data += 'lb '+char_y+' '; + )); + + display_title(player, 'actionbar', format(display_data)); + )); ); help() -> ( - player = player(); - print(player, format('bd ==Help for the Waypoints app==')); - print(player, format(str('f the following commands are available with /%s', system_info('app_name')) )); - print(player, format('q \ \ add [] []', 'fb \ | ', 'g add a new waypoint at given position with given description')); - print(player, format('q \ \ del ', 'fb \ | ', 'g delete existing waypoint')); - print(player, format('q \ \ edit ', 'fb \ | ', 'g edit the description of an existing waypoint')); - print(player, format('q \ \ list []', 'fb \ | ', 'g list all existing waypoints, optionally filtering by author')); - print(player, format('q \ \ settings track [ ]', 'fb \ | ', 'g sets strack options')); - if(_is_tp_allowed(), print(player, format('q \ \ tp ', 'fb \ | ', 'g teleport to given waypoint'))); + player = player(); + print(player, format('bd ==Help for the Waypoints app==')); + print(player, format(str('f the following commands are available with /%s', global_app_name) )); + print(player, format('q \ \ add [] []', 'fb \ | ', 'g add a new waypoint at given position with given description')); + print(player, format('q \ \ del ', 'fb \ | ', 'g delete existing waypoint')); + print(player, format('q \ \ edit ', 'fb \ | ', 'g edit the description of an existing waypoint')); + print(player, format('q \ \ list [] []', 'fb \ | ', 'g list all existing waypoints, optionally filtering by dimensions and/or author')); + print(player, format('q \ \ settings [ ]', 'fb \ | ', 'g sets options')); + if(_is_tp_allowed(), print(player, format('q \ \ tp ', 'fb \ | ', 'g teleport to given waypoint'))); + if (player()~'permission_level' > 1, ( + print(player, format('q \ \ config ', 'fb \ | ', 'g get config option (admin only)')); + print(player, format('q \ \ config ', 'fb \ | ', 'g set config option (admin only)')); + )); ); _error(msg)->( - print(player(), format(str('r %s', msg))); - exit() + _exit(str('r %s', msg)) ); -_settings(key, value) -> ( - splayer = str(player()); - if(!has(global_settings, splayer), global_settings:splayer = {}); - global_settings:splayer:key = value; - write_file('settings', 'JSON', global_settings); +_exit(...msg) -> ( + print(player(), format(msg)); + exit(); ); -global_default_settings = { - 'type' -> {'name'->'particles', 'defaults'->['render', 'particle']}, - 'distance' -> {'name'->'distance', 'defaults'->['off', 'on']}, - 'autodisable' -> 'off', - 'length' -> 2, - 'width' -> 2, - 'flat' -> {'name'->'flat', 'defaults'->['false', 'true']}, -}; show_settings() -> ( - splayer = str(player()); - print(splayer, format('b Your current settings are:')); - for(keys(global_default_settings), - name = _; - if(has(global_default_settings:name, 'name'), //to grab the true name of a display name if they are different - key = global_default_settings:name:'name'; - default = global_default_settings:name:'defaults', - - key = name; - default = global_default_settings:name - ); - - is_default = !has(global_settings:splayer, key); - value = if(type(default)=='list', - default:(global_settings:splayer:key), - if(is_default, default, global_settings:splayer:key) - ); - if(name=='autodisable'&&value==-1, value=default); - if(name=='length'&&value==-1, value='inf'); - - modify_cmd = str('?/%s settings track %s ', system_info('app_name'), name); - modify_tlt = '^g Click me to modify!'; - print(splayer, format( - 'bd\ \ '+name, modify_tlt, modify_cmd, - 'f \ \ » ', modify_tlt, modify_cmd, - 'q '+value, modify_tlt, modify_cmd, - if(is_default, 'g \ (Unmodified value)') - )) - ); + splayer = str(player()); + if(!has(global_settings, splayer), global_settings:splayer = {}); + print(splayer, format('b Current settings:')); + for(sort(keys(global_default_settings)), ( + key = _; + if (has(global_settings:splayer, key), ( + is_default = false; + value = global_settings:splayer:key; + ),( + is_default = true; + value = global_default_settings:key; + )); + + if(key=='track_autodisable' && value==-1, value='off'); + + name = split('_', key); + category = name:0; + delete(name, 0); + name = join('_', name); + + modify_cmd = str('?/%s settings %s %s ', global_app_name, category, name); + modify_tlt = '^g Click to modify'; + + print(splayer, format( + 'bd\ \ '+category+' '+name, modify_tlt, modify_cmd, + 'f \ \ » ', modify_tlt, modify_cmd, + 'q '+value, modify_tlt, modify_cmd, + if(is_default, 'g \ (Unmodified value)') + )) + )); ); _get_commands() -> ( - base_commands = { - '' -> 'help', - 'del ' -> 'del_prompt', - 'confirm_del' -> 'confirm_del', - 'cancel_del' -> 'cancel_del', - 'add ' -> ['add', null, null], - 'add ' -> ['add', null], - 'add ' -> 'add', - 'edit ' -> 'edit', - 'list' -> ['list', null], - 'list ' -> 'list', - 'track ' -> 'track', - 'track disable' -> ['track', null], - //'settings track line vector' -> _() -> _settings('vector', true), - //'settings track line direction' -> _() -> _settings('vector', false), - 'settings track' -> 'show_settings', - 'settings track type particle' -> _() -> _settings('particles',true), - 'settings track type render' -> _() -> _settings('particles',false), - 'settings track distance on' -> _() -> _settings('distance',true), - 'settings track distance off' -> _() -> _settings('distance',false), - 'settings track autodisable off' -> _() -> _settings('autodisable', -1), - 'settings track autodisable ' -> _(d) -> _settings('autodisable', d), - 'settings track width ' -> _(w) -> _settings('width', w), - 'settings track length ' -> _(l) -> _settings('length', l), - 'settings track length inf' -> _() -> _settings('length', -1), - 'settings track flat ' -> _(b) -> _settings('flat', b), - }; - if(_is_tp_allowed(), put(base_commands, 'tp ', 'tp')); - base_commands; + base_commands = { + '' -> 'help', + 'delete' -> ['delete_waypoint', null], + 'delete ' -> 'delete_waypoint', + + 'add ' -> ['add', null, null], + 'add ' -> ['add', null], + 'add ' -> 'add', + 'edit ' -> 'edit', + + 'list' -> _() -> list(null, null), + 'list ' -> _(d) -> list(d, null), + 'list ' -> _(d,a) -> list(d, a), + + 'track ' -> 'track', + 'track disable' -> ['track', null], + + 'settings' -> 'show_settings', + 'settings track indicator ' -> _(t) -> _set_setting('track_indicator', t), + 'settings track autodisable off' -> _() -> _set_setting('track_autodisable', -1), + 'settings track autodisable ' -> _(d) -> _set_setting('track_autodisable', d), + 'settings list show_author ' -> _(v) -> _set_setting('list_show_author', v), + 'settings list default_dimension ' -> _(v) -> _set_setting('list_default_dimension', v), + 'settings list sort_by distance' -> _() -> _set_setting('list_sort_by', 'distance'), + 'settings list sort_by name' -> _() -> _set_setting('list_sort_by', 'name'), + }; + if(_is_tp_allowed(), put(base_commands, 'tp ', 'tp')); + if (player()~'permission_level' > 1, ( + put(base_commands, 'config ', ['_set_config', null]); + put(base_commands, 'config ', '_set_config'); + )); + base_commands; ); __config() -> { - 'scope'->'global', - 'stay_loaded'-> true, - 'commands' -> _get_commands(), - 'arguments' -> { - 'waypoint' -> { - 'type' -> 'term', - 'suggester'-> _(args) -> keys(global_waypoints), - }, - 'name' -> { - 'type' -> 'term', - 'suggest' -> [], // to make it not suggest anything - }, - 'description' -> { - 'type' -> 'text', - 'suggest' -> [], - }, - 'author' -> { - 'type' -> 'term', - 'suggester'-> _(args) -> keys(global_authors), - }, - 'distance' -> { - 'type' -> 'int', - 'suggest' -> [5, 10], - 'min' -> 0 - }, - 'width' -> { - 'type' -> 'int', - 'suggest' -> [5, 10], - 'min' -> 0 - }, - 'length' -> { - 'type' -> 'int', - 'suggest' -> [5, 10], - 'min' -> 0 - }, - } + 'scope'->'global', + 'stay_loaded'-> true, + 'commands' -> _get_commands(), + 'arguments' -> { + 'waypoint' -> { + 'type' -> 'term', + 'suggester'-> _(args) -> keys(global_waypoints), + }, + 'name' -> { + 'type' -> 'term', + 'suggest' -> [], // to make it not suggest anything + }, + 'description' -> { + 'type' -> 'text', + 'suggest' -> [], + }, + 'author' -> { + 'type' -> 'term', + 'suggester'-> _(args) -> ( + suggest = ['all', 'myself']; + put(suggest, 0, keys(global_authors), 'extend'); + suggest; + ), + }, + 'dimension' -> { + 'type' -> 'term', + 'suggester'-> _(args) -> ( + suggest = ['all', 'current']; + put(suggest, 0, keys(global_dimensions), 'extend'); + suggest; + ), + }, + 'distance' -> { + 'type' -> 'int', + 'suggest' -> [5, 10], + 'min' -> 0 + }, + 'value' -> { + 'type' -> 'bool', + }, + 'config' -> { + 'type' -> 'term', + 'suggester'-> _(args) -> keys(global_waypoint_config), + }, + 'config_value' -> { + 'type' -> 'term', + }, + 'type' -> { + 'type' -> 'term', + 'options' -> ['rendered', 'text', 'both'], + }, + } }; +