~/paste/56745
~/paste/56745
~/paste/56745

  1. #Define the specific parameters here, no color codes.
  2. @title = 'Pioneer Compass';
  3. @lore1 = 'This special compass was awarded';
  4. @lore2 = 'to players for participating in';
  5. @perm = 'essentials.kits.pioneer';
  6. ### Checks are asyncronous and shouldn't cause lag, but if they do you can specify how often they are run in seconds here:
  7. @checkevery = 1.5;
  8. #CRun ever x amount of time
  9. set_interval(floor(1000 * @checkevery),0,closure(@checkevery_ = @checkevery, @title_ = @title, @perm_ = @perm, @lore1_ = @lore1, @lore2_ = @lore2){
  10.   #In case the player logs off or something, this try/catch will safely break the scheduled task.
  11.         x_new_thread('async',closure(){
  12.     foreach(all_players(),@player){
  13.                 if(has_permission(@player,@perm_)){
  14.         try(
  15.           // Not sure this line actually works
  16.           set_compass_target(@player,get_spawn(pworld(@player)));
  17.           //
  18.                   #If the display name of the item, having been stripped of colors, matches this text
  19.                   if(strip_colors(pinv(@player,-106)['meta']['display']) === @title){
  20.                         #If the lore on the item, having been stripped of colors, matches this text
  21.                         if(strip_colors(pinv(@player,-106)['meta']['lore'][0]) === @lore1 || strip_colors(pinv(@player,-106)['meta']['lore'][1]) === @lore1){
  22.                           if(strip_colors(pinv(@player,-106)['meta']['lore'][1]) === @lore2 || strip_colors(pinv(@player,-106)['meta']['lore'][2]) === @lore2){
  23.                                   @time = time();
  24.                                   @entityTypes = array(
  25.                                         CAVE_SPIDER,
  26.                                         CREEPER,
  27.                                         ELDER_GUARDIAN,
  28.                                         ENDER_CRYSTAL,
  29.                                         ENDER_DRAGON,
  30.                                         ENDERMAN,
  31.                                         ENDERMITE,
  32.                                         EVOKER,
  33.                                         GHAST,
  34.                                         GIANT,
  35.                                         GUARDIAN,
  36.                                         HUSK,
  37.                                         ILLUSIONER,
  38.                                         MAGMA_CUBE,
  39.                                         PIG_ZOMBIE,
  40.                                         PRIMED_TNT,
  41.                                         SHULKER,
  42.                                         SHULKER_BULLET,
  43.                                         SILVERFISH,
  44.                                         SKELETON,
  45.                                         SKELETON_HORSE,
  46.                                         SLIME,
  47.                                         SPIDER,
  48.                                         STRAY,
  49.                                         VEX,
  50.                                         VINDICATOR,
  51.                                         WITCH,
  52.                                         WITHER_SKELETON,
  53.                                         WITHER_SKULL,
  54.                                         ZOMBIE,
  55.                                         ZOMBIE_HORSE,
  56.                                         ZOMBIE_VILLAGER
  57.                                   );
  58.                                   x_run_on_main_thread_later(closure(set_peffect(@player,1,2,ceil(@checkevery_),true,false)));
  59.                                   x_run_on_main_thread_later(closure(set_peffect(@player,8,1,ceil(@checkevery_),true,false)));
  60.                                   @px = ploc(@player)[0];
  61.                                   @pz = ploc(@player)[2];
  62.                                   @entities = entities_in_radius(ploc(@player),32);
  63.                 foreach(@entities,@index,@entity){
  64.                   if(!array_contains(@entityTypes,entity_type(@entity))){
  65.                     array_remove(@entities,@index);
  66.                     continue(0);
  67.                   }
  68.                 }
  69.                                   if(array_size(@entities) > 0){
  70.                                                 array_sort(@entities, closure(@1,@2){
  71.                                                   @1x = entity_loc(@1)[0];
  72.                                                   @1z = entity_loc(@1)[2];
  73.                                                   @onedistance = sqrt(((@px - @1x) ** 2) + ((@pz - @1z) ** 2));
  74.                                                         @2x = entity_loc(@2)[0];
  75.                                                         @2z = entity_loc(@2)[2];
  76.                                                   @twodistance = sqrt(((@px - @2x) ** 2) + ((@pz - @2z) ** 2));
  77.                                                   return(@onedistance > @twodistance);
  78.                                                 });
  79.                                                 set_compass_target(@player,entity_loc(@entities[0]));
  80.                                                 action_msg(@player, color(c).entity_type(@entities[0]));
  81.                                                 // Timing Check
  82.                                     }else{ ## Entities in radius is empty
  83.                   // Not sure this line actually works
  84.                   set_compass_target(@player,get_spawn(pworld(@player)));
  85.                   //
  86.                 }
  87.                 ### Uncomment this line in order to enable timing messages.
  88.                 #tmsg(@player,time() - @time);
  89.               } ### end Lore 2 check
  90.             } ### end Lore 1 check
  91.           } ### end Title check
  92.         ) ### end TRY
  93.       } ### end permission check
  94.     } ### end foreach playet
  95.   }) ### end async
  96. }); ### end interval
  97.  
Language: text
Posted by code at 30 Jan 2018, 12:13:40 UTC