Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 11 12 [13] 14 15 ... 42

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

Roses

  • Bay Watcher
    • View Profile
Re: DFHack Spells official v1.0
« Reply #180 on: May 29, 2014, 12:48:11 pm »

Copying items is currently not possible with the scripts I know. Creating new ones, yes, but nothing that would take the item type and sub type and material from the reaction.

Yes, I meant that the code is all written, it just needs to be copy and pasted and put together, so it shouldn't be hard to do.

Glad people are interested in what this can do, I tested it a little bit with changing work tiles and it seemed to work ok. It may even be possible to change the size of buildings when they upgrade, but I would need to test that some more.

EDIT: Here's what the example interactions will look like;

Code: [Select]
[INTERACTION:SPELL_ARCANE_TIME_HASTE]
* Increase speed of unit
* Combat Buff
* Targets Civ units only
-CAN_DO_INTERACTION:SPELL_ARCANE_TIME_HASTE--
-CDI:ADV_NAME:Haste--
-CDI:USAGE_HINT:ATTACK--
-CDI:TARGET:C:LINE_OF_SIGHT--
-CDI:TARGET_RANGE:C:15--
-CDI:MAX_TARGET_NUMBER:C:1--
-CDI:VERB:casts haste:haste casted:hasted--
-CDI:WAIT_PERIOD:1000--
[I_SOURCE:CREATURE_ACTION]
[I_TARGET:C:CREATURE]
[IT_LOCATION:CONTEXT_CREATURE]
[IT_CANNOT_TARGET_IF_ALREADY_AFFECTED]
[IT_MANUAL_INPUT:target]
[I_EFFECT:ADD_SYNDROME]
[IE_TARGET:C]
[IE_IMMEDIATE]
[SYNDROME]
[SYN_NAME:haste]
[SYN_CLASS:\COMMAND]
[SYN_CLASS:wrapper]
[SYN_CLASS:script@addsyndrome]
[SYN_CLASS:args@SYNDROME_ARCANE_TIME_HASTE;!UNIT]
[SYN_CLASS:self@true]
[SYN_CLASS:center@false]
[SYN_CLASS:target@civ]
[SYN_CLASS:maxtargets@1]
[SYN_CLASS:radius@10/10/10]
[SYN_CLASS:iclass@;TIME2;TIME3;TIME4;MAGIC_IMMUNE;MAGIC_RESIST;ARCANE_RESIST;ARCANE_IMMUNE]
[SYN_CLASS:isyndrome@MAGIC_IMMUNITY;RESIST_MAGIC;TIMEWARD;ARCANEWARD]
[SYN_CLASS:relfect@REFLECT_TIME;REFLECT_ARCANE;REFLECT_ALL]
[SYN_CLASS:silence@SILENCE_TIME;SILENCE_ARCANE:SILENCE_ALL]
[SYN_CLASS:verbose@true]
[CE_SKILL_ROLL_ADJUST:PERC:100:PERC_ON:0:START:0:END:0]

I know similar things can be done using more of the in game mechanics than scripts, but it is just a useful example of what can be done. I will be releasing an entire collection of these soonish.
« Last Edit: May 29, 2014, 03:17:42 pm by Roses »
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: DFHack Spells official v1.0
« Reply #181 on: May 31, 2014, 02:23:03 am »

Hey, I had a first testrun with your upgradebuildings scripts. I do have 4 basic workshops (stone, gem, wood, bone), and allowed to cycle between them. "Refurbish workshop".  Works beautifully.

But you have one bug: Only the first PRESERVE_REAGENT reagent will be added as buildmat. Even when taking your example reaction:

Code: [Select]
[REACTION:LUA_HOOK_UPGRADE_BUILDING_STONECUTTER]
[NAME:Refurbish with stonecutting tools]
[BUILDING:GEMWORKSHOP:NONE]
[BUILDING:BONEYARD:NONE]
[BUILDING:WOODCUTTER:NONE]
[REAGENT:A:1:BOULDER:NONE:INORGANIC:NONE][PRESERVE_REAGENT] => This one becomes a buildmat.
[REAGENT:B:1:BOULDER:NONE:INORGANIC:NONE][PRESERVE_REAGENT] => This one is preserved, but just lies around. No buildmat, and will be stockpiled/used in other reactions as usual.
[PRODUCT:100:0:BOULDER:NONE:INORGANIC:UPGRADE_BUILDING]
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 :::

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: DFHack Spells official v1.0
« Reply #182 on: May 31, 2014, 04:20:14 am »

I guess we can circumvent it by pre-combining the build mats into a "building plan" or something :).
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: DFHack Spells official v1.0
« Reply #183 on: May 31, 2014, 09:00:14 am »

Can you help me out a bit please?

I use this:
Code: [Select]
[REACTION:TELEPORTER_TELEPORT]
[NAME:teleport]
[BUILDING:BUILDING_TELEPORTER:CUSTOM_A]
[PRODUCT:100:1:BOULDER:NONE:INORGANIC:TELEPORT]

[INORGANIC:TELEPORT]
[USE_MATERIAL_TEMPLATE:STONE_VAPOR_TEMPLATE]
[STATE_NAME_ADJ:ALL_SOLID:blinding flash of light]
[STATE_NAME_ADJ:LIQUID:molten failure stone]
[STATE_NAME_ADJ:GAS:magic]
[SYNDROME]
[SYN_CLASS:\AUTO_SYNDROME]
[SYN_CLASS:\COMMAND] autosyndrome command begins here
[SYN_CLASS:teleport]
[SYN_CLASS:unit]
[SYN_CLASS:\WORKER_ID]
[SYN_CLASS:building]
[SYN_CLASS:BUILDING_TELEPORTER]
         [SYN_NAME:doesnt matter]
         [SYN_CONTACT]
         [SYN_INHALED]
         [SYN_AFFECTED_CREATURE:DWARF:ALL]
[CE_SPEED_CHANGE:SPEED_PERC:100:START:0:END:1]
[DISPLAY_COLOR:4:4:1][TILE:'*']
[MATERIAL_VALUE:1]

When I trigger the reaction I expect the worker to teleport to a random building with BUILDING_TELEPORTER type.

But I get this error in dfhack console:



P.S. When I try to init "upgradeitem" I get this:
« Last Edit: May 31, 2014, 09:48:51 am by Deon »
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: DFHack Spells official v1.0
« Reply #184 on: May 31, 2014, 10:15:40 am »

I am definitely doing something wrong...

The following syndrome on a vapor stone does not bring the result:

Code: [Select]
[SYNDROME]
[SYN_CLASS:\AUTO_SYNDROME]
[SYN_CLASS:\COMMAND]
[SYN_CLASS:counters]
[SYN_CLASS:\WORKER_ID]
[SYN_CLASS:APOCALYPSE]
[SYN_CLASS:1]
[SYN_CLASS:minimum]
[SYN_CLASS:10]
[SYN_CLASS:customweather@dragonfire;100;50;1000;3000]

It's supposed to start a dragonfire all over the map after 10 uses but it does nothing.
Can you help me when you get time please? :) What am I doing wrong?
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Roses

  • Bay Watcher
    • View Profile
Re: DFHack Spells official v1.0
« Reply #185 on: May 31, 2014, 11:14:59 am »

Lots of bugs I see :) I am traveling this weekend, but I might be able to take a look on the plane. If not I will definately look at them on Monday.

@Meph
That is odd, it was adding both boulders for me, I wonder if, because I had a non-added boulder it worked out with the vectors. I will do some testing, but it definitely will add all items with PRESERVE_REAGENT to the building when it is working properly.

@Deon
The building one is just my own fault for uploading an old version, otherwise it will work exactly as you have it.

Similarly, upgrade item, I must have uploaded an old version, or broken something and didn't realize it, because I have never seen that error before, shouldn't take long to fix it, hopefully I can upload a fix from the airport.

As for the counters, I have no idea why what you have isn't working, must be another error on my part (I had a bunch of different copies floating around when I collected them all together, so I don't remember which versions I tested and which passed under the radar). So, again my fault not yours. Should work exactly as you have it, now I need to figure out if its the counters or the customweather :)

Thanks for testing these all, I was hoping there wouldn't be so many errors, but I suppose it's how coding works.
Logged

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: DFHack Spells official v1.0
« Reply #186 on: May 31, 2014, 11:18:10 am »

Is there any chance to get the updated versions from somewhere? At least for the upgradeitem to work :). I plan to make a few additions to my mod this weekend and I would love to have that functionality. Is there a chance that you could share a working version? This shiz is amaaazing.
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Roses

  • Bay Watcher
    • View Profile
Re: DFHack Spells official v1.0
« Reply #187 on: May 31, 2014, 11:20:15 am »

Yeah, that fix is easy, I will upload the fixed version of that in an hour or two.

EDIT: Or now, try this

Code: [Select]
--upgradeitem.lua v1.0
--[[
upgradeitem - used to upgrade item from one to another, or to change them from one to another
Requires a reaction an inorganic and corresponding items

REACTION OPTIONS:
All item reagents with [PRESERVE_REAGENT] will be flagged for upgrading
Reagents without the [PRESERVE_REAGENT] tag will be consumed
The first product must be the inorganic with the syndrome attached to it
Subsequent products will be created as normal

EXAMPLE REACTION:
[REACTION:LUA_HOOK_UPGRADE_ITEM_EXAMPLE_1] <- LUA_HOOK_UPGRADE_ITEM is required
[NAME:upgrade armor]
[BUILDING:UPGRADE_SMITH:NONE]
[REAGENT:A:1:ARMOR:NONE:INORGANIC:NONE][PRESERVE_REAGENT]
[REAGENT:C:1500:COIN:NONE:INORGANIC:SILVER]
[PRODUCT:100:0:BOULDER:NONE:INORGANIC:UPGRADE_ITEM]

INORGANIC OPTIONS:
Inorganics must have a syndrome with two [SYN_CLASS:] tags
Valid arguments for the first SYN_CLASS;
this - this will change the items in the reaction
all - this will change all items of the same type and subtype as the items in the reaction
ITEM_TOKEN - this will change a randomly selected item of the given token (e.g. ITEM_ARMOR_TEST_1)
Valid arguments for the second SYN_CLASS;
upgrade - this will upgrade the item to one higher (i.e. ITEM_ARMOR_TEST_1 -> ITEM_ARMOR_TEST_2)
downgrade - this will downgrade the item to one lower (i.e. ITEM_ARMOR_TEST_2 -> ITEM_ARMOR_TEST_1)
ITEM_TOKEN - this will change the item to a completely new token (i.e. ITEM_ARMOR_TEST_1 -> ITEM_ARMOR_ELF_ARMOR)

EXAMPLE INORGANIC:
[INORGANIC:UPGRADE_ITEM]
[USE_MATERIAL_TEMPLATE:STONE_VAPOR_TEMPLATE]
[SPECIAL]
[SYNDROME]
[SYN_CLASS:this]
[SYN_CLASS:upgrade]
[MATERIAL_VALUE:0]

ITEM OPTIONS:
Nothing special is required from items except when using the upgrade/downgrade option
then the item you wish to change need to be named in the convention BLAH_BLAH_BLAH_1, BLAH_BLAH_BLAH_2, etc...

EXAMPLE ITEMS:
[ITEM_ARMOR:ITEM_ARMOR_TEST_1]
[NAME:armor:armor]
[PREPLURAL:suits of]
[MATERIAL_PLACEHOLDER:leather]
[ARMORLEVEL:1]
[UBSTEP:1]
[LBSTEP:1]
[SHAPED]
[LAYER:ARMOR]
[COVERAGE:100]
[LAYER_SIZE:20]
[LAYER_PERMIT:49]
[MATERIAL_SIZE:6]
[LEATHER]
[HARD]
[BARRED]
[SCALED]

[ITEM_ARMOR:ITEM_ARMOR_TEST_2]
[NAME:plated hide:plated hides]
[ARMORLEVEL:3]
[SHAPED]
[LAYER:ARMOR]
[COVERAGE:100]
[LAYER_SIZE:25]
[LEATHER]
[LAYER_PERMIT:49]
[MATERIAL_SIZE:9]
[BARRED]
[HARD]
[METAL]

RESTRICTIONS!
Only upgrade between the same types (i.e. ARMOR -> ARMOR), never upgrade to different types
Can upgrade anything with a subtype (including toys, instruments, siegeammo, etc...)
Will not downgrade if item is at _1 and will not upgrade if there is no higher _#
--]]

function split(str, pat)
   local t = {}  -- NOTE: use {n = 0} in Lua-5.0
   local fpat = "(.-)" .. pat
   local last_end = 1
   local s, e, cap = str:find(fpat, 1)
   while s do
      if s ~= 1 or cap ~= "" then
table.insert(t,cap)
      end
      last_end = e+1
      s, e, cap = str:find(fpat, last_end)
   end
   if last_end <= #str then
      cap = str:sub(last_end)
      table.insert(t, cap)
   end
   return t
end

function itemSubtypes(item) -- Taken from Putnam's itemSyndrome
   local subtypedItemTypes =
    {
    ARMOR = df.item_armorst,
    WEAPON = df.item_weaponst,
    HELM = df.item_helmst,
    SHOES = df.item_shoesst,
    SHIELD = df.item_shieldst,
    GLOVES = df.item_glovest,
    PANTS = df.item_pantsst,
    TOOL = df.item_toolst,
    SIEGEAMMO = df.item_siegeammost,
    AMMO = df.item_ammost,
    TRAPCOMP = df.item_trapcompst,
    INSTRUMENT = df.item_instrumentst,
    TOY = df.item_toyst}
    for x,v in pairs(subtypedItemTypes) do
        if v:is_instance(item) then
return df.item_type[x]
end
    end
    return false
end

function upgradeitem(reaction,unit,input_items,input_reagents,output_items,call_native)
local ptype = reaction.products[0].mat_type
local pindx = reaction.products[0].mat_index
local product = dfhack.matinfo.decode(ptype,pindx)
local args = {}
for i,x in ipairs(product.material.syndrome[0].syn_class) do
args[i] = x.value
end

print(args[0],args[1])
local sitems = {}
if args[0] == 'this' then
-- Upgrade only the input items with preserve reagent
for i,x in ipairs(input_reagents) do
if x.flags.PRESERVE_REAGENT then sitems[i] = input_items[i] end
end
elseif args[0] == 'all' then
-- Upgrade all items of the same type as input
local itemList = df.global.world.items.all
local k = 0
for j,y in ipairs(input_reagents) do
if y.flags.PRESERVE_REAGENT then
for i,x in ipairs(itemList) do
if x.subtype.id == y.subtype.id then
sitems[k] = itemList[i]
k = k + 1
end
end
end
end
else
-- Randomly upgrade one specific item
local itemList = df.global.world.items.all
local k = 0
for j,y in ipairs(input_reagents) do
if y.flags.PRESERVE_REAGENT then
for i,x in ipairs(itemList) do
if x.subtype.id == y.subtype.id then
sitems[k] = itemList[i]
k = k + 1
end
end
end
end
local rando = dfhack.random.new()
sitems = {sitems[rando:random(#sitems)]}
end

if args[1] == 'upgrade' then
-- Increase items number by one
for _,x in ipairs(sitems) do
local name = x.subtype.id
local namea = split(name,'_')
local num = tonumber(namea[#namea])
num = num + 1
namea[#namea] = tostring(num)
name = table.concat(namea,'_')
item_index = itemSubtypes(x)
for i=0,dfhack.items.getSubtypeCount(item_index)-1,1 do
item_sub = dfhack.items.getSubtypeDef(item_index,i)
if item_sub.id == name then x:setSubtype(item_sub.subtype) end
end
end
elseif args[1] == 'downgrade' then
-- Decrease items number by one
for _,x in ipairs(sitems) do
local name = x.subtype.id
local namea = split(name,'_')
local num = tonumber(namea[#namea])
num = num - 1
if num > 0 then namea[#namea] = tostring(num) end
name = table.concat(namea,'_')
item_index = itemSubtypes(x)
for i=0,dfhack.items.getSubtypeCount(item_index)-1,1 do
item_sub = dfhack.items.getSubtypeDef(item_index,i)
if item_sub.id == name then x:setSubtype(item_sub.subtype) end
end
end
else
-- Change item to new item
for _,x in ipairs(sitems) do
item_index = itemSubtypes(x)
print(item_index)
for i=0,dfhack.items.getSubtypeCount(item_index)-1,1 do
item_sub = dfhack.items.getSubtypeDef(item_index,i)
if item_sub.id == args[1] then x:setSubtype(item_sub.subtype) end
end
end
end
end

-- START Taken from hire-guard.lua
local eventful = require 'plugins.eventful'
local utils = require 'utils'

function string.starts(String,Start)
   return string.sub(String,1,string.len(Start))==Start
end

dfhack.onStateChange.loadUpgradeItem = function(code)
local registered_reactions
if code==SC_MAP_LOADED then
--registered_reactions = {}
for i,reaction in ipairs(df.global.world.raws.reactions) do
-- register each applicable reaction (to avoid doing string check
-- for every lua hook reaction (not just ours), this way uses identity check
if string.starts(reaction.code,'LUA_HOOK_UPGRADE_ITEM') then
-- register reaction.code
eventful.registerReaction(reaction.code,upgradeitem)
-- save reaction.code
--table.insert(registered_reactions,reaction.code)
registered_reactions = true
end
end
--if #registered_reactions > 0 then print('HireGuard: Loaded') end
if registered_reactions then print('Upgradable Items: Loaded') end
elseif code==SC_MAP_UNLOADED then
--[[ doesn't seem to be working, and probably not needed
registered_reactions = registered_reactions or {}
if #registered_reactions > 0 then print('HireGuard: Unloaded') end
for i,reaction in ipairs(registered_reactions) do
-- un register each registered reaction (to prevent persistance between
-- differing worlds (probably irrelavant, but doesn't hurt)
-- un register reaction.code
eventful.registerReaction(reaction.code,nil)
end
registered_reactions = nil -- clear registered_reactions
--]]
end
end

-- if dfhack.init has already been run, force it to think SC_WORLD_LOADED to that reactions get refreshed
if dfhack.isMapLoaded() then dfhack.onStateChange.loadUpgradeItem(SC_MAP_LOADED) end
-- END Taken from hire-guard.lua
« Last Edit: May 31, 2014, 11:23:46 am by Roses »
Logged

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: DFHack Spells official v1.0
« Reply #188 on: May 31, 2014, 11:36:46 am »

Thank you, I will wait for the upgraded teleport/teleportbase and I will definitely try the upgradeitem ASAP. I just don't have enough time to mod during weekend, thank you very much for the help, it means a lot :).
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Roses

  • Bay Watcher
    • View Profile
Re: DFHack Spells official v1.0
« Reply #189 on: May 31, 2014, 11:37:48 am »

Question, the only custom buildings are workshops and furnaces, correct?

EDIT: Technically you can test the teleport/teleportbase as long as you only have workshops or furnaces built. If you deconstruct your wagon you shouldn't get that error.
Logged

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: DFHack Spells official v1.0
« Reply #190 on: May 31, 2014, 11:43:26 am »

Quote
If you deconstruct your wagon you shouldn't get that error.
Ohh never thought of that. Can I exclude wagon from any checks to avoid the issue on new start?
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Roses

  • Bay Watcher
    • View Profile
Re: DFHack Spells official v1.0
« Reply #191 on: May 31, 2014, 11:49:26 am »

Yes, I am going to add a check so that it ignores any non-workshop non-furnace buildings. But for just testing thats a quick work around.
Logged

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: DFHack Spells official v1.0
« Reply #192 on: May 31, 2014, 11:56:04 am »

Okay, now another thing. Now that I deconstructed the wagon it gives me "no valid teleport locations found, aborting" or something like that.

The string I pass up with autosyndrome is "teleport unit \WORKER_ID building TELEPORTER".

Please note that it gives the same message with "teleport unit \WORKER_ID building workshop".

Any idea what could be causing it?
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Roses

  • Bay Watcher
    • View Profile
Re: DFHack Spells official v1.0
« Reply #193 on: May 31, 2014, 12:10:06 pm »

That is odd, it was working on my computer. I'll look over it, just another mistake of mine I am sure.

EDIT: This one is just a mistake on my commenting, your command string you pass should be of the form

teleport unit \WORKER_ID building/TELEPORTER 0/0/0

The last three numbers are the radius around the unit to be teleported, so 0/0/0 means everyone on the square of the unit (I seem to have forgotten to include the -1/-1/-1 check which would be just the unit, not the whole square, for now just use 0/0/0)

That should work.
« Last Edit: May 31, 2014, 12:27:01 pm by Roses »
Logged

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: DFHack Spells official v1.0
« Reply #194 on: May 31, 2014, 12:32:34 pm »

This is amazing, thanks a lot! Now I can actually make it useful that I know that it does not teleport the worker only :). I will be able to make a 5x5 teleporter room which will send a squad stationed there where we need it to go!
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository
Pages: 1 ... 11 12 [13] 14 15 ... 42