Closest Location Utility


Author: Iroh
Created: 2014-06-19T17:10:39-0400
Edited: 2014-06-21T22:54:39-0400
Denizen Version: 0.9.4
Views: 25
Downloads: 743
Likes: 0


WGET
Description: This is a utility script that allows you to figure out which of a set of locations is closest to a location and also in the correct direction.

######################################################################################
# USAGE:
# First define the following:
# sortList - A list of all server flags to be compared
# cord - The coordinate you want to make sure the npc goes toward (so they don't walk backward to a closest point)
# operator - Defines if cord should be getting larger or small
# location - Location of the entity in question
# Them simply inject closestUtility
#
# HOW IT WORKS:
# 1) foreach sortList it does the following
# 2) if there is no current "winning" value (defined by currentClosestNumber/Name) it defines the current value is the "winner"
# 3) if there is a current "winning" value it makes sure the distance from the new value (to the $%location%) is less than %currentClosestNumber%
# 4) if it is smaller it also checks that that %location% has a %cord% value !%operator% than the location it is going to.
# 5) if those last 2 if's are true it define %vlaue% (the current testing location) as the current "winner" (%currentClosestNumber%)
######################################################################################
closestTrigger:
# this is just a world script for trigging closest utility manually, I used it to test the script
# by having it use my player's location just to make sure sorting was correct.
# editting the defines here will allow you to test more easily.
  type: world
  events:
    on closest command:
    - define sortList [email protected]|Trainee1.loc2|Trainee1.loc3|Trainee1.loc4|Trainee1.loc5|Trainee1.loc6|Trainee1.loc7|Trainee1.loc8|Trainee1.loc9|Trainee1.loc10|Trainee1.loc11|Trainee1.loc12|Trainee1.loc13|Trainee1.end
    - define cord z
    - define operator LESS
    - define location <player.location>
    - inject closestUtility
trainee1Closest:
# This is an example of how I utilize closestUtility.
# Feel free to edit the name and the sortList definition to your needs.
  type: task
  script:
  - define sortList [email protected]|Trainee1.loc2|Trainee1.loc3|Trainee1.loc4|Trainee1.loc5|Trainee1.loc6|Trainee1.loc7|Trainee1.loc8|Trainee1.loc9|Trainee1.loc10|Trainee1.loc11|Trainee1.loc12|Trainee1.loc13|Trainee1.end
  - define cord z
  - define operator LESS
  - inject closestUtility
closestUtility:
# The first half of the giant if nest is the main portion
# to use the script with maximium efficency (only needing the first 1/2)
# you should define the sortList in sequential order
# if you don't the second 1/2 of the script will have to be used
# this will increase resource usage unnecessarily.
  type: task
  script:
  - foreach <def[sortList]> {
    - define serverflag <server.flag[%value%].as_location>
    - if !<def[currentClosestNumber].exists> {
      - if !<def[location].z.is[%operator%].than[<def[serverflag].z>]> {
        - if !<def[location].distance[%serverflag%].is[LESS].than[2]> {
          - define currentClosestNumber <def[serverflag].distance[%location%]>
          - define currentClosestName %value%
          }
        }
      }
      else {
      - if <def[serverflag].distance[%location%].is[%operator%].than[<def[currentClosestNumber]>]> {
        - announce "<def[location].z.distance[%serverflag%]> - distance from npc to current point"
        - if !<def[location].distance[%serverflag%].is[LESS].than[2]> {
          - if !<def[location].%cord%.is[%operator%].than[<def[serverflag].%cord%>]> {
            - define currentClosestNumber <def[serverflag].distance[%location%]>
            - define currentClosestName %value%
            }
          }
        }
      }
    }
  - define destination <server.flag[%currentClosestName%]>




Comments
No one has posted a comment! Post one below: