#Define the specific parameters here, no color codes.
@title = 'Pioneer Compass';
@lore1 = 'This special compass was awarded';
@lore2 = 'to players for participating in';
@perm = 'essentials.kits.pioneer';
### Checks are asyncronous and shouldn't cause lag, but if they do you can specify how often they are run in seconds here:
@checkevery = 1.5;
#CRun ever x amount of time
set_interval(floor(1000 * @checkevery),0,closure(@checkevery_ = @checkevery, @title_ = @title, @perm_ = @perm, @lore1_ = @lore1, @lore2_ = @lore2){
#In case the player logs off or something, this try/catch will safely break the scheduled task.
x_new_thread('async',closure(){
foreach(all_players(),@player){
if(has_permission(@player,@perm_)){
try(
// Not sure this line actually works
set_compass_target(@player,get_spawn(pworld(@player)));
//
#If the display name of the item, having been stripped of colors, matches this text
if(strip_colors(pinv(@player,-106)['meta']['display']) === @title){
#If the lore on the item, having been stripped of colors, matches this text
if(strip_colors(pinv(@player,-106)['meta']['lore'][0]) === @lore1 || strip_colors(pinv(@player,-106)['meta']['lore'][1]) === @lore1){
if(strip_colors(pinv(@player,-106)['meta']['lore'][1]) === @lore2 || strip_colors(pinv(@player,-106)['meta']['lore'][2]) === @lore2){
@time = time();
@entityTypes = array(
CAVE_SPIDER,
CREEPER,
ELDER_GUARDIAN,
ENDER_CRYSTAL,
ENDER_DRAGON,
ENDERMAN,
ENDERMITE,
EVOKER,
GHAST,
GIANT,
GUARDIAN,
HUSK,
ILLUSIONER,
MAGMA_CUBE,
PIG_ZOMBIE,
PRIMED_TNT,
SHULKER,
SHULKER_BULLET,
SILVERFISH,
SKELETON,
SKELETON_HORSE,
SLIME,
SPIDER,
STRAY,
VEX,
VINDICATOR,
WITCH,
WITHER_SKELETON,
WITHER_SKULL,
ZOMBIE,
ZOMBIE_HORSE,
ZOMBIE_VILLAGER
);
x_run_on_main_thread_later(closure(set_peffect(@player,1,2,ceil(@checkevery_),true,false)));
x_run_on_main_thread_later(closure(set_peffect(@player,8,1,ceil(@checkevery_),true,false)));
@px = ploc(@player)[0];
@pz = ploc(@player)[2];
@entities = entities_in_radius(ploc(@player),32);
foreach(@entities,@index,@entity){
if(!array_contains(@entityTypes,entity_type(@entity))){
array_remove(@entities,@index);
continue(0);
}
}
if(array_size(@entities) > 0){
array_sort(@entities, closure(@1,@2){
@1x = entity_loc(@1)[0];
@1z = entity_loc(@1)[2];
@onedistance = sqrt(((@px - @1x) ** 2) + ((@pz - @1z) ** 2));
@2x = entity_loc(@2)[0];
@2z = entity_loc(@2)[2];
@twodistance = sqrt(((@px - @2x) ** 2) + ((@pz - @2z) ** 2));
return(@onedistance > @twodistance);
});
set_compass_target(@player,entity_loc(@entities[0]));
action_msg(@player, color(c).entity_type(@entities[0]));
// Timing Check
}else{ ## Entities in radius is empty
// Not sure this line actually works
set_compass_target(@player,get_spawn(pworld(@player)));
//
}
### Uncomment this line in order to enable timing messages.
#tmsg(@player,time() - @time);
} ### end Lore 2 check
} ### end Lore 1 check
} ### end Title check
) ### end TRY
} ### end permission check
} ### end foreach playet
}) ### end async
}); ### end interval