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

Update speed.sc #375

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all 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
64 changes: 26 additions & 38 deletions programs/survival/speed.sc
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,36 @@
//By: Ghoulboy

// stay loaded
__config() -> (
m(
l('stay_loaded','true')
)
);

import('math','_euclidean');

//Funcs

__setup_player(player)->(
global_prevpos:player=pos(player);
global_pos:player=pos(player);
entity_event(player,'on_tick','__display')
);

__display(player)->(
if(tick_time()%global_refresh_rate==0,
global_pos:player=pos(player);
__config() -> {
'stay_loaded'->true
};

speed=_euclidean(global_pos:player,global_prevpos:player)*20/global_refresh_rate;
scoreboard('Speed',player,roundmath(speed*1000,1));
import('math', '_euclidean', '_round');

global_prevpos:player=pos(player)
)
__command() -> if(global_active = !global_active,
display_title(player(), 'actionbar', 'Speed display active');
global_pos = pos(player());
display_speed(),
display_title(player(), 'actionbar', 'Speed display inactive')
);

__on_player_connects(player)->__setup_player(player);

roundmath(num,precision)->return(round(num/precision)*precision);

//Initial code

global_active = false;
global_refresh_rate = 5; //refresh once every 5 ticks
global_pos = null;
scoreboard_add('Speed');
scoreboard_display('sidebar','Speed');
global_prevpos={};
global_pos={};
global_refresh_rate=20;


print('Divide number on the side of the screen by 1000 to get actual speed in m/s!');

for(player('*'),
__setup_player(_)
display_title(player(), 'actionbar','Divide number on the side of the screen by 1000 to get actual speed in m/s!');

display_speed()->(
distance = _euclidean(global_pos, pos(player()));
speed = distance * 20 / global_refresh_rate;
//display_title(player(), 'title', '', 0, global_refresh_rate, global_refresh_rate/2+1);
//display_title(player(), 'subtitle', _round(speed, 0.001), 0, global_refresh_rate, global_refresh_rate/2+1);
scoreboard('Speed',player,_round(speed*1000,1));
global_pos = pos(player());
if(global_active,
schedule(global_refresh_rate, 'display_speed')
)
);

__on_server_shuts_down()-> scoreboard_remove('Speed');