Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Print skill levels of a unit
- -- modified by gameboy17 from make-legendary by vjek
- local help = [====[
- checkskills
- ==============
- Prints the level and exp of each of the unit's skills.
- Color is based on skill level.
- By default, only shows skills of Novice level or greater.
- `-help`
- Print this message.
- `-all`
- Do not hide skills below Novice level.
- `-attr`
- Also print the unit's current and maximum attributes.
- Cosmetic:
- `-decimal`
- Show skill level to two decimal places rather than a separate Exp%.
- `-nodim`
- Print attribute maximum values in same colors as current values.
- `-altcol`
- Prints skills with same palette used for skills ingame.
- The default is more of a gradient.
- ]====]
- local utils=require('utils')
- validArgs = validArgs or utils.invert({
- 'help',
- 'unit',
- 'dabbling',
- 'all',
- 'decimal',
- 'attr',
- 'nodim',
- 'altcol'
- })
- local args = utils.processArgs({...}, validArgs)
- function main()
- if args.help then print(help); return; end
- local unit = tonumber(args.unit) and df.unit.find(tonumber(args.unit)) or dfhack.gui.getSelectedUnit(true)
- if not unit then print("No unit - watch me swooce right out!"); return; end
- print(dfhack.TranslateName(unit.name))
- PrintSkills(unit,args.all or args.dabbling)
- if args.attr then
- PrintAttrs(unit)
- end
- end
- function PrintSkills(unit,showdabbling)
- local soul = unit.status.current_soul
- local skillid
- local skillname
- local skilllevel
- local skillexp
- local nextexp
- local exppercent
- for k,v in ipairs(soul.skills) do
- skillid = v.id
- skillname = df.job_skill.attrs[skillid].caption
- skilllevel = v.rating
- skillexp = v.experience
- nextexp = 400+100*(skilllevel+1)
- exppercent = math.floor(100*skillexp/nextexp)
- if skilllevel > 0 or showdabbling then
- ColorByNumbers(skilllevel)
- dfhack.print(string.format("\t%-20s", skillname, skilllevel, skillexp))
- ColorByStatus(skilllevel)
- dfhack.print("Lv ")
- ColorByNumbers(skilllevel)
- dfhack.print(string.format("%2d", skilllevel))
- if args.decimal then
- dfhack.print(string.format(".%02d\t", exppercent))
- else
- ColorByStatus(skilllevel)
- dfhack.print("\tExp: ")
- ColorByNumbers(skilllevel)
- dfhack.print(string.format("%2d", exppercent).."%")
- end
- ColorByStatus(skilllevel)
- dfhack.print(string.format("\t(%-4d/%4d)",skillexp,nextexp))
- dfhack.color(COLOR_RESET)
- print()
- end
- end
- end
- function PrintAttrs(unit)
- body = unit.body
- soul = unit.status.current_soul
- --local attrid
- --local attrname
- --local attrval
- --local attrmax
- --local attrlevel
- --local attrpercent
- bodyattrnames = {"Strength","Agility","Toughness","Endurance","Recuperation","Disease Resistance"}
- soulattrnames = {"Analytical Ability","Focus","Memory","Creativity","Intuition","Focus","Willpower","Patience","Spatial Sense","Kinesthetic Sense","Linguistic Ability","Empathy","Social Awareness"}
- -- printall(body.physical_attrs)
- -- printall(bodyattrnames)
- -- printall(soul.mental_attrs)
- -- printall(soulattrnames)
- print("Body:")
- for k,v in ipairs(body.physical_attrs) do
- PrintAttr(v,bodyattrnames[k+1])
- end
- print("Soul:")
- for k,v in ipairs(soul.mental_attrs) do
- PrintAttr(v,soulattrnames[k+1])
- end
- end
- function PrintAttr(attr,attrname)
- if not attrname then return end
- local attrval = attr.value
- local attrmax = attr.max_value
- local attrpercent = math.floor(100*attrval/attrmax)
- local attrlevel = math.floor((attrval-400)/100 - 1)
- ColorByAttr(attrval,attrname,false)
- dfhack.print(string.format("\t%4d",attrval))
- ColorByStatus(attrlevel)
- dfhack.print("/")
- ColorByAttr(attrmax,attrname,true)
- dfhack.print(string.format("%-4d",attrmax))
- ColorByAttr(attrval,attrname,false)
- dfhack.print(string.format(" %-20s", attrname))
- ColorByStatus(attrlevel)
- dfhack.print("\tPotential: ")
- ColorByPercent(attrpercent)
- dfhack.print(string.format("%2d", attrpercent).."%")
- dfhack.color(COLOR_RESET)
- print()
- end
- --Set print color based on level of skill
- function ColorByNumbers(lvl)
- if not args.altcol then
- if lvl >19 then dfhack.color(COLOR_LIGHTMAGENTA)
- elseif lvl >14 then dfhack.color(COLOR_LIGHTCYAN)
- elseif lvl > 9 then dfhack.color(COLOR_LIGHTGREEN)
- elseif lvl > 5 then dfhack.color(COLOR_YELLOW)
- elseif lvl > 2 then dfhack.color(COLOR_BROWN) --RED
- elseif lvl > 0 then dfhack.color(COLOR_RED) --BROWN
- else dfhack.color(COLOR_DARKGREY)
- end
- else
- if lvl >14 then dfhack.color(COLOR_LIGHTMAGENTA)
- elseif lvl > 8 then dfhack.color(COLOR_LIGHTGREEN)
- elseif lvl > 5 then dfhack.color(COLOR_LIGHTCYAN)
- elseif lvl > 2 then dfhack.color(COLOR_GREEN)
- elseif lvl > 1 then dfhack.color(COLOR_WHITE)
- elseif lvl > 0 then dfhack.color(COLOR_LIGHTGRAY)
- else dfhack.color(COLOR_BROWN)
- end
- end
- end
- --Set print color based on whether skill is dabbling, normal, or legendary
- function ColorByStatus(lvl)
- if lvl < 1 then dfhack.color(COLOR_DARKGREY)
- elseif lvl <15 then dfhack.color(COLOR_LIGHTGRAY)
- else dfhack.color(COLOR_WHITE)
- end
- end
- --dfhack.color(skilllevel==0 and COLOR_DARKGREY or COLOR_RESET)
- --Set print color based on "level" of attribute
- --Switched some stuff around
- function ColorByAttrLvl(lvl)
- if lvl >19 then dfhack.color(COLOR_LIGHTMAGENTA)
- elseif lvl >14 then dfhack.color(COLOR_LIGHTCYAN)
- elseif lvl > 9 then dfhack.color(COLOR_LIGHTGREEN)
- elseif lvl > 5 then dfhack.color(COLOR_YELLOW)
- elseif lvl > 2 then dfhack.color(COLOR_BROWN)
- elseif lvl > 0 then dfhack.color(COLOR_RED)
- else dfhack.color(COLOR_LIGHTRED)
- end
- end
- --Set print color based on attribute value
- --Based on attribute ranges for dwarves
- function ColorByAttr(val,attr,dark)
- local thresh
- --Body
- if attr == "Strength" then thresh = {2250,2000,1750,1500,1001,751,501,251,0} end
- if attr == "Agility" then thresh = {1900,1650,1400,1150,651,401,151,0,-1} end
- if attr == "Toughness" then thresh = {2250,2000,1750,1500,1001,751,501,251,0} end
- if attr == "Endurance" then thresh = {2000,1750,1500,1250,751,501,251,1,0} end
- if attr == "Recuperation" then thresh = {2000,1750,1500,1250,751,501,251,1,0} end
- if attr == "Disease Resistance" then thresh = {2000,1750,1500,1250,751,501,251,1,0} end
- --Soul
- if attr == "Analytical Ability" then thresh = {2250,2000,1750,1500,1001,751,501,251,0} end
- if attr == "Focus" then thresh = {2542,2292,2042,1792,1293,1043,793,543,0} end
- if attr == "Willpower" then thresh = {2000,1750,1500,1250,751,501,251,1,0} end
- if attr == "Creativity" then thresh = {2250,2000,1751,1500,1001,751,501,251,0} end
- if attr == "Intuition" then thresh = {2000,1750,1500,1250,751,501,251,1,0} end
- if attr == "Patience" then thresh = {2250,2000,1750,1500,1001,751,501,251,0} end
- if attr == "Memory" then thresh = {2250,2000,1750,1500,1001,751,501,251,0} end
- if attr == "Linguistic Ability" then thresh = {2000,1750,1500,1250,751,501,251,1,0} end
- if attr == "Spatial Sense" then thresh = {2542,2292,2042,1792,1293,1043,793,543,0} end
- if attr == "Musicality" then thresh = {2000,1750,1500,1250,751,501,251,1,0} end
- if attr == "Kinesthetic Sense" then thresh = {2000,1750,1500,1250,751,501,251,1,0} end
- if attr == "Empathy" then thresh = {2000,1750,1500,1250,751,501,251,1,0} end
- if attr == "Social Awareness" then thresh = {2000,1750,1500,1250,751,501,251,1,0} end
- if not thresh then thresh = {5000,5000,5000,5000,5000,5000,5000,5000,0} end
- local colors = {
- COLOR_LIGHTMAGENTA,
- COLOR_LIGHTCYAN,
- COLOR_LIGHTGREEN,
- COLOR_GREEN,
- COLOR_YELLOW,
- COLOR_BROWN,
- COLOR_RED,
- COLOR_LIGHTRED,
- COLOR_DARKGREY
- }
- if dark and not args.nodim then colors = {
- COLOR_MAGENTA,
- COLOR_CYAN,
- COLOR_GREEN,
- COLOR_GREEN,
- COLOR_BROWN,
- COLOR_DARKGREY,
- COLOR_DARKGREY,
- COLOR_DARKGREY,
- COLOR_BLACK
- } end
- -- print(attr)
- -- print(val)
- -- printall(thresh)
- for i = 0, 9, 1 do
- if val >= thresh[i+1] then
- dfhack.color(colors[i+1])
- break
- end
- end
- end
- --Set print color based on range from 0..100
- --Intended for attribute potential percentage
- function ColorByPercent(pct)
- if pct >=100 then dfhack.color(COLOR_LIGHTMAGENTA)
- elseif pct >= 85 then dfhack.color(COLOR_LIGHTCYAN)
- elseif pct >= 70 then dfhack.color(COLOR_LIGHTGREEN)
- elseif pct >= 40 then dfhack.color(COLOR_YELLOW)
- elseif pct >= 20 then dfhack.color(COLOR_RED)
- elseif pct > 5 then dfhack.color(COLOR_BROWN)
- else dfhack.color(COLOR_DARKGREY)
- end
- end
- --Execution starts
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement