DUL_Astar_default_neighbours:
type: procedure
debug: false
DUL:
author:
- BlackCoyote
name:
- A* Pathfinder default neighbours
description:
- Returns the neighbours of a location, as required for the A* pathfinder.
usage:
- <proc[DUL_Astar_default_neighbours].context[<location>]>
example:
- <proc[DUL_Astar_default_neighbours].context[<def[location]>]>
script:
# this needs to be better
- determine <def[1].find.surface_blocks.within[2]||li@>
DUL_Astar:
type: procedure
debug: false
DUL:
author:
- BlackCoyote
name:
- A* Pathfinder
description:
- Returns a path from one location to another, using the A* algorithm
usage:
- <proc[DUL_Astar].context[start|destination(|precision|max loops|neighbour procedure)]>
example:
- <proc[DUL_Astar].context[<npc.location>|<npc.flag[spawn_location]>]>
script:
- define origin <def[1]||null>
- define destination <def[2]||null>
- define precision <def[3]||2>
- define max_loops <def[4]||25000>
- define neighbour_procedure <def[5]||DUL_Astar_default_neighbours>
- define open li@0/<def[origin]>/null
- define closed li@
- while <def[open].is_empty.not||false>:
- if <def[loop_index]> > <def[max_loops]> determine null
- define parent_id <def[loop_index]>
- define q <def[open].get[1]>
- define parent_<def[parent_id]> <def[q]>
- define open <def[open].exclude[<def[q]>]>
- define q_loc <def[q].before_last[/].after[/].as_location>
- define q_f <def[q].before[/]>
- define neighbours <proc[<def[neighbour_procedure]>].context[<def[q_loc]>]>
- foreach <def[neighbours]>:
- if <def[value].as_location.distance[<def[destination]>]> < <def[precision]> {
- define final "0/<def[value].as_location>/parent_<def[parent_id]>"
- while stop
}
- define f <def[value].as_location.distance_squared[<def[q_loc]>].add[<def[q_f]>].add[<def[origin].distance_squared[<def[value].as_location>]>]>
- if <def[open].filter[before_last[/].after[/].is[==].to[<def[value].as_location>]].filter[before[/].is[less].than[<def[f]>]].is_empty.not> {
- foreach next
}
- if <def[closed].filter[before_last[/].after[/].is[==].to[<def[value].as_location>]].filter[before[/].is[less].than[<def[f]>]].is_empty.not> {
- foreach next
}
- define open <def[open].include[<def[f]>/<def[value].as_location>/parent_<def[parent_id]>].alphanumeric>
- define closed <def[closed].include[<def[q]>]>
- define path li@
- if <def[final].exists.not> {
- determine null
}
- define parent <def[final].after_last[/]||null>
- while true:
- if <def[loop_index]> > <def[max_loops]> determine null
- define current <def[<def[parent]>]||null>
- if <def[current]> == null {
- while stop
}
- define location <def[current].before_last[/].after[/].as_location>
- define path <def[path].include[<def[location]>]>
- define parent <def[current].after_last[/]||null>
- determine <def[path].reverse>
# commented version, entirely commented out for laziness sake
# DUL_Astar:
# type: procedure
# debug: false
# DUL:
# author:
# - BlackCoyote
# name:
# - A* Pathfinder
# description:
# - Returns a path from one location to another, using the A* algorithm
# usage:
# - <proc[DUL_Astar].context[start|destination(|precision|max loops|neighbour procedure)]>
# example:
# - give <proc[DUL_Astar].context[<npc.location>|<npc.flag[spawn_location]>]>
# script:
# - define origin <def[1]||null>
# - define destination <def[2]||null>
# - define precision <def[3]||2>
# - define max_loops <def[4]||25000>
# - define neighbour_procedure <def[5]||DUL_Astar_default_neighbours>
# initiate the open and closed lists, include the origin as a value to open
# - define open li@0/<def[origin]>/null
# - define closed li@
# while we still have values to look through
# - while <def[open].is_empty.not||false>:
# - if <def[loop_index]> > <def[max_loops]> determine null
# define the ID of the current parent node as the value of the while loop
# - define parent_id <def[loop_index]>
# Q is the parent node, which is the entry in the open list with the smallest cost (get1 since we sort this list alphanumerically when redefining)
# - define q <def[open].get[1]>
# fill the current parent ID's variable with the parent node's info
# - define parent_<def[parent_id]> <def[q]>
# remove the current parent from the open list
# - define open <def[open].exclude[<def[q]>]>
# get the location from the current parent
# - define q_loc <def[q].before_last[/].after[/].as_location>
# get the cost of the current parent
# - define q_f <def[q].before[/]>
# get all the eligible neighbours from the current parent
# - define neighbours <proc[<def[neighbour_procedure]>].context[<def[q_loc]>]>
# loop through each neighbour node
# - foreach <def[neighbours]>:
# if the neighbour is within the threshold distance from the destination, stop the search loop
# - if <def[value].as_location.distance[<def[destination]>]> < <def[precision]> {
# store the final node at which the path was completed separately
# - define final "0/<def[value].as_location>/parent_<def[parent_id]>"
# - while stop
# }
# define the cost for the current child node, based on its distance to the parent, its parent's cost, and its distance to the destination
# - define f <def[value].as_location.distance_squared[<def[q_loc]>].add[<def[q_f]>].add[<def[origin].distance_squared[<def[value].as_location>]>]>
# if the open list contains a node with the same location and a lower cost, we can dismiss this node
# - if <def[open].filter[before_last[/].after[/].is[==].to[<def[value].as_location>]].filter[before[/].is[less].than[<def[f]>]].is_empty.not> {
# - foreach next
# }
# if the closed list contains a node with the same location and a lower cost, we can dismiss this node
# - if <def[closed].filter[before_last[/].after[/].is[==].to[<def[value].as_location>]].filter[before[/].is[less].than[<def[f]>]].is_empty.not> {
# - foreach next
# }
# add this current node to the open list,
# each added node will also contain an ID to which parent node it came from, this is used to trace back the direct path to the origin
# each node will contain the cost it took to get there, so that it can be compared with other locations
# - define open <def[open].include[<def[f]>/<def[value].as_location>/parent_<def[parent_id]>].alphanumeric>
# when we finished looping through the neighbours for a parent, we add the parent to the closed list
# - define closed <def[closed].include[<def[q]>]>
# at this point we reached our destination, we now have a list of nodes. Each node will have a link to its parent node (which is the node from which this current node was a neighbour node of) and now we simply backtrack every parent node starting from the destination, until we run out of parent nodes.
#
# for example the node cost/l@x,y,z,world/parent_50 has parent_50 as the parent's ID, if we now read <def[parent_50]> we get cost/l@x,y,z,world/parent_46, and so we trace back through every single parent involved with the successful neighbour untill we run out of parents which means we got the origin again
#
# - define path li@
# - if <def[final].exists.not> {
# no path found :(
# - determine null
# }
# - define parent <def[final].after_last[/]||null>
# now we basicly backtrack the entire node list,
# - while true:
# - if <def[loop_index]> > <def[max_loops]> determine null
# - define current <def[<def[parent]>]||null>
# - if <def[current]> == null {
# - while stop
# }
# - define location <def[current].before_last[/].after[/].as_location>
# - define path <def[path].include[<def[location]>]>
# - define parent <def[current].after_last[/]||null>
# - determine <def[path].reverse>
DUL_colorcode_message:
type: procedure
debug: false
DUL:
name:
- Colorcode Message
author:
- BlackCoyote
description:
- Encodes your message into a colour code string and back.
- only works with characters from a-z, 0-9, and _ !
usage:
- <proc[DUL_colorcode_message].context[encode/decode|<message>]>
example:
- <proc[DUL_colorcode_message].context[encode|my_sword_id]>
encode:
a: '&0&0'
b: '&0&1'
c: '&0&2'
d: '&0&3'
e: '&0&4'
f: '&0&5'
g: '&0&6'
h: '&0&7'
i: '&0&8'
j: '&0&9'
k: '&1&0'
l: '&1&1'
m: '&1&2'
n: '&1&3'
o: '&1&4'
p: '&1&5'
q: '&1&6'
r: '&1&7'
s: '&1&8'
t: '&1&9'
u: '&2&0'
v: '&2&1'
w: '&2&2'
x: '&2&3'
y: '&2&4'
z: '&2&5'
0: '&2&6'
1: '&2&7'
2: '&2&8'
3: '&2&9'
4: '&3&0'
5: '&3&1'
6: '&3&2'
7: '&3&3'
8: '&3&4'
9: '&3&5'
_: '&3&6'
decode:
'&0&0': a
'&0&1': b
'&0&2': c
'&0&3': d
'&0&4': e
'&0&5': f
'&0&6': g
'&0&7': h
'&0&8': i
'&0&9': j
'&1&0': k
'&1&1': l
'&1&2': m
'&1&3': n
'&1&4': o
'&1&5': p
'&1&6': q
'&1&7': r
'&1&8': s
'&1&9': t
'&2&0': u
'&2&1': v
'&2&2': w
'&2&3': x
'&2&4': y
'&2&5': z
'&2&6': 0
'&2&7': 1
'&2&8': 2
'&2&9': 3
'&3&0': 4
'&3&1': 5
'&3&2': 6
'&3&3': 7
'&3&4': 8
'&3&5': 9
'&3&6': _
script:
- if li@encode|decode !contains <def[1]||> {
- debug error "DUL - No valid action specified! Must be encode or decode!"
- determine null
}
- if <def[2]||> == "" {
- debug error "DUL - No message specified to <def[1]>!"
- determine null
}
- define result ""
- if <def[1]> == encode {
- define list <def[2].to_list>
} else {
- define list li@
- define 2 <def[2].escaped.replace[&ss].with[&]>
- repeat <def[2].length.div[4].as_int> {
- define list <def[list].include[<def[2].substring[<def[value].mul[4].sub[4].add[1]||1>,<def[value].mul[4]>]>]>
}
}
- foreach <def[list]>:
- define result "<def[result]><script.yaml_key[<def[1]>.<def[value]>]||->"
- determine <def[result].parse_color>
DUL_colorcode_to_RGB:
type: procedure
debug: false
DUL:
name:
- Colorcode to RGB
author:
- BlackCoyote
description:
- Returns a matching RGB value for the specified color code
usage:
- <proc[DUL_colorcode_to_RGB].context[<colorcode>]>
example:
- <proc[DUL_colorcode_to_RGB].context[&2]>
colors:
0: 0,0,0
1: 0,0,170
2: 0,170,0
3: 0,170,170
4: 170,0,0
5: 170,0,170
6: 255,170,0
7: 170,170,170
8: 85,85,85
9: 85,85,255
a: 85,255,85
b: 85,255,255
c: 255,85,85
d: 255,85,255
e: 255,255,85
f: 255,255,255
script:
- determine <script.yaml_key[colors.<def[1].after[&]||null>]||null>
DUL_ColorList:
type: procedure
debug: false
DUL:
author:
- Anthony
name:
- ColorList
description:
- Return colors from input or just list all colors
usage:
- <proc[DUL_colorlist].context[<list/match|input>]>
example:
- narrate <proc[DUL_colorlist].context[list]>
- narrate <proc[DUL_colorlist].context[match|blu]>
colors:
black: 0
dark_blue: 1
dark_green: 2
dark_aqua: 3
dark_red: 4
dark_purple: 5
gold: 6
gray: 7
dark_gray: 8
blue: 9
green: a
aqua: b
red: c
light_purple: d
yellow: e
white: f
magic: k
bold: l
strikethrough: m
underline: n
italic: o
reset: r
script:
- define colors '<script.list_keys[colors]>'
- choose '<def[1]>':
- case 'list':
- define list 'li@'
- foreach '<def[colors]>':
- define list '<def[list].include[<el@val[&<script.yaml_key[colors.%value%]>]> %value%]>'
- determine '<def[list]>'
- case 'match':
- determine '<proc[DUL_find_best_match].context[<def[colors]>|<def[2]>]>'
DUL_cuboid_vertices:
type: procedure
debug: false
DUL:
author:
- Anthony
name:
- Cuboid Vertices
description:
- Return the list of cuboid vertices from a location pair.
usage:
- <proc[DUL_cuboid_vertices].context[%loc1%|%loc2%]>
example:
- <proc[DUL_cuboid_vertices].context[l@0,0,0,world|l@5,4,3,world]>
script:
- define lx '<def[1].x>'
- define ly '<def[1].y>'
- define lz '<def[1].z>'
- define hx '<def[2].x>'
- define hy '<def[2].y>'
- define hz '<def[2].z>'
- define world '<def[1].world.name>'
- determine 'li@l@<def[lx]>,<def[ly]>,<def[lz]>,<def[world]>|l@<def[lx]>,<def[hy]>,<def[lz]>,<def[world]>|l@<def[lx]>,<def[ly]>,<def[hz]>,<def[world]>|l@<def[hx]>,<def[ly]>,<def[lz]>,<def[world]>|l@<def[hx]>,<def[hy]>,<def[hz]>,<def[world]>|l@<def[lx]>,<def[hy]>,<def[hz]>,<def[world]>|l@<def[hx]>,<def[hy]>,<def[lz]>,<def[world]>|l@<def[hx]>,<def[ly]>,<def[hz]>,<def[world]>'
# Scrapped for flames, keeping for lulz
#DUL_cuboid_vertices:
# type: procedure
# debug: false
# DUL:
# author:
# - Anthony
# name:
# - Cuboid Vertices
# description:
# - Return the list of cuboid vertices from a location pair.
# usage:
# - <proc[DUL_cuboid_vertices].context[%loc1%|%loc2%]>
# example:
# - <proc[DUL_cuboid_vertices].context[<l@0,0,0,world>|<l@1,1,1,world>]>
# script:
# - define world '<def[1].world.name>'
# - foreach 'li@x|y|z':
# - define %value%pair 'li@<def[1].%value%>|<def[2].%value%>'
# - define vertlist 'li@'
# - foreach '<def[xpair]>':
# - define x '%value%'
# - foreach '<def[ypair]>':
# - define y '%value%'
# - foreach '<def[zpair]>':
# - define vertlist '<def[vertlist].include[l@%x%,%y%,%value%,%world%]>'
# - determine '%vertlist%'
DUL_cuboid_overlap:
type: procedure
debug: false
DUL:
author:
- Anthony
name:
- Cuboid Overlap
description:
- Returns a cuboid object from 2 overlapping cuboids
usage:
- <proc[DUL_cuboid_overlap].context[%cuboid1%|%cuboid2%]>
example:
- <proc[DUL_cuboid_overlap].context[cu@0,0,0,world|4,4,4,world|cu@3,3,3,world|5,5,5,world]>
script:
# Reconstruct cuboids from list
- define objects '<def[raw_context].as_list>'
- define 'c1' '<def[objects].get[1].to[2].as_cuboid>'
- define 'c2' '<def[objects].get[3].to[4].as_cuboid>'
- if <def[c1].intersects[%c2%].not> {
- determine null
}
- define 1l '<def[c1].min>'
- define 1h '<def[c1].max>'
- define world '<def[1l].world.name>'
- define 1lx '<def[1l].x>'
- define 1ly '<def[1l].y>'
- define 1lz '<def[1l].z>'
- define 1hx '<def[1h].x>'
- define 1hy '<def[1h].y>'
- define 1hz '<def[1h].z>'
- define 2l '<def[c2].min>'
- define 2h '<def[c2].max>'
- define 2lx '<def[2l].x>'
- define 2ly '<def[2l].y>'
- define 2lz '<def[2l].z>'
- define 2hx '<def[2h].x>'
- define 2hy '<def[2h].y>'
- define 2hz '<def[2h].z>'
- define flx '<def[1lx].max[%2lx%].max[<def[1lx].min[%2hx%]>].round>'
- define fly '<def[1ly].max[%2ly%].max[<def[1ly].min[%2hy%]>].round>'
- define flz '<def[1lz].max[%2lz%].max[<def[1lz].min[%2hz%]>].round>'
- define fhx '<def[1hx].max[%2lx%].min[<def[1hx].min[%2hx%]>].round>'
- define fhy '<def[1hy].max[%2ly%].min[<def[1hy].min[%2hy%]>].round>'
- define fhz '<def[1hz].max[%2lz%].min[<def[1hz].min[%2hz%]>].round>'
- determine 'cu@%flx%,%fly%,%flz%,%world%|%fhx%,%fhy%,%fhz%,%world%'
DUL_cuboid_shell:
type: procedure
debug: false
DUL:
author:
- Anthony
name:
- Cuboid Shell
description:
- Supply a list of cuboids and returns the list of surface locations.
usage:
- <proc[DUL_cuboid_shell].context[<cuboid>|...]>
example:
- <proc[DUL_cuboid_shell].context[<cuboid>|...]>
script:
# Reconstruct cuboids from list
- define objects '<def[raw_context].as_list>'
- define clist 'li@'
- repeat '<def[objects].size.div[2].round>':
- define 'cuboid%value%' '<def[objects].get[<def[value].mul[2].sub[1].round>].to[<def[value].mul[2].round>]>'
- define clist '<def[clist].include[cuboid%value%]>'
- define blocks 'li@'
- define overLaps 'li@'
- foreach '%clist%':
- define olist '<def[clist].remove[%loop_index%]>'
- define cuboid '<def[%value%].as_cuboid>'
- define 1l '<def[cuboid].min>'
- define 1h '<def[cuboid].max>'
- define world '<def[1h].world.name>'
- define 1lx '<def[1l].x>'
- define 1ly '<def[1l].y>'
- define 1lz '<def[1l].z>'
- define 1hx '<def[1h].x>'
- define 1hy '<def[1h].y>'
- define 1hz '<def[1h].z>'
- foreach '%olist%':
- define this '<def[%value%].as_cuboid>'
- if <def[cuboid].intersects[%this%]> {
- define 2l '<def[this].min>'
- define 2h '<def[this].max>'
- define 2lx '<def[2l].x>'
- define 2ly '<def[2l].y>'
- define 2lz '<def[2l].z>'
- define 2hx '<def[2h].x>'
- define 2hy '<def[2h].y>'
- define 2hz '<def[2h].z>'
- define flx '<def[1lx].max[%2lx%].max[<def[1lx].min[%2hx%]>].round>'
- define fly '<def[1ly].max[%2ly%].max[<def[1ly].min[%2hy%]>].round>'
- define flz '<def[1lz].max[%2lz%].max[<def[1lz].min[%2hz%]>].round>'
- define fhx '<def[1hx].max[%2lx%].min[<def[1hx].min[%2hx%]>].round>'
- define fhy '<def[1hy].max[%2ly%].min[<def[1hy].min[%2hy%]>].round>'
- define fhz '<def[1hz].max[%2lz%].min[<def[1hz].min[%2hz%]>].round>'
- define oShell 'cu@l@%flx%,%fly%,%flz%,%world%|l@%fhx%,%fhy%,%flz%,%world%|l@%flx%,%fly%,%flz%,%world%|l@%flx%,%fhy%,%fhz%,%world%|l@%flx%,%fly%,%flz%,%world%|l@%fhx%,%fly%,%fhz%,%world%|l@%fhx%,%fhy%,%fhz%,%world%|l@%flx%,%fly%,%fhz%,%world%|l@%fhx%,%fhy%,%fhz%,%world%|l@%fhx%,%fly%,%flz%,%world%|l@%fhx%,%fhy%,%fhz%,%world%|l@%flx%,%fhy%,%flz%,%world%'
- define overLaps '<def[overlaps].include[<def[oShell].blocks>]>'
}
- define shell 'cu@l@%1lx%,%1ly%,%1lz%,%world%|l@%1hx%,%1hy%,%1lz%,%world%|l@%1lx%,%1ly%,%1lz%,%world%|l@%1lx%,%1hy%,%1hz%,%world%|l@%1lx%,%1ly%,%1lz%,%world%|l@%1hx%,%1ly%,%1hz%,%world%|l@%1hx%,%1hy%,%1hz%,%world%|l@%1lx%,%1ly%,%1hz%,%world%|l@%1hx%,%1hy%,%1hz%,%world%|l@%1hx%,%1ly%,%1lz%,%world%|l@%1hx%,%1hy%,%1hz%,%world%|l@%1lx%,%1hy%,%1lz%,%world%'
- define blocks '<def[blocks].include[<def[shell].blocks>]>'
- determine '<def[blocks].deduplicate.exclude[<def[overLaps].deduplicate>]>'
#
# Just a some commands to play with
#
#DUL_Commands_ShowOverlap:
# type: command
# debug: false
# name: showoverlap
# description: Show the overlapping area of two cuboids
# usage: /showoverlap
# aliases: ''
# tab complete:
# - determine 'li@'
# script:
# - showfake m@white_stained_glass <proc[DUL_cuboid_shell].context[<proc[DUL_cuboid_overlap].context[<c.args.get[1].as_cuboid>|<c.args.get[2].as_cuboid>]>]> to:<player> d:<player.flag[dWE.show].split[/].get[2]||10>s
#DUL_Commands_Showshell:
# type: command
# debug: false
# name: showshell
# description: Show the shell of two cuboids
# usage: /showshell
# aliases: ''
# tab complete:
# - determine 'li@'
# script:
# - showfake m@white_stained_glass <proc[DUL_cuboid_shell].context[<c.args.get[1].as_cuboid>|<c.args.get[2].as_cuboid>]> to:<player> d:<player.flag[dWE.show].split[/].get[2]||10>s
#
DUL_duration_formatted_full:
type: procedure
debug: false
DUL:
author:
- BlackCoyote
name:
- Duration formatted full
description:
- Returns the duration as a formatted string, with full words.
- additionally, you can specify your own words for it to use.
usage:
- <proc[DUL_duration_formatted_full].context[<duration>(|<days_singular>|<days_plural<|<hours_SG>|<hours_PL>|<minutes_SG>|<minutes_PL<|<seconds_SG>|<seconds_PL>)]>
example:
- <proc[DUL_duration_formatted_full].context[d@30.180h]>
script:
- define duration <def[1].as_duration||null>
- if <def[duration]> == null {
- debug error "DUL - No valid duration specified!"
- determine null
}
- define return ""
- define d <def[duration].in_days.round_down>
- if <def[d]> > 1 {
- define return " <def[d]> <def[3]||days>"
} else if <def[d]> > 0 {
- define return " <def[d]> <def[2]||day>"
}
- define duration <def[duration].sub[d@<def[d]>d]>
- define h <def[duration].in_hours.round_down>
- if <def[h]> > 1 {
- define return "<def[return]> <def[h]> <def[5]||hours>"
} else if <def[h]> > 0 {
- define return "<def[return]> <def[h]> <def[4]||hour>"
}
- define duration <def[duration].sub[d@<def[h]>h]>
- define m <def[duration].in_minutes.round_down>
- if <def[m]> > 1 {
- define return "<def[return]> <def[m]> <def[7]||minutes>"
} else if <def[m]> > 0 {
- define return "<def[return]> <def[m]> <def[6]||minute>"
}
- define duration <def[duration].sub[d@<def[m]>m]>
- define s <def[duration].in_seconds.round_down>
- if <def[s]> > 1 {
- define return "<def[return]> <def[s]> <def[9]||seconds>"
} else if <def[s]> > 0 {
- define return "<def[return]> <def[s]> <def[8]||second>"
}
- determine <def[return].trim>
DUL_find_best_match:
type: procedure
debug: false
DUL:
name:
- Find Best Match
author:
- BlackCoyote
- Anthony
description:
- Returns the best search match out of a list.
usage:
- <proc[DUL_find_best_match].context[<list>|<value>]>
example:
- <proc[DUL_find_best_match].context[<server.flag[homes].as_list>|<context.args.get[1]>]>
script:
- define list '<def[raw_context].as_list||li@>'
- if <def[list].size> < 2 {
- debug error "DUL - Must provide at least one value to match and one value to match against!"
- determine null
}
- define match '<def[list].last>'
- define list '<def[list].remove[<def[list].size>]>'
- if <def[list].contains[<def[match]>]> {
- determine '<def[match]>'
} else if <def[list].filter[starts_with[<def[match]>]].size||0> > 0 {
- determine '<def[list].filter[starts_with[<def[match]>]].sort_by_number[length].first||null>'
} else if <def[list].filter[contains[<def[match]>]].size||0> > 0 {
- determine '<def[list].filter[contains[<def[match]>]].sort_by_number[length].first||null>'
} else {
- determine null
}
DUL_hidden_spawn_locations:
type: procedure
debug: false
definitions: location|radius
DUL:
name:
- Hidden Spawn Locations
author:
- BlackCoyote
description:
- Finds spawn locations within range that are out of line of sight.
- If no locations out of line of sight are found, it will return valid spawn locations within line of sight.
usage:
- <proc[DUL_hidden_spawn_locations].context[<l@location>|<radius>]>
example:
- <proc[DUL_hidden_spawn_locations].context[<player.location>|15]>
script:
- if <def[location]||null> !matches location {
- debug error "DUL - No valid location specified!"
- determine null
}
- if <def[radius]||null> !matches number {
- debug error "DUL - No valid radius specified!"
- determine null
}
- define radius <def[radius].as_int>
- determine <def[location].find.surface_blocks.within[<def[radius]>].filter[y.sub[<def[location].y>].abs.is[less].than[3]].filter[above.above.above.material.name.is[==].to[air]].filter[above.above.above.above.material.name.is[==].to[air]].filter[above.above.above.above.above.material.name.is[==].to[air]].filter[material.is_occluding].parse[above].filter[above.center.line_of_sight[<def[location].add[0,1.5,0].center>].not]||<def[location].find.surface_blocks.within[<def[radius]>]||li@<def[location]>>>
DUL_parsePrepend:
type: procedure
debug: false
DUL:
author:
- Anthony
name:
- String Prepender
description:
- Prepends a string to the beginning of each item in a list
usage:
- <proc[DUL_parsePrepend].context[prepender|<list>]>
example:
- narrate "<proc[DUL_parsePrepend].context[Number |1|2|3]>"
script:
- define e '<def[raw_context].as_list>'
- determine '<def[e].get[2].to[<def[e].size>].parse[replace[regex:^].with[<def[e].get[1]>]||li@>'
DUL_parseAppend:
type: procedure
debug: false
DUL:
author:
- Anthony
name:
- String Appender
description:
- Appends a string to the end of each item in a list
usage:
- <proc[DUL_parseAppend].context[appender|<list>]>
example:
- narrate "<proc[DUL_parseAppend].context[ am awesome!|I|You|We]>"
script:
- define e '<def[raw_context].as_list>'
- determine '<def[e].get[2].to[<def[e].size>].parse[replace[regex:$].with[<def[e].get[1]>]||li@>'
DUL_parseWrap:
type: procedure
debug: false
DUL:
author:
- Anthony
name:
- String Wrapper
description:
- Adds a prepender and an appender to each item in a list
usage:
- <proc[DUL_parseWrap].context[prepender|appender|<list>]>
example:
- narrate "<proc[DUL_parseWrap].context[Number |!|1|2|3]>"
script:
- define e '<def[raw_context].as_list>'
- determine '<def[e].get[3].to[<def[e].size>].parse[replace[regex:^].with[<def[e].get[1]>].parse[replace[regex:$].with[<def[e].get[2]>]||li@>'
#
DUL_parse_colors_without_url:
type: procedure
debug: false
DUL:
name:
- Parse Colors Without URL
author:
- BlackCoyote
description:
- parses the color codes in the input whilst skipping the ones within URLs.
usage:
- <proc[DUL_parse_colors_without_url].context[<escape message>]>
example:
- <proc[DUL_parse_colors_without_url].context[<context.message.escaped>]>
script:
- if <def[1]||null> == null {
- determine null
}
- define message ""
- foreach <def[1].split_by[<&sp>]>:
- define string <def[value].unescaped>
- if <def[string].starts_with[http<&co>//]> || <def[string].starts_with[https<&co>//]> || <def[string].starts_with[www.]> {
- define message "<def[message]><def[string]> "
} else {
- define message "<def[message]><def[string].parse_color> "
}
- determine <def[message].trim>
DUL_rainbow_text:
type: procedure
debug: false
DUL:
name:
- Rainbow Text
author:
- BlackCoyote
description:
- Turns the colour of a text into a rainbow format with a new colour per letter.
usage:
- <proc[DUL_rainbow_text].context[<text.escaped>]>
example:
- <proc[DUL_rainbow_text].context[<context.message.escaped>]>
script:
- if <def[1].exists.not> {
- debug error "DUL - No valid text specified!"
- determine null
}
- define colormap li@<&4>|<&6>|<&e>|<&a>|<&3>|<&9>|<&5>
- define result ""
- foreach <def[1].unescaped.to_list.escape_contents>:
- define result "<def[result]><def[colormap].get[<def[loop_index].sub[1].mod[7].add[1].as_int>]><def[value]>"
- determine <def[result].unescaped>
DUL_random_numbers_by_total:
type: procedure
debug: false
DUL:
name:
- Random Numbers by Total
author:
- BlackCoyote
description:
- returns the specified amount of random positive integer numbers that always add up to the specified total.
usage:
- <proc[DUL_random_numbers_by_total].context[<amount>|<total>]>
example:
- <proc[DUL_random_numbers_by_total].context[5|100]>
definitions: amount|total
script:
- if <def[amount]||null> !matches number {
- debug error "DUL - No valid amount specified."
- determine null
}
- if <def[total]||null> !matches number {
- debug error "DUL - No valid total specified."
- determine null
}
- define numbers li@
- define currenttotal 0
- repeat <def[amount].sub[1].round>:
- define numbers <def[numbers].include[<util.random.int[1].to[<def[total].sub[<def[currenttotal]>].sub[<def[amount].sub[<def[value]>]>].round>]>]>
# new number = random int from 1 to ( specified total - current total - ( specified amount - current amount ) ) fml i hate math
- define currenttotal <def[currenttotal].add[<def[numbers].last>]>
- define numbers <def[numbers].include[<def[total].sub[<def[currenttotal]>]>]>
- determine <def[numbers].random[<def[amount]>]>
DUL_random_surface_block:
type: procedure
definitions: location|radius
debug: false
DUL:
name:
- Random Surface Block
author:
- BlackCoyote
description:
- Finds a random surface block within the provided radius more efficiently than conventional denizen tags.
usage:
- <proc[DUL_random_surface_block].context[<l@location>|<radius>]>
example:
- <proc[DUL_random_surface_block].context[<player.location>|5000]>
script:
- if <def[location]||null> !matches location {
- debug error "DUL - No valid location specified!"
- determine null
}
- if <def[radius]||null> !matches number {
- debug error "DUL - No valid radius specified!"
- determine null
}
- while true:
- define newloc <def[location].add[<util.random.int[<def[radius].mul[-1]>].to[<def[radius]>]>,0,<util.random.int[<def[radius].mul[-1]>].to[<def[radius]>]>].highest.find.surface_blocks.within[5].get[1]||null>
- if <def[newloc]> != null && <def[newloc].material.is_occluding> {
- determine <def[newloc].above>
} else if <def[loop_index]> >= 10 {
- determine null
}
DUL_rn:
# An internally faster version
type: procedure
debug: false
DUL:
name:
- Random Numbers by Total
author:
- Anthony
description:
- returns the specified amount of random positive integer numbers that always add up to the specified total.
usage:
- <proc[DUL_rn].context[<amount>|<total>]>
example:
- <proc[DUL_rn].context[5|100]>
definitions: a|t
script:
- define r li@
- define s '%a%'
- while <def[s].is[MORE].than[1]>:
- define s '<def[s].sub[1].round>'
- define n '<util.random.int[1].to[<def[t].sub[%s%].round>]>'
- define t '<def[t].sub[%n%].round>'
- define r '%r%%n%|'
- define r '%r%%t%'
- determine <def[r].random[%a%]>
#
DUL_safeString:
type: procedure
debug: false
DUL:
author:
- Anthony
name:
- Safe String
description:
- Boolean tag returns true if the string only contains lower case letters, numbers, and/or underscore _
usage:
- <proc[DUL_safeString].context[string]>
example:
- narrate <proc[DUL_safeString].context[check_this_string]>
script:
- determine '<def[1].matches[^[a-z0-9-_]+$]>'
DUL_cleanString:
type: procedure
debug: false
DUL:
author:
- Anthony
name:
- Clean String
description:
- Clean a string of any character that is not a lower case letter, number, or underscore _
usage:
- <proc[DUL_cleanString].context[string]>
example:
- narrate <proc[DUL_cleanString].context[cleanA_thi&s_string]>
script:
- determine '<def[1].replace[regex:[^a-z0-9-_]]>'
#
DUL_script_tracker:
type: world
debug: false
events:
on system time hourly:
- webget "http://stats.denizenscript.com/tracker?script=96&version=<s@DUL_version_script.yaml_key[version]>"
DUL_text_progress_bar:
type: procedure
debug: false
DUL:
name:
- Text Progress Bar
author:
- BlackCoyote
description:
- Makes a text based progress bar based on the percentage you provide.
usage:
- <proc[DUL_text_progress_bar].context[<percentage>(|<size>|<character.escaped>|<color1>|<color2>)]>
example:
- <proc[DUL_text_progress_bar].context[<player.health.percentage>]>
script:
- define percentage <def[1]||0>
- if <def[percentage].as_int||none> == none {
- define percentage 0
}
- if <def[2].exists> {
- define max <def[2]>
}
- if <def[max].as_int||none> == none {
- define max 10
}
- if <def[3].exists> {
- define char <def[3].unescaped.substring[1,1]||=>
} else {
- define char =
}
- if <def[4].exists> {
- define col1 <def[4]>
} else {
- define col1 &a
}
- if <def[5].exists> {
- define col2 <def[5]>
} else {
- define col2 &7
}
- define string <el@.pad_right[<def[max]>].with[<def[char]>]>
- define split <def[max].div[100].mul[<def[percentage]>].as_int>
- determine "<def[col1].parse_colors><def[string].substring[1,<def[split]>]><def[col2].parse_colors><def[string].substring[<def[split].add[1].as_int>,<def[max]>]>"
DUL_unique_queue_id_prefixed:
type: procedure
debug: false
DUL:
name:
- Unique Queue ID Prefixed
author:
- BlackCoyote
description:
- Gives a unique queue ID for you to use, with a specified prefix.
usage:
- <proc[DUL_unique_queue_id_prefixed].context[<prefix>]>
example:
- <proc[DUL_unique_queue_id_prefixed].context[DUL_<player>]>
script:
- define prefix <def[1]||>
- define id <def[prefix]><util.random.duuid>
- while <queue.list.parse[id].contains[<def[id]>]>:
- define id <def[prefix]><util.random.duuid>
- determine <def[id]>
DUL_unparse_colors:
type: procedure
debug: false
DUL:
name:
- Unparse Colors
author:
- BlackCoyote
description:
- unparses all the colors in your input
usage:
- <proc[DUL_unparse_colors].context[<escape message>]>
example:
- <proc[DUL_unparse_colors].context[<context.message.escaped>]>
script:
- if <def[1]||null> == null {
- determine null
}
- determine <def[1].unescaped.replace[<&ss>].with[&]>
DUL_version_script:
type: version
name: dUtilLib
id: 96
description: A collection of dscript functions and utilities written by BlackCoyote and Anthony.
version: 20
DUL_WRCG:
type: procedure
debug: false
DUL:
author:
- Anthony
name:
- Weighted Random Choice Generator
description:
- Supply a list of weight/return values and have one of the values returned to you randomly based on weight.
usage:
- <proc[DUL_WRCG].context[weight/return|...]>
example:
- give <proc[DUL_WRCG].context[10/i@apple|1/i@gold_ingot|20/i@stone]>
script:
- define l '<def[raw_context].as_list>'
- define w '0'
- foreach '<def[l].parse[before[/]]>':
- define w '<def[w].add[%value%]>'
- define number '<util.random.int[1].to[%w%]>'
- define hv '0'
- foreach '%l%':
- define ov '%hv%'
- define lv '<def[ov].add[1]>'
- define hv '<def[ov].add[<def[value].before[/]>]>'
- if %number% >= %lv% && %number% <= %hv% {
- determine '<def[value].after[/]>'
}