Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3

Author Topic: Example for running dfhack scripts from workshops.  (Read 6270 times)

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Example for running dfhack scripts from workshops.
« on: March 17, 2013, 10:49:56 am »

Hi everyone,

I thought it would be nice to give a little example of what you can do with expwnents autosyndrome, besides applying syndromes directly to people. This alone is huge, but it can do even more. The script can run dfhack commands from a reaction. This means your dwarves can control dfhack.

Here is a small example: Running 'siren' from a reaction. I made a little building, called the Alarm Siren. It needs a mechanism to be build, any dwarf can run the reaction, which is called: Sound the alarm. When this is done, dfhack will automatically run the siren script. What it does? Siren Script Readme: Wakes up sleeping units, cancels breaks and stops parties either everywhere, or in the burrows given as arguments. In return, adds bad thoughts about noise, tiredness and lack of protection. Also, the units with interrupted breaks will go on break again a lot sooner. The script is intended for emergencies, e.g. when a siege appears, and all your military is partying.

This is how it looks ingame:


Spoiler: Entity File: (click to show/hide)

Spoiler: Inorganic File: (click to show/hide)

Spoiler: Reaction File: (click to show/hide)

Spoiler: Building File: (click to show/hide)

Edit*: The STONE_VAPOR_TEMPLATE is a simple stone template copy that boils away on 8000 urist and has a fixed temperature of 8100 urist.

And this is it. Any script can be called. Following things have to be considered when using this:
  • You need to create a boiling rock that is below or equal to 9000 Urist.
  • You need the \COMMAND as the first syn_class.
  • You need the wanted script as the second syn_class.
  • If you have two words, for example "weather rain", you have to make two syn_classes. One called "weather" and a second one "rain"
  • You can add as many scripts to one material as you want, but only one command on each syndrome.
  • If you want two commands, simply add two syndromes to the material, using two \COMMAND syn_classes.

Hope this helps people using this awesome feature. I can already think of many uses, especially religious and magic-related. Ceremony of True-Sight = reveal, Pray to Armok to smite your opponents = killrace goblin, Invoke elven nature magic = grow/regrass, Activate weather control device = weather rain.

Useful links:
DFHACK README
Expwnents How-To Autosyndrome Post
Autosyndrome Source Code on Github

If anyone has suggetions on how to further use this, please feel free to post them here. :)

Edit: Just wanted to add that you need dfhack r3 for this, and that everything posted here is of course open source. If you want to use it in a mod, just copy it. :)
« Last Edit: August 21, 2013, 04:52:22 pm by Meph »
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 :::

narhiril

  • Bay Watcher
  • [DUTY_BOUND]
    • View Profile
Re: Example for running dfhack scripts from workshops.
« Reply #1 on: March 17, 2013, 02:29:57 pm »

It's so beautiful...  *sniff*

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Example for running dfhack scripts from workshops.
« Reply #2 on: March 17, 2013, 02:33:38 pm »

Yes, this is pretty nice. I could write some simple scripts with this in mind. I think that scripts can target the worker, yes?

Spirit of Power

  • Bay Watcher
    • View Profile
Re: Example for running dfhack scripts from workshops.
« Reply #3 on: March 17, 2013, 02:38:08 pm »

So... I could have a custom workshop which has a job which will, say, transform the dwarf who does it into a bronze colossus?

Looks like I might have to revisit that Mobile Suit Gundam: Dwarf Fortress idea I had a while back...
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Example for running dfhack scripts from workshops.
« Reply #4 on: March 17, 2013, 02:56:32 pm »

So... I could have a custom workshop which has a job which will, say, transform the dwarf who does it into a bronze colossus?

Looks like I might have to revisit that Mobile Suit Gundam: Dwarf Fortress idea I had a while back...

You could have done that way back when 34.01 was released with syndrome boiling rocks. Autosyndrome makes them far, far more efficient, though.

smakemupagus

  • Bay Watcher
  • [CANOPENDOORS]
    • View Profile
Re: Example for running dfhack scripts from workshops.
« Reply #5 on: March 17, 2013, 03:04:18 pm »

Very cool 8)
I saw those descriptions in autosyndrome but didn't really understand it, thanks for explaining !


Yes, this is pretty nice. I could write some simple scripts with this in mind. I think that scripts can target the worker, yes?

I think that's true, autosyndrome has "\WORKER_ID" and "\LOCATION", which I guess can be used provide target for scripts like removebadthoughts or digvein?
« Last Edit: March 17, 2013, 03:08:45 pm by smakemupagus »
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Example for running dfhack scripts from workshops.
« Reply #6 on: March 17, 2013, 03:27:42 pm »

Location for digv might be difficult, since it would be a specific location. You would have to make a 1tile-mining workshop with 4 reactions. One for each direction. Problem is that the location would target the workshop and not the tile nearby. I dont think its possible with the current script behind it, but should be easy to write. Though I doubt the usefulness of this. Currently its this:
 "\LOCATION": The next three arguments passed to whatever command are the x, y, and z coordinate of the work tile of the building which triggered the reaction.

This means all scripts that need a location will always target the work-tile of the workshop. You cant give it different locations atm.

Worker_Id does indeed target the worker. Removebradthoughts would be possible for example.
"\WORKER_ID": The next argument passed to whatever command is the id of the worker who did the reaction.

@Spirit of Power: Yes, no problem. Again, you can do this even without dfhack. Problem is that the bronze colossus is not a civ-member and you loose control over the creature. Only solution is to make a bronze-colossus caste which does (almost) not occur naturally. Its all a bit tricky, but in theory completely possible.
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 :::

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Example for running dfhack scripts from workshops.
« Reply #7 on: March 17, 2013, 03:44:44 pm »

I made a script that could work with this:

Code: [Select]
-- Forces an attack from the civ type or number (don't use if you don't know!) specified. If no civ is specified, it will use the first valid babysnatcher civ found. Note that the siege won't happen unless progress triggers are already met.

local function findBabysnatcherCiv()
for eid,entity in ipairs(df.global.world.entities.all) do
if entity.entity_raw.flags.BABYSNATCHER == true then return entity end
end
end

local function progressTriggersMet(entity)
local siegeEntity = entity.entity_raw.progress_trigger --evil, but readable
local fortress = df.global.ui
if fortress.progress_population < siegeEntity.pop_siege and fortress.progress_trade < siegeEntity.prod_siege and fortress.progress_production < siegeEntity.prod_siege then return false end
return true
end

local function findCivWithGivenToken(arg)
local entities = df.global.world.entities.all
if tonumber(arg) then
local argnumber = tonumber(arg)
if argnumber > #entities then qerror("There aren't that many civs in the world!") end
return entities[argnumber]
end
if arg and not tonumber(arg) then
for eid,entity in ipairs(entities) do
if entity.entity_raw.code == arg then return entity end
end
end
dfhack.gui.showAnnouncement("The civilization you want to challenge does not exist on this world.",COLOR_YELLOW)
qerror("Civ not found. Aborting!")
end

argument = ...

local function force_siege()
local siegeEntity
if argument
then siegeEntity = findCivWithGivenToken(argument)
else siegeEntity = findBabysnatcherCiv()
end
if not progressTriggersMet(siegeEntity) then
dfhack.gui.showAnnouncement("The civilization you want to challenge isn't even interested in you.",COLOR_YELLOW)
qerror("Progress triggers not met.")
end
df.global.timed_events:insert('#', { new = df.timed_event, type = df.timed_event_type.CivAttack, season = df.global.cur_season, season_ticks = df.global.cur_season_tick, entity = siegeEntity } )
end

force_siege()

It forces a siege, simply enough. You have to have met the progress triggers, but if you have, the siege comes instantly. For a goblin siege, it would look like this:

Code: [Select]
  [SYNDROME]   
 [SYN_CLASS:\COMMAND]
   [SYN_CLASS:forcesiege] assuming you named the script "forcesiege"
   [SYN_CLASS:EVIL]
         [SYN_NAME:siren]
         [SYN_CONTACT]
         [SYN_INHALED]
         [SYN_AFFECTED_CREATURE:DWARF:ALL][SYN_AFFECTED_CREATURE:KOBOLD_CAMP:ALL]
   [CE_SPEED_CHANGE:SPEED_PERC:100:START:0:END:1]

EDIT: Updated with Meph's gripes :V
« Last Edit: March 17, 2013, 06:03:57 pm by Putnam »
Logged

IamanElfCollaborator

  • Bay Watcher
  • Resident Shipper God and Freyjapiller
    • View Profile
Re: Example for running dfhack scripts from workshops.
« Reply #8 on: March 17, 2013, 03:51:56 pm »

Sounds interesting.

Terraria Goblin Standard anyone?

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Example for running dfhack scripts from workshops.
« Reply #9 on: March 17, 2013, 04:09:37 pm »

Ahh.. I heard about that, Quietust posted this a while back, yes? Or did you write it yourself? I think megabeasts and fbs can be triggered too, if I am not mistaken.

That would of course be a nice addition. "Sound the horn of war"  :)

[SYN_CLASS:EVIL] => EVIL is the entity-id, I assume? so SKULKING for kobolds and PLAINS for humans and so forth ?

I would totally include that, if you can post a .dll/.lua file :)
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 :::

IamanElfCollaborator

  • Bay Watcher
  • Resident Shipper God and Freyjapiller
    • View Profile
Re: Example for running dfhack scripts from workshops.
« Reply #10 on: March 17, 2013, 04:10:58 pm »

Hm..I could use this for a mod I'm working on.

Could this be applied to individual creatures?

Also, I just realized we could use this as a teleport homer ala Warhammer 40k.

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Example for running dfhack scripts from workshops.
« Reply #11 on: March 17, 2013, 04:14:02 pm »

Feel free to use it.

Could WHAT be applied to individual creatures? You can target the worker inside the workshop, OR any valid target inside the workshop. Or just one pet, not the worker. I use it to armor my wardogs for example.

Teleporter cant be done with this, at least not without changing the script behind it. But yes, teleporting workers from workshop A to B can be done. But the pathfinding would never recognize it.
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 :::

IamanElfCollaborator

  • Bay Watcher
  • Resident Shipper God and Freyjapiller
    • View Profile
Re: Example for running dfhack scripts from workshops.
« Reply #12 on: March 17, 2013, 04:19:01 pm »

I meant the script for siegers.

I was asking if it could be applied to an individual creature, and the teleport homer I meant was a siege of dreadnoughts.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Example for running dfhack scripts from workshops.
« Reply #13 on: March 17, 2013, 04:21:00 pm »

Ahh.. I heard about that, Quietust posted this a while back, yes? Or did you write it yourself? I think megabeasts and fbs can be triggered too, if I am not mistaken.

That would of course be a nice addition. "Sound the horn of war"  :)

[SYN_CLASS:EVIL] => EVIL is the entity-id, I assume? so SKULKING for kobolds and PLAINS for humans and so forth ?

I would totally include that, if you can post a .dll/.lua file :)

Yes, EVIL is the entity-id. I did post a lua file, just put it into a file, name the file forcesiege.lua, and there you have it :V it DOES actually work that way for lua scripts!

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Example for running dfhack scripts from workshops.
« Reply #14 on: March 17, 2013, 04:34:04 pm »

Tested, works in a way...

Progress triggers not met, although I meet ONE of them. Usually thats enough. I spawned a couple of adamantine items to skyrocket fort value, but goblins wont come. Instead I get the announcement that they are not interested in me. Either DF needs some time to recognize the fort value (I will wait till next season and try again) OR your script needs all three met, not just one.

The announcement ingame is a bit strange btw. While grammatically correct, it sounds strange to me, but I am not a native english speaker.
Quote
The civilization you want to siege you arent even interested in you.

I personally would change it to "challenge" The civilization you want to challenge isnt even interested in you.

AND THATS PERFECT FOR THE EXPEDITION SYSTEM. HAHAHAHA. Raid drow underdark? Have a low chance that this script runs. Oh, soooo perfect. :)
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 :::
Pages: [1] 2 3