Well that was a dumb error lol
I realized that I was calling: holiday_shamrock_thoughts()
The function was: function holiday_thoughts_shamrock()
initializing shamrock holiday
initializing shamrock countdown
shamrock tick: 19200 current tick: 16800 ticks to shamrock: 2400
calibrating leprechaun position
leprechaun positioning: [ 106 180 155 ]
extracting holiday thoughts
merrymakers thinking: 7
C:\Users\bro\Desktop\df_44_12_win\hack\lua\utils.lua:603: bad argument #1 to 'sub' (string expected, got userdata)
stack traceback:
[C]: in function 'string.sub'
C:\Users\bro\Desktop\df_44_12_win\hack\lua\utils.lua:603: in function 'utils.processArgs'
...\bro\Desktop\df_44_12_win/hack/scripts/add-thought.lua:70: in local 'script_code'
C:\Users\bro\Desktop\df_44_12_win\hack\lua\dfhack.lua:680: in function 'dfhack.run_script_with_env'
(...tail calls...)
...a\Desktop\df_44_12_win/hack/scripts/holiday_shamrock.lua:61: in global 'holiday_shamrock_thoughts'
...a\Desktop\df_44_12_win/hack/scripts/holiday_shamrock.lua:20: in function <...a\Desktop\df_44_12_win/hack/scripts/holiday_shamrock.lua:16>print("initializing shamrock holiday")
function holiday_shamrock_countdown()
local year_tick_total = 1200*28*12
local current_tick = df.global.cur_year_tick
local date_shamrock = 1200*(0*28+16)
local ticks = date_shamrock - current_tick
if ticks < 0 then
ticks = ticks + year_tick_total
end
print("initializing shamrock countdown")
print("shamrock tick:", date_shamrock, "current tick:", current_tick, "ticks to shamrock:", ticks)
dfhack.timeout(ticks+1,'ticks',holiday_shamrock)
end
function holiday_shamrock()
pos = getPositionSurface()
print("leprechaun positioning:", '[ ' ..tostring(pos.x)..' '..tostring(pos.y)..' '..tostring(pos.z).. ' ]')
dfhack.run_command("modtools/create-unit -race holiday_LEPRECHAUN -caste MALE -name PLAINS -location " .. '[ ' ..tostring(pos.x)..' '..tostring(pos.y)..' '..tostring(pos.z).. ' ]')
holiday_shamrock_thoughts()
dfhack.gui.showPopupAnnouncement("The Shamrock Holiday has come! A day of mischief and merriment, this festival celebrates the middle of Spring, when day and night are equal. Keep a watchful eye and guard your valuables. This is the day of the leprechaun!", COLOR_WHITE , true )
holiday_shamrock_countdown()
end
function getPositionSurface()
print("calibrating leprechaun position")
local rand = dfhack.random.new()
local mapx, mapy, mapz = dfhack.maps.getTileSize()
randx = rand:random(mapx)
randy = rand:random(mapy)
local pos = {}
pos.x = randx
pos.y = randy
pos.z = mapz - 1
local j = 0
while dfhack.maps.ensureTileBlock(pos.x,pos.y,pos.z-j).designation[pos.x%16][pos.y%16].outside do
j = j + 1
end
pos.z = pos.z - j + 1
return pos
end
function holiday_shamrock_thoughts()
print("extracting holiday thoughts")
local units = {}
local n = 0
for i,unit in pairs(df.global.world.units.active) do
if dfhack.units.isDwarf(unit) then
n = n + 1
units[n] = unit
end
end
print("merrymaker thinking:",n)
while n > 0 do
local holiday_thought_type = math.random(4)
if (holiday_thought_type == 1) then
dfhack.run_script("add-thought", "-unit",units[n],"-thought","ENJOYMENT","-severity",1)
elseif (holiday_thought_type == 2) then
dfhack.run_script("add-thought", "-unit",units[n],"-thought","AMUSEMENT","-severity",1)
elseif (holiday_thought_type == 3) then
dfhack.run_script("add-thought", "-unit",units[n],"-thought","DELIGHT","-severity",1)
elseif (holiday_thought_type == 4) then
-- no thought
end
units[n] = nil
n = n - 1
end
end
holiday_shamrock_countdown()
So, I changed the code to match the dfhack.run_command (like the create-unit) and got the following error:
initializing shamrock holiday
initializing shamrock countdown
shamrock tick: 19200 current tick: 16800 ticks to shamrock: 2400
calibrating leprechaun position
leprechaun positioning: [ 167 133 177 ]
extracting holiday thoughts
merrymakers thinking: 7
add-thought -unit is not a recognized command.
add-thought -unit is not a recognized command.
add-thought -unit is not a recognized command.
add-thought -unit is not a recognized command.
add-thought -unit is not a recognized command.
add-thought -unit is not a recognized command.initializing shamrock countdown
shamrock tick: 19200 current tick: 19201 ticks to shamrock: 403199
print("initializing shamrock holiday")
function holiday_shamrock_countdown()
local year_tick_total = 1200*28*12
local current_tick = df.global.cur_year_tick
local date_shamrock = 1200*(0*28+16)
local ticks = date_shamrock - current_tick
if ticks < 0 then
ticks = ticks + year_tick_total
end
print("initializing shamrock countdown")
print("shamrock tick:", date_shamrock, "current tick:", current_tick, "ticks to shamrock:", ticks)
dfhack.timeout(ticks+1,'ticks',holiday_shamrock)
end
function holiday_shamrock()
pos = getPositionSurface()
print("leprechaun positioning:", '[ ' ..tostring(pos.x)..' '..tostring(pos.y)..' '..tostring(pos.z).. ' ]')
dfhack.run_command("modtools/create-unit -race holiday_LEPRECHAUN -caste MALE -name PLAINS -location " .. '[ ' ..tostring(pos.x)..' '..tostring(pos.y)..' '..tostring(pos.z).. ' ]')
holiday_shamrock_thoughts()
dfhack.gui.showPopupAnnouncement("The Shamrock Holiday has come! A day of mischief and merriment, this festival celebrates the middle of Spring, when day and night are equal. Keep a watchful eye and guard your valuables. This is the day of the leprechaun!", COLOR_WHITE , true )
holiday_shamrock_countdown()
end
function getPositionSurface()
print("calibrating leprechaun position")
local rand = dfhack.random.new()
local mapx, mapy, mapz = dfhack.maps.getTileSize()
randx = rand:random(mapx)
randy = rand:random(mapy)
local pos = {}
pos.x = randx
pos.y = randy
pos.z = mapz - 1
local j = 0
while dfhack.maps.ensureTileBlock(pos.x,pos.y,pos.z-j).designation[pos.x%16][pos.y%16].outside do
j = j + 1
end
pos.z = pos.z - j + 1
return pos
end
function holiday_shamrock_thoughts()
print("extracting holiday thoughts")
local units = {}
local n = 0
for i,unit in pairs(df.global.world.units.active) do
if dfhack.units.isDwarf(unit) then
n = n + 1
units[n] = unit
end
end
print("merrymakers thinking:",n)
while n > 0 do
local holiday_thought_type = math.random(4)
if (holiday_thought_type == 1) then
dfhack.run_command("add-thought -unit" , ' ..units[n].. ' , "-thought ENJOYMENT -severity 1")
elseif (holiday_thought_type == 2) then
dfhack.run_command("add-thought -unit" , ' ..units[n].. ' , "-thought AMUSEMENT -severity 1")
elseif (holiday_thought_type == 3) then
dfhack.run_command("add-thought -unit" , ' ..units[n].. ' , "-thought DELIGHT -severity 1")
elseif (holiday_thought_type == 4) then
-- no thought
end
units[n] = nil
n = n - 1
end
end
holiday_shamrock_countdown()
EDIT: I was thinking it could be the following, but it didn't like that one either.
dfhack.run_command("add-thought" , ' ..tostring(units[n]).. ' , DELIGHT 1")
I'll keep messing with it. Once I get these thoughts working and the mischievous/curiousitem tags working the Shamrock holiday should be done