Another conflicting variable. Replace "desireToStay(" with something else (with the opening parenthesis, e.g. "desire_to_stay(") - lines 163, 185, and 190.
Lines 163-213:
function desire_to_stay(unit,method,civ_id)
value = unit.status.happiness
if (method == 'merchant' or method == 'diplomat') and civ_id ~= unit.civ_id then value = value*2 end
if method == 'diplomat' then value = value*2 end
if method == 'wild' then value = value*5 end
if method == 'invader' then value = value*10 end
if method == 'beast' then value = value*10 end
return value
end
function checkForDeserters(method,civ_id)
allUnits = df.global.world.units.active
local u
for i=#allUnits-1,0,-1 do -- search list in reverse
if math.random (prob) == 1 then -- about once every 3000 season ticks. That should be one check per caravan, on average.
u = allUnits[i]
if dfhack.units.isCitizen(u)
and dfhack.units.isSane(u)
and u.profession ~= 103
and not dfhack.units.isDead(u) then
if canLeave(u,method) == true then
local can_Leave = true
local desireToStay = desire_to_stay(u,method,civ_id)
if u.relations.spouse_id ~= -1 then
spouse = df.unit.find(u.relations.spouse_id)
if not dfhack.units.isDead(spouse) then
if canLeave(spouse,method) then
spouse_desireToStay = desire_to_stay(spouse,method,civ_id)
assert1 = 100 --should be assertiveness of this unit
assert2 = 100 --should be assertiveness of spouse
twm = 1/(assert1+assert2)
weight1 = assert1*twm
weight2 = assert2*twm
desireToStay = (desireToStay*weight1) + (spouse_desireToStay*weight2)
else
can_Leave = false
end
end
end
if desireToStay < 1 then desireToStay = 1 end -- no divide by zero
local desertChance = 100/desireToStay
if math.random(100) < desertChance and can_Leave == true then
desert(u,method)
end
end
end
end
end
end