Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 31 32 [33] 34 35 ... 42

Author Topic: [DFHack] Roses' Script Collection Updated 5/4/15  (Read 125392 times)

milo christiansen

  • Bay Watcher
  • Something generic here
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 12/11/15
« Reply #480 on: December 27, 2014, 06:03:45 pm »

Rubble comes with an addon that triggers this bug, simply activate "User/Speluncaphobia" and "User/Speluncaphobia/DFHack" (plus any other needed/wanted addons). Embark as saurians or humans ("User/Saurian" or "User/Human/Playable") or modify the config vars so that dwarves will get speluncaphobia (use the web UI config var editor, should be obvious what to change).

The instant you unpause the game it will crash, this can be avoided by commenting out the two calls to item-trigger in the onload.init file.
Logged
Rubble 8 - The most powerful modding suite in existence!
After all, coke is for furnaces, not for snorting.
You're not true dwarven royalty unless you own the complete 'Signature Collection' baby-bone bedroom set from NOKEAS

expwnent

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 12/11/15
« Reply #481 on: December 27, 2014, 06:28:39 pm »

It's a crash to desktop when you unpause fort mode after doing even a basic onEquip. It sounds like the problem is in EventManager in the EQUIPMENT_CHANGE event but I'm not sure because it never crashes on my computer.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 12/11/15
« Reply #482 on: December 27, 2014, 06:36:45 pm »

What's your computer all up ins?

milo christiansen

  • Bay Watcher
  • Something generic here
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 12/11/15
« Reply #483 on: December 27, 2014, 07:09:29 pm »

All my testing was done on a 64 bit Windows 7 machine, maybe expwnent uses Linux? (that would tie things up nicely, but something obvious like that is probably too much to hope for)

Edit: Going to bed now, so I cant answer questions until I get up ~1-2 am EST (weird schedule...)
« Last Edit: December 27, 2014, 07:12:42 pm by milo christiansen »
Logged
Rubble 8 - The most powerful modding suite in existence!
After all, coke is for furnaces, not for snorting.
You're not true dwarven royalty unless you own the complete 'Signature Collection' baby-bone bedroom set from NOKEAS

expwnent

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 12/11/15
« Reply #484 on: December 27, 2014, 07:26:14 pm »

64 bit windows 8, but I can also test on 32 bit arch linux next time I get a chance. Slightly more work to do that.
Logged

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 12/11/15
« Reply #485 on: December 28, 2014, 12:13:12 am »

Hmm, very strange. I've got a 64 bit Windows 7 and it is crashing for me as well. The odd thing is that it is crashing after it had already done everything. I put dozens of print statements throughout the entire script, and they were all correctly triggered. And in the eventful function itself I placed three print statements, all of which printed correctly.
Code: [Select]
eventful.onInventoryChange.equipmentTrigger = function(unit, item, item_old, item_new)
 if item_old and item_new then
  return
 end
 
 local isEquip = item_new and not item_old
 print(item_new,item_old,item,unit)
 print('Before equip handler')
 equipHandler(unit,item,isEquip)
 print('After equip handler')
end
I have no idea what could be causing the crash. Testing in fort/adventure/arena mode all produced the same result.

This was tested by creating a new world with a and embarking with an expedition with a zinc pick. The zinc pick came already equipped on one of the miners. I then ran
Code: [Select]
modtools/item-trigger -material INORGANIC:ZINC -onEquip -command [ modtools/add-syndrome -help ]Running this before the game unpaused for the first time gave no errors and only crashed once the game was unpaused. If I unpaused the game first, then paused it again and ran the above command it would crash straight away without needing to be unpaused. Even using a material that none of my units had caused the crash.

My only thought is that there is something in the closing or reopening of the eventful script that it doesn't like. Let me know if I can provide any other information, or if I can test anything else out.
Logged

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 12/11/15
« Reply #486 on: December 29, 2014, 03:49:11 am »

With everything commented out except for
Code: [Select]
local eventful = require 'plugins.eventful'
eventful.enableEvent(eventful.eventType.INVENTORY_CHANGE,5)
It is still crashing to desktop for me. Which is I guess why you said the culprit seems to be in the EventManager. I have no idea why it would be crashing for some and not for others. I suppose we could try having expwnent upload his entire folder and then I could try that, just in case there is some dependency or something I that I don't have.
Logged

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 12/11/15
« Reply #487 on: December 30, 2014, 08:26:40 pm »

So the event system is almost done, it has unfortunately taken me longer than I would have liked, but it has some neat functionality. One such example is the changing merchant stall. By using the event system it is possible to have a different "merchant" arrive each week/month/season at your fort by changing the merchant stall building to a different merchant stall building. This, of course, can be used for any building. More examples will be coming with the release, but basically anything you can do with scripts manually can be automated and randomized, giving the player the sense of a "living world", hence the Event System.

Edit: forgot to mention. I'm writing another script that replaces the dfhack wait function (the one that let's you run a script after a certain delay). This will do the same thing except it will keep track of the function calls between save and reload
« Last Edit: December 30, 2014, 11:14:42 pm by Roses »
Logged

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 12/11/15
« Reply #488 on: January 08, 2015, 02:42:32 am »

The event system is done! And for the most part it works well. Because I don't think anyone is clamoring to use it I am going to hold off on uploading it until I test it some more and add some of the other things from my to-do list. In order to get people thinking about it a little bit I have made two examples.

The first allows for a simulation of merchants arriving randomly each month, chosen between 7 different options with different weightings.
Code: [Select]
[EVENT:MERCHANT_ARRIVAL]
 [NAME:a new merchant arrives]
 [REQUIREMENT:BUILDING:EMPTY_MERCHANTS_STALL]
 [CHECK:MONTHLY]
 [CHANCE:100]
 [DELAY:0]
 [EFFECT:1]
  [EFFECT_NAME:merchants arrive for a short time]
  [EFFECT_CHANCE:100]
  [EFFECT_DELAY:0]
  [EFFECT_ARGUMENT:1]
   [ARGUMENT_WEIGHTING:100,100,100,10,10,10,1]
   [ARGUMENT_VARIABLE:HUMAN_MERCHANT,ELF_MERCHANT,DWARF_MERCHANT,TRAVELING_MERCHANT.GOBLIN_MERCHANT,KOBOLD_MERCHANT,EXOTIC_MERCHANT]
  [EFFECT_SCRIPT:"building/change -from EMPTY_MERCHANTS_STALL -to !ARG_1 -dur 25200"]

The second simulates a goblin siege depending on how many goblins you have killed in the past.
Code: [Select]
[EFFECT:GOBLIN_SIEGE]
 [NAME:goblins begin to siege your fortress]
 [CHECK:MONTHLY]
 [CHANCE:10]
 [DELAY:16800]
 [REQUIREMENTS:KILL:GOBLIN:50]
 [EFFECT:1]
  [EFFECT_NAME:a small unit of goblins appears]
  [EFFECT_CHANCE:100]
  [EFFECT_DELAY:0]
  [EFFECT_LOCATION:SURFACE:EDGE:RANDOM]
  [EFFECT_SCRIPT:"unit/spawn -unit GOBLIN -number 10 -location !LOCATION"]
 [EFFECT:2]
  [EFFECT_NAME:more goblins appear]
  [EFFECT_CHANCE:80]
  [EFFECT_CONTINGENT:1]
  [EFFECT_REQUIREMENT:KILL:GOBLIN:75]
  [EFFECT_DELAY:100]
  [EFFECT_LOCATION:EFFECT:1]
  [EFFECT_SCRIPT:"unit/spawn -unit GOBLIN -number 15 -location !LOCATION"]
 [EFFECT:3]
  [EFFECT_NAME:a mass of goblins appear]
  [EFFECT_CHANCE:50]
  [EFFECT_CONTINGENT:2]
  [EFFECT_REQUIREMENT:KILL:GOBLIN:125]
  [EFFECT_DELAY:200]
  [EFFECT_LOCATION:EFFECT:1]
  [EFFECT_SCRIPT:"unit/spawn -unit GOBLIN -number 30 -location !LOCATION"]
 [EFFECT:4]
  [EFFECT_NAME:the entire goblin horde has arrived]
  [EFFECT_CHANCE:10]
  [EFFECT_CONTINGENT:3]
  [EFFECT_REQUIREMENT:KILL:GOBLIN:200]
  [EFFECT_DELAY:200]
  [EFFECT_LOCATION:EFFECT:1]
  [EFFECT_SCRIPT:"unit/spawn -unit GOBLIN -number 100 -location !LOCATION"]

Now obviously I need to write up a tutorial like I have for the Class and Civilization Systems, but just wanted to get this little teaser out tonight.
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: [DFHack] Roses' Script Collection Updated 12/11/15
« Reply #489 on: January 08, 2015, 12:41:04 pm »

Tutorial would be nice, yes. :P

Seems you found some way to get caravans and invaders back, in a fashion. Thats very good to hear.
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: [DFHack] Roses' Script Collection Updated 12/11/15
« Reply #490 on: January 12, 2015, 03:02:07 pm »

Events and You!

Today I will be talking about the Event System

Have you ever thought to yourself, "There aren't enough random events that occur while I play, I wish I could get a double mega-beast attack, or meteors could fall from the sky"? If so, then this is for you!

The Event System allows you to program customizable events to randomly occur while playing. Anything that is do-able with DFHack scripts is able to be triggered by this systems. Events are triggered randomly depending on specified requirements and checked at various intervals.

This means that you can have a lot of customization in your game! So let's start by going over what you will need.
  • Dwarf Fortress
  • DFHack
  • My Script Collection
The files in my script collection that are related to the Civilization System:
  • hack/lua/events/requirement-check.lua
  • hack/lua/events/findunit.lua
  • hack/lua/events/finditem.lua
  • hack/lua/events/findlocation.lua
  • hack/lua/events/findbuilding.lua
  • hack/scripts/events/trigger.lua
  • hack/scripts/base/events.lua
  • raw/objects/event.txt
So now that we know what it does, and we know what we need. How do we get started? Well for virtually everything you want to do, the only file you will need to modify is the event.txt file.

So let's take a look at event.txt
Code: [Select]
[EVENT:SAMPLE_EVENT]
 [NAME:this is a sample event]
 [CHECK:MONTHLY]
 [CHANCE:10]
 [DELAY:RANDOM:12000]
 [REQUIREMENT:BUILDING:SAMPLE_WORKSHOP:1]
 [REQUIREMENT:COUNTER:SAMPLE_COUNTER:10]
 [REQUIREMENT:TIME:10000]
 [REQUIREMENT:POPULATION:50]
 [REQUIREMENT:WEALTH:TOTAL:10000]
 [REQUIREMENT:CLASS:SAMPLE_CLASS:3]
 [REQUIREMENT:SKILL:MINER:15]
 [REQUIREMENT:KILLS:GOBLIN:10]
 [REQUIREMENT:DEATHS:ALL:50]
 [REQUIREMENT:TRADES:PLAINS:5]
 [REQUIREMENT:SIEGES:EVIL:5]
 [EFFECT:1]
  [EFFECT_NAME:first sample effect of the event]
  [EFFECT_CHANCE:100]
  [EFFECT_DELAY:STATIC:100]
  [EFFECT_CONTINGENT:0]
  [EFFECT_ARGUMENT:1]
  *EFFECT_REQUIREMENT:* <- same as for just normal REQUIREMENT
   [ARGUMENT_WEIGHTING:100,100,100,10,10,10,1]
   [ARGUMENT_VARIABLE:HUMAN_MERCHANT,ELF_MERCHANT,DWARF_MERCHANT,TRAVELING_MERCHANT.GOBLIN_MERCHANT,KOBOLD_MERCHANT,EXOTIC_MERCHANT]
  [EFFECT_SCRIPT:"building/change -from EMPTY_MERCHANTS_STALL -to !ARG_1 -dur 25200"]
That includes all of the currently supported tokens for each event. Note that the X in [EVENT:X] must be the unique. Now let's talk about what each one does.

Starting with the event declaration itself;
Event Tokens
Base Tokens
These tokens are mandatory for each event, and should only occur once. If they are repeated, they will be overwritten.
  • [NAME] - what the event is called, not currently used for anything, but will be included later
  • [CHECK] - how often to check if they event should be triggered. Valid entries inlude
    • DAILY
    • WEEKLY
    • MONTHLY
    • SEASON
    • YEARLY
  • [CHANCE] - the percentage chance that the event will be triggered
  • [DELAY] - the amount of time, in in-game ticks, after the check that the event should be triggered. Can be either a STATIC delay or a RANDOM delay.
Requirement Tokens
These tokens specify what requirements must be met in order for the event to be triggered. They can be combined in any number of ways.
  • COUNTER - for use with the counters script
  • TIME - checks the age of the fortress, in in-game ticks
  • POPULATION - checks the population of the fortress
  • WEALTH - checks the wealth of the fortress, Valid secondary tokens include;
    • TOTAL - checks total wealth
    • IMPORTED - checks imported wealth
    • EXPORTED - checks exported wealth
    • WEAPONS - checks cumulative value of all weapons
    • ARMOR - checks cumulative value of all armor
    • FURNITURE - checks cumulative value of all furniture
    • DISPLAYED - checks cumulative value of all displayed items
    • HELD - checks cumulative value of all held items
    • ARCHITECTURE - checks cumulative wealth of all architecture
    • OTHER - no idea, everything else I guess?
  • BUILDING - checks for a number of specified custom workshops and furnaces
  • SKILL - checks for any units that have a specified skill at a specified level
  • CLASS - for use with the Class System, checks for a number of units with the specified class
  • KILLS - checks for a specific amount of kills
  • DEATHS - checks for a specific amount of deaths
  • TRADES - checks for a specific number of trades
  • SIEGES - checks for a specific number of sieges

With the event tokens specified we can move on to the effect tokens, which is where the magic actually happens.

Effect Tokens
Base Tokens
The same as the base event tokens, these tokens must occur once for each effect.
  • [EFFECT_NAME] - name of the effect, not currently used
  • [EFFECT_CHANCE] - chance the effect will be triggered after the event has already been triggered
  • [EFFECT_DELAY] - delay of effect triggering, cumulative with event [DELAY]
Requirement Tokens
The exact same as the event requirement tokens, just change [REQUIREMENT] to [EFFECT_REQUIREMENT], with one addition.
[EFFECT_CONTINGENT] specifies that a previous effect must have triggered in order for the current effect to trigger.
Script Tokens
The effects are where the scripts are actually run, and can contain as many scripts as you would like. The scripts are specified just as they would be on the command line with a few differences for special inputs. The following special inputs are used to modify the scripts.
  • !UNIT - for use with [EFFECT_UNIT]
  • !LOCATION - for use with [EFFECT_LOCATION]
  • !BUILDING - for use with [EFFECT_BUILDING]
  • !ITEM - for use with [EFFECT_ITEM]
  • !ARG_X - for use with [EFFECT_ARGUMENT:X]
[EFFECT_UNIT]
This is how the effect identifies a unit to send to the script being run. Valid arguments include
  • RANDOM - picks any active unit
  • RANDOM:CIVILIZATION - picks any active unit that is a member of your forts civilzation
  • RANDOM:POPULATION - picks any active unit that is a member of your fort
  • RANDOM:INVADER - picks any unit that is currently invading your fort
  • RANDOM:MALE - picks any male on the map
  • RANDOM:FEMALE - picks any female on the map
  • RANDOM:PROFESSION:PROFESSION_NAME - picks any unit of the given profession
  • RANDOM:CLASS:CLASS_NAME - for use with the Class System, picks any unit of the given class
  • RANDOM:SKILL:SKILL_NAME:VALUE - picks any unit with the specified skill/value combination
  • RANDOM:CREATURE:CASTE - picks any unit of the specified creature/caste combination
[EFFECT_LOCATION]
Use this when you need to pass a location to a script
  • RANDOM - picks any location on the map
  • RANDOM:SURFACE - picks any location on the surface
  • RANDOM:SURFACE:EDGE - picks any location on the surface on an edge
  • RANDOM:SURFACE:CENTER:X - picks any location on the surface within X tiles of the x,y center
  • RANDOM:UNDERGROUND - picks any location underground (this includes inside stone walls and the like)
  • RANDOM:UNDERGROUND:CAVERN:X - picks any open location in a specified cavern level
  • RANDOM:SKY - picks any location above the surface
  • RANDOM:SKY:EDGE - picks any location above the surface on an edge
  • RANDOM:SKY:CENTER:X - picks any location above the surface within X tiles of the x,y center
[EFFECT_ITEM]
When you need an item ID for a script you can use this. Valid arguments include
  • RANDOM - picks any item on the map at random
  • RANDOM:WEAPON - picks any weapon on the map, can include an optional :SUBTYPE
  • RANDOM:ARMOR - picks any armor on the map, can include an optional :SUBTYPE
  • RANDOM:HELM - picks any helm on the map, can include an optional :SUBTYPE
  • RANDOM:PANTS - picks any pants on the map, can include an optional :SUBTYPE
  • RANDOM:GLOVE - picks any glove on the map, can include an optional :SUBTYPE
  • RANDOM:SHOE - picks any shoe on the map, can include an optional :SUBTYPE
  • RANDOM:SHIELD - picks any shield on the map,, can include an optional :SUBTYPE
  • RANDOM:AMMO - picks any piece of ammo on the map, can include an optional :SUBTYPE
  • RANDOM:MATERIAL - picks any item made of a specific material, currently only supports INORGANIC materials
[EFFECT_BUILDING]
For when you need to pass a building ID to a script
  • RANDOM - picks any building on the map
  • RANDOM:WORKSHOP - picks any workshop on the map
  • RANDOM:FURNACE - picks any furnace on the map
  • RANDOM:CUSTOM:CUSTOM_BUILDING - picks any custom building
  • RANDOM:TRADE_DEPOT - picks any trade depot on the map
  • RANDOM:STOCKPILE - picks any stockpile on the map
  • RANDOM:ZONE - picks any civ zone on the map
[EFFECT_ARGUMENT]
This allows for even more customization in an individual script call. The way it works is, any time the script sees !ARG_X it will replace it with whatever [EFFECT_ARGUMENT:X] is. In order for this too work new tokens must be defined.
Argument Tokens
Each [EFFECT_ARGUMENT] must have a corresponding weighting and value so that it can randomly pick what to replace.
  • [ARGUMENT_WEIGHTING] - this is mandatory, it tells the script how to handle multiple options
  • [ARGUMENT_VALUE] - this tells the script the various values to choose for an effect (note these can be numeric values or strings)
  • [ARGUMENT_EQUATION] - this is a special case of [ARGUMENT_VALUE] and is more complex, see the wrapper documentation to see how equations work

And that is all the tokens currently available to use in event.txt. Let us take a look at an example in order to provide some clarity.
Code: [Select]
[EVENT:MERCHANT_ARRIVAL]
 [NAME:a new merchant arrives]
 [REQUIREMENT:BUILDING:EMPTY_MERCHANTS_STALL:1]
 [CHECK:MONTHLY]
 [CHANCE:100]
 [DELAY:STATIC:0]
 [EFFECT:1]
  [EFFECT_NAME:merchants arrive for a short time]
  [EFFECT_CHANCE:100]
  [EFFECT_DELAY:STATIC:0]
  [EFFECT_BUILDING:RANDOM:CUSTOM:EMPTY_MERCHANTS_STALL]
  [EFFECT_ARGUMENT:1]
   [ARGUMENT_WEIGHTING:100,100,100,10,10,10,1]
   [ARGUMENT_VARIABLE:HUMAN_MERCHANT,ELF_MERCHANT,DWARF_MERCHANT,TRAVELING_MERCHANT.GOBLIN_MERCHANT,KOBOLD_MERCHANT,EXOTIC_MERCHANT]
  [EFFECT_SCRIPT:"building/change -building !BUILDING -to !ARG_1 -dur 25200"]
In words, this event changes the building EMPTY_MERCHANTS_STALL into a different building at the start of every month. The building it changes in to is chosen randomly from those found in [ARGUMENT_VALUE] with the weighting found in [ARGUMENT_WEIGHTING].

And that's everything you need to know. I hope to be able to create some of my own custom events to share with all of you, but please, if you create any events for yourself, or for your mod, please post them here so that others can see more examples!

Addendum 1:
You can force an event to trigger by using the dfhack command
Code: [Select]
events/trigger -event EVENT_IDThis will still run the requirement checks, but will by-pass the [CHECK] and [CHANCE] tokens. In order to by-pass the requirements as well, you can use the command
Code: [Select]
events/trigger -event EVENT_ID -forceWhich will by-pass the event requirements, or
Code: [Select]
events/trigger -event EVENT_ID -forceAllWhich will by-pass both the event and effect requirements
Logged

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 12/11/15
« Reply #491 on: January 12, 2015, 03:04:04 pm »

Event system tutorial is up (post above this one). Note that the complexity of the system makes a tutorial difficult to say the least. Please, if there are any questions, just let me know.

Hopefully in the next couple of days I will actually release the system, along with some of the other things I have been working on.
Logged

Boltgun

  • Bay Watcher
  • [UTTERANCES]
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 12/11/15
« Reply #492 on: January 13, 2015, 05:13:10 am »

Okay that solve it. This will be the framework of my race's endgame goals. Thank you.
« Last Edit: January 13, 2015, 05:22:21 am by Boltgun »
Logged

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 12/11/15
« Reply #493 on: January 15, 2015, 02:49:56 pm »

So because my work has become a coding nightmare, the joy of writing scripts has left me for the moment. In the interim, for at least a couple weeks probably, I have decided to devote my time to working on my actual mod. Because much of what I will do for my mod is related to the various systems in my script collection, I will be including my work as examples. First up is the classes, for a first pass I have
Spoiler (click to show/hide)
Now there are definitely some names that I am not thrilled about, and I would like to add more combinations, but those might have to come in later updates. Currently each class has 10 levels and is able to learn about 5 skills. I need to figure out a way to make sure it is all balanced in terms of gameplay, but that is going to be much much harder.

PS. I will still be answering questions and everything about my scripts, and will still be around. Just need a little break from writing code. Starting to think in for and while loops, it's no good.

EDIT: I am also taking suggestions for other classes as well
« Last Edit: January 15, 2015, 02:57:46 pm by Roses »
Logged

expwnent

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection Updated 12/11/15
« Reply #494 on: January 15, 2015, 11:28:50 pm »

Do you remember the specific EventManager stuff you requested? I just vaguely remember something about the UNIT_ATTACK event and getting the vector of items created by a reaction. I'm updating the github issues tracker with todos.
Logged
Pages: 1 ... 31 32 [33] 34 35 ... 42