Skip to content

Tputils: Home and Warps #335

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions programs/survival/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ Various scripts that modify various game elements, often replicating popular mod
There is a video on his channel about this.
https://www.youtube.com/watch?v=g7Ku73ElDBs
Cos im too lazy to write all the shit down.

### [tpUtils.sc](https://github.com/gnembon/scarpet/blob/master/programs/survival/tpUtils.sc):
#### By SurfingDude
Adds homes and warps. All tasks(like adding, deleting, teleporting, etc) can be done via commands.
Additionally listing and teleporting to other warps/homes can be done through a gui.

### [updater.sc](https://github.com/gnembon/scarpet/blob/master/programs/survival/updater.sc):
#### By Firigion
Expand Down Expand Up @@ -418,4 +423,5 @@ Various scripts that modify various game elements, often replicating popular mod
Opsaaaaa
Xendergo
ch-yx
SurfingDude
(Many more hopefully!)
283 changes: 283 additions & 0 deletions programs/survival/tputils.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
global_max_homes = 20; //Edit to allow more/less homes
global_operator_permission_level = 2;

__config()->{
'scope' -> 'global',
'commands' ->
{
'home add <nameh>' -> '_hadd',
'home tp <hlocation>' -> '_htp',
'home remove <hlocation>' -> '_hremove',
'home list' -> '_hlist',
'warp add <namew> <description>' -> '_wadd',
'warp tp <wlocation>' -> '_wtp',
'warp remove <wlocation>' -> '_wremove',
'warp menu' -> '_wmenu'
},
'arguments' ->
{
'hlocation' -> {
'type' -> 'text',
'suggester' -> _(args) -> (
keys(global_hdata:str(player()~'uuid'))
),
'case_sensitive' -> false
},

'nameh' -> {
'type' -> 'text',
'suggest' -> ['Spawn','Base','End Portal','Nether Portal'],
'case_sensitive' -> false
},

'namew' -> {
'type' -> 'string',
'suggest' -> ['Spawn','Marketplace','Arena'],
'case_sensitive' -> false
},

'description' -> {
'type' -> 'text'
},

'wlocation' -> {
'type' -> 'text',
'suggester' -> _(args) -> (
keys(global_wdata)
),
'case_sensitive' -> false
}
}
};


//Initializing homes and warps data

if(read_file('hdata','JSON') == null,
global_hdata = {},
//else when file already exists
global_hdata = read_file('hdata','JSON');;
);
if(read_file('wdata','JSON') == null,
global_wdata = {},
//else when file already exists
global_wdata = read_file('wdata','JSON');;
);



//Home functions

_hadd(name) -> (

player=player();
uuid = str(player~'uuid');

if(length(global_hdata:uuid)>global_max_homes,
print(player,format('r Max numbers of homes achieved. Please update/delete an existing one.'));
return();
);
if(global_hdata:uuid==null,global_hdata:uuid={});
global_names = keys(global_hdata:uuid);
if(global_names~name!=null, print(player,format(str('r %s is already in use. Therefore, updating the old home to new location. \n',name))));

global_hdata:uuid:name={};
global_hdata:uuid:name:'location' = pos(player);
global_hdata:uuid:name:'pitch' = player~'pitch';
global_hdata:uuid:name:'yaw' = player~'yaw';
global_hdata:uuid:name:'dimension' = player~'dimension';
_saveHData();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as with another pr u've done I think, I think you should do saveData in __on_close() and that's it to avoid re-writing to disk a bunch of times

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yh imma change this

print(player,format('e Succesfully saved home to location with name: '+name));
);

_htp(name) -> (

info = global_hdata:str(player()~'uuid'):name;
if(info==null,
print(player,format('r \nThe specefied location does not exist. Please use home list to know your current list'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print(player,format('r \nThe specefied location does not exist. Please use home list to know your current list'));
print(player(),format('r \nThe specefied location does not exist. Please use home list to know your current list'));

return();
);
dimension = info:'dimension';
pitch = info:'pitch';
yaw = info:'yaw';
location = info:'location';

run(str('execute in %s run tp %s %f %f %f %f %f',dimension,player(),location:0,location:1,location:2,yaw,pitch));

);

_hremove(name) -> (
if(global_hdata:str(player()~'uuid'):name==null,
print(player,format('r \nThe specefied location does not exist. Please use home list to know your current list'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print(player,format('r \nThe specefied location does not exist. Please use home list to know your current list'));
print(player(),format('r \nThe specefied location does not exist. Please use home list to know your current list'));

return();
);
delete(global_hdata:str(player()~'uuid'),name);
_saveHData();
print(player(),format(str('e \n%s was succesfully removed from your home list.',name)));
);

_hlist() -> (

info = global_hdata:str(player()~'uuid');
if(length(keys(info))==0,print(player(),format('r You have not set any homes yet.')));
print(player(),format('qub \nList of Available Homes: \n'));
for(keys(info),

loc = info:_:'location';
x = round(loc:0);
y = round(loc:1);
z = round(loc:2);
dim = info:_:'dimension';
if(dim=='the_end',
dim='End';
color='m',
//if else nether
dim=='the_nether',
dim='Nether';
color='r',
//else
dim='Overworld';
color='e'
);
print(player(),format(str('%s Name: %s, Location: %s %s %s, Dimension: %s',color,_,x,y,z,dim),str('!/%s home tp %s',system_info('app_name'),_),str('^di Click here to tp to: %s',_)));
);
);

//Warps

_wadd(name,description)->(

player=player();

if(player~'permission_level'<global_operator_permission_level,
print(player,format('r You do not have the permsission to execute this command. If you believe this to be an error, please contact server admin.'));
return();
);

global_names = keys(global_wdata);
if(global_names~name!=null, print(player,format(str('r %s is already in use. Therefore, updating the warp home to new location. \n',name))));
if(global_wdata:name==null,global_wdata:name={});

global_wdata:name:'location' = pos(player);
global_wdata:name:'pitch' = player~'pitch';
global_wdata:name:'yaw' = player~'yaw';
global_wdata:name:'dimension' = player~'dimension';
global_wdata:name:'description'= description;

//Extra stuff that is only availble to people with fake inv screens
if(_screenCheck(),
global_wdata:name:'item'= query(player,'holds','mainhand'):0;
);
_saveWData();
print(player,format('e Succesfully saved warp to location with name: '+name));

);

_wremove(name)->(

player=player();
if(player~'permission_level'<global_operator_permission_level,
print(player,format('r You do not have the permsission to execute this command. If you believe this to be an error, please contact server admin.'));
return();
);

if(global_wdata:name==null,
print(player,format('r \nThe specefied location does not exist. Please use warp menu to know about current warps'));
return();
);
delete(global_wdata,name);
_saveWData();
print(player,format(str('e \n%s was succesfully removed from warp list.',name)));

);

_wtp(name) -> (

player=player();
info = global_wdata:name;
if(info==null,
print(player,format('r \nThe specefied location does not exist. Please use warp menu to know about current warps'));
return();
);
dimension = info:'dimension';
pitch = info:'pitch';
yaw = info:'yaw';
location = info:'location';

run(str('execute in %s run tp %s %f %f %f %f %f',dimension,player,location:0,location:1,location:2,yaw,pitch));

);

_wmenu() -> (

player= player();
if(_screenCheck(),
warpCount = length(keys(global_wdata));
rowCount = ceil(warpCount/9);

menu= create_screen(player,str('generic_9x%s',rowCount),format('tb Available Warps'),_(screen,player,action,data) -> (

if(action=='pickup' || action== 'swap' || action=='quick_move' || action== 'throw' || action== 'pickup_all',
itemNbt= inventory_get(screen,data:'slot'):2;
itemName= parse_nbt(itemNbt:'display':'Name'):0:'text';
_wtp(itemName);
close_screen(screen);
);
));

if(screen_property(menu,'open'),

slot=0;
for(keys(global_wdata),

info = global_wdata:_;
iType=info:'item';
if(iType==null,iType='barrier');
des=info:'description';
loc=info:'location';
x= floor(loc:0);
y= floor(loc:1);
z= floor(loc:2);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a completely unrelated point, but this is the same as [x, y, z] = map(loc, floor(_)).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oman my whole scarpet life was a lie. I never knew this was possible xD. Imma change it everywhere asap

dim= info:'dimension';
if(dim=='the_end',
color='magenta',
//if else nether
dim=='the_nether',
color='red',
//else
color='green'
);
item=str('%s{display:{Name:\'[{"text":"%s","color":"%s","italic":false}]\',Lore:[\'[{"text":"Location: %s %s %s","color":"blue","italic":false}]\',\'[{"text":"Description:","color":"white","italic":false}]\',\'[{"text":"%s","italic":false}]\']}}',iType,str(_),color,x,y,z,des);
inventory_set(menu,slot,1,item);
slot+=1;
);

);

);


);


//utility
_saveHData()->(
delete_file('hdata','JSON');
write_file('hdata','JSON',global_hdata);
);

_saveWData()->(
delete_file('wdata','JSON');
write_file('wdata','JSON',global_wdata);
);

_screenCheck() -> (

sVersion= split('\\+',system_info('scarpet_version')):0; //fetches first part before the +, eg 1.4.57
vNumbers=split('\\.',sVersion);
if(number(vNumbers:0)>=1 && number(vNumbers:1)>=4 && number(vNumbers:2)>=57,
return (true);,
//Cant make screen
return(false);
)
);