• Crusader Kings III Available Now!

    The realm rejoices as Paradox Interactive announces the launch of Crusader Kings III, the latest entry in the publisher’s grand strategy role-playing game franchise. Advisors may now jockey for positions of influence and adversaries should save their schemes for another day, because on this day Crusader Kings III can be purchased on Steam, the Paradox Store, and other major online retailers.


    Real Strategy Requires Cunning

RenoMartin

Recruit
Jun 9, 2020
1
0
Trying to mod workers in workshops milestone, because I think sometimes it bugs out. Several times during playthroughs I hit 40%+ and it didn't count.
Wanted to bring it down at 20-25% and see how it goes. My code looks like this:


function Milestone_WorkshopWorkersPercent(city, 25)
local min_interval = const.HourDuration
local max_interval = const.DayDuration
while true do
local current_percent = city and city:GetWorkshopWorkersPercent() or 0
if current_percent >= target_percent then
return true
end
local interval = min_interval + MulDivRound(max_interval - min_interval, target_percent - current_percent, target_percent)
Sleep(interval)
end
end

function OnMsg.ClassesPostprocess()
PlaceObj('Milestone', {
Complete = function (self, city)
return Milestone_WorkshopWorkersPercent(city, 25)
end,
SortKey = 16000,
bonus_score = 3000,
bonus_score_expiration = 300,
display_name = T(590068197487, --[[Milestone Default WorkersInWorkshops display_name]] "25% Workers in Workshops"),
group = "Default",
id = "WorkersInWorkshops",
reward_research = 5000,
trigger_fireworks = true,
})
end


As you can see, I don't really know what I'm doing, best I could come up with after digging in documentation. What am I doing wrong and how it should look like?

P.S. I'd also like to reduce reasearch points reward to ~5k for balance reasons.