Created
March 27, 2016 15:47
-
-
Save warmist/13f33e01fa817f0c0f2c to your computer and use it in GitHub Desktop.
A needs manipulation script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- this following part is for our documentation | |
--[[=begin | |
needs | |
===== | |
shows needs of a unit. | |
=end]] | |
local args={...} --let's get the command line arguments to a nice table | |
--nice scripts use various tools to get args from commandline, this is just a quick script, not for production use! | |
local action=args[1] -- what do we want to do | |
local unit=dfhack.gui.getSelectedUnit() --get selected unit. You need to be in "z" view for adventure mode | |
local needs=unit.status.current_soul.personality.unk_v4201_1a --this will change with next dfhack version. Probably last part will be just "needs" | |
if action=="list" then | |
for i,v in ipairs(needs) do --iterate over all needs | |
local need_name=df.need_type[v.unk_0] --get the name | |
print(need_name,v.unk_8,v.unk_c) | |
end | |
elseif action=="add" then | |
local need_type=df.need_type[args[2]] --this converts from string to number for need_type | |
local focus_level=tonumber(args[3]) --goes to 400 when unit satisfies need | |
local need_level=tonumber(args[4]) --how fast focus_level decreases when it below 0 | |
needs:insert("#",{new=true,unk_0=need_type,unk_4=-1,unk_8=focus_level,unk_c=need_level}) --now this is a strange thing | |
--insert accepts id for first param. If you replace it with "#" it inserts at the end. | |
--Also dfhack gladly converts a table with value new=true to a type you need, so you can skip the nasty type definitions | |
--also it accepts key-value pairs and sets the inserted structure fields to those | |
elseif action=="fulfill" then | |
if args[2]=="all" then --if you pass "all" instead of id | |
for i,v in ipairs(needs) do --iterate over all the needs | |
v.unk_8=400 --fulfilling them | |
end | |
else | |
local to_fulfill=tonumber(args[2]) --get the id to fulfill | |
needs[to_fulfill].unk_8=400 --fulfill it! | |
end | |
elseif action=="remove" then | |
local to_remove=tonumber(args[2]) --get the id to remove | |
needs:erase(to_remove) --remove it | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment