Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Script to stop migrants?  (Read 1534 times)

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Script to stop migrants?
« on: July 26, 2016, 02:02:12 pm »

I know that force event can trigger migrants to appear. Would it be possible to make a script that checks for such an event to occur and set it to "no migrants came"?

I want to stop migration completely for a race; formerly I've been doing that by ensuring that the civ dies out in world gen. That is no longer easily done, because breeding castes are now necessary for the civ to be placed and scholars, mercenaries, etc join the civ, keeping it artificially alive.
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

lethosor

  • Bay Watcher
    • View Profile
Re: Script to stop migrants?
« Reply #1 on: July 26, 2016, 07:09:26 pm »

It might be possible to delete the scheduled migrant events before they occur. I don't know how far in advance DF schedules them before they occur, though.
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Script to stop migrants?
« Reply #3 on: July 27, 2016, 12:56:13 am »

Aaahhhh... I forgot to send you feedback about it, didnt I? Sorry.


Code: [Select]
local function removeMigrantWaves()
    local indexesToErase={}
    for k,v in ipairs(df.global.timed_events) do
        if v.type==df.timed_event_type['Migrants'] then
            table.insert(indexesToErase,k)
        end
    end
    for i=#indexesToErase,1,-1 do
        df.global.timed_events:erase(indexesToErase[i])
    end
end

require('repeat-util').scheduleEvery('remove migrant waves',1,'ticks',removeMigrantWaves)

That works, but I have to run it from a workshop every time I load a save. I cant just put it in the onload.init, because it would stop all migration to all civs. To use it, it would need to be smart enough to know which race you are playing. Adding one argument, the civID, would be enough... it could check if the local civ is the civID in question, if yes, stop migrants; if no, do nothing.
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

Roses

  • Bay Watcher
    • View Profile
Re: Script to stop migrants?
« Reply #4 on: July 27, 2016, 09:31:21 am »

Code: [Select]
local function removeMigrantWaves()
  if df.global.world.entities.all[df.global.ui.civ_id].entity_raw.code == 'MOUNTAIN' then
    local indexesToErase={}
    for k,v in ipairs(df.global.timed_events) do
        if v.type==df.timed_event_type['Migrants'] then
            table.insert(indexesToErase,k)
        end
    end
    for i=#indexesToErase,1,-1 do
        df.global.timed_events:erase(indexesToErase[i])
    end
  end
end

require('repeat-util').scheduleEvery('remove migrant waves',1,'ticks',removeMigrantWaves)

Replace mountain with whatever entity you want.
Logged

Bogus

  • Bay Watcher
    • View Profile
Re: Script to stop migrants?
« Reply #5 on: July 28, 2016, 05:21:58 am »

Quote
That works, but I have to run it from a workshop every time I load a save.

dfhack.onStateChange should do?
Logged

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: Script to stop migrants?
« Reply #6 on: July 28, 2016, 07:57:22 pm »

In prior versions, migrant waves were only scheduled at the very beginning of the season; given what you're describing, however, it would seem to no longer be the case...
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Script to stop migrants?
« Reply #7 on: July 28, 2016, 08:25:11 pm »

His problem is operating it on a per-entity basis, not having migrants not be prevented AFAIK. The script I posted seems to work, and based on what you're saying can probably be changed to run every 1200 ticks instead of every tick.