Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 23 24 [25] 26 27 ... 44

Author Topic: Putnam's DFHack scripts  (Read 119041 times)

Roses

  • Bay Watcher
    • View Profile
Re: Putnam's DFHack modder's utilities
« Reply #360 on: October 01, 2013, 05:57:35 pm »

Couple item syndrome questions:

1. So with itemsyndrome, is it possible to give an item that gives a syndrome that gives an interaction to a dwarf? For example, if I give a dwarf a shield can I give that shield a syndrome that allows the dwarf to do the 'shield bash' interaction?

2. If this is possible, can a single item confer multiple interactions?

3. Can itemsyndrome also work on materials the item is made from? For instance, normal boots do nothing, but boots made of levisium make the user faster?

4. If both are possible, can a single item confer a syndrome from the item type and material type?
Logged

Nahere

  • Bay Watcher
    • View Profile
Re: Putnam's DFHack modder's utilities
« Reply #361 on: October 01, 2013, 06:00:08 pm »

Couple item syndrome questions:

1. So with itemsyndrome, is it possible to give an item that gives a syndrome that gives an interaction to a dwarf? For example, if I give a dwarf a shield can I give that shield a syndrome that allows the dwarf to do the 'shield bash' interaction?

2. If this is possible, can a single item confer multiple interactions?

3. Can itemsyndrome also work on materials the item is made from? For instance, normal boots do nothing, but boots made of levisium make the user faster?

4. If both are possible, can a single item confer a syndrome from the item type and material type?
Yes to all four, as far as I'm aware.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Putnam's DFHack modder's utilities
« Reply #362 on: October 01, 2013, 06:39:04 pm »

To the first two: anything you can do with normal syndromes can be done with itemsyndrome.

To 3: actually, that was how it originally worked. I added item-based syndromes later.

4. Yeah. I didn't exactly try to make that happen, but it does happen, which is a welcome coincidence.

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Putnam's DFHack modder's utilities
« Reply #363 on: October 01, 2013, 06:42:35 pm »

But can you make levisium boots that make you faster, but a levisium armor that does not make you faster? a way to give a syndrome only if material and item fit together.
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: Putnam's DFHack modder's utilities
« Reply #364 on: October 01, 2013, 07:09:42 pm »

Why? I can't really think of why you'd want that. I mean, you could always have items only able to be made of the one material.

Code: [Select]
local function applySyndromesBasedOnItems(_uid,unit)
    if itemsyndromedebug then print("Checking unit #" .. _uid+1) end
    local transformation = false
    for itemid,item_inv in ipairs(unit.inventory) do
        local item = item_inv.item
        if itemsyndromedebug then print("checking item #" .. itemid+1 .." on unit #" .. _uid+1) end
        if getSyndrome(getMaterial(item)) then
            if itemsyndromedebug then print("item has a syndrome, checking if item is valid for application...") end
            local syndrome = getSyndrome(getMaterial(item))
            local syndromeApplied
            if syndromeIsTransformation(syndrome) then
                unitInventory = rememberInventory(unit)
                transformation = true
            end
            if syndromeIsDfHackSyndrome(syndrome) and creatureIsAffected(unit,syndrome) and itemIsInValidPosition(item_inv, syndrome) then
                assignSyndrome(unit,syndrome.id)
                syndromeApplied = true
            end
        end
        if itemHasSyndrome(item) then
            if itemsyndromedebug then print("Item itself has a syndrome, checking if item is in correct position and creature is affected") end
            local syndrome = itemHasSyndrome(item)
            if syndromeIsTransformation(syndrome) then
                unitInventory = rememberInventory(unit)
                transformation = true
            end
            if item_inv.mode~=0 and item_inv.mode~=7 and creatureIsAffected(unit,syndrome) then assignSyndrome(unit,syndrome.id) end --the mode thing is to avoid stuckins from doing
        end
        if itemsyndromecontaminants and item.contaminants then
            if itemsyndromedebug then print("Item has contaminants. Checking for syndromes...") end
            for _,contaminant in ipairs(item.contaminants) do
                if itemsyndromedebug then print("Checking contaminant #" .. _ .. " on item #" .. itemid .. " on unit #" .. _uid ..".") end
                if getSyndrome(getMaterial(contaminant)) then
                    local syndrome = getSyndrome(getMaterial(contaminant))
                    if syndromeIsTransformation(syndrome) then
                        unitInventory = rememberInventory(unit)
                        transformation =true
                    end
                    if syndromeIsDfHackSyndrome(syndrome) and creatureIsAffected(unit,syndrome) and itemIsInValidPosition(item_inv, syndrome) then assignSyndrome(unit,syndrome.id) end
                end
            end
        end
    end
    if transformation then dfhack.timeout(2,"ticks",function() moveAllToInventory(unit,unitInventory) end) end
end

I don't wanna make this function any bigger, dang it!

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Putnam's DFHack modder's utilities
« Reply #365 on: October 01, 2013, 07:29:52 pm »

It wasnt a request, it was a question. Because I think that is what the poster above me meant. No worries, I know how to do it with interactions and your current script, I was just wondering about it.

Possible use is some sort of wonder material that gives different effects to different items, but even then you can just use identical inorganics with same name, different ID and different effects.
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: Putnam's DFHack modder's utilities
« Reply #366 on: October 01, 2013, 07:33:04 pm »

To the first two: anything you can do with normal syndromes can be done with itemsyndrome.

To 3: actually, that was how it originally worked. I added item-based syndromes later.

4. Yeah. I didn't exactly try to make that happen, but it does happen, which is a welcome coincidence.

That is perfect, thanks!
Logged

Roses

  • Bay Watcher
    • View Profile
Re: Putnam's DFHack modder's utilities
« Reply #368 on: October 01, 2013, 11:39:13 pm »

Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Putnam's DFHack modder's utilities
« Reply #369 on: October 02, 2013, 12:03:12 am »

Minor performance and sense improvements. The current version there, for example, has a slight (untested) difference in how it determines when a unit will get their items checked relative to other units (I.E only units that have inventories will be checked and they will be checked sequentially, tick by tick).

The version I posted up there is always to be considered experimental, note, unless I say it's tested working.

narhiril

  • Bay Watcher
  • [DUTY_BOUND]
    • View Profile
Re: Putnam's DFHack modder's utilities
« Reply #370 on: October 02, 2013, 05:03:19 pm »

Hey,

Running into an issue that I was hoping you might be able to help with.  If a unit picks up an item without an assigned material, the plugin crashes.

stderr:
Code: [Select]
...sktop\LFR DFHack Test Copy\hack\scripts/itemsyndrome.lua:54: attempt to index local 'material' (a nil value)
stack traceback:
...sktop\LFR DFHack Test Copy\hack\scripts/itemsyndrome.lua:54: in function 'getMaterial'
...sktop\LFR DFHack Test Copy\hack\scripts/itemsyndrome.lua:280: in function 'findItems'
...sktop\LFR DFHack Test Copy\hack\scripts/itemsyndrome.lua:335: in function <...sktop\LFR DFHack Test Copy\hack\scripts/itemsyndrome.lua:333>


Is there a way to add a safeguard against this situation (maybe another if statement)?  If I were more familiar with lua, I'd do it myself, but I'm not sure exactly which command in the if statement on line 54 is causing the issue.
« Last Edit: October 02, 2013, 05:05:05 pm by narhiril »
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Putnam's DFHack modder's utilities
« Reply #371 on: October 02, 2013, 05:19:49 pm »

The script doesn't crash, just throw an error. Of course, that's still damn annoying, so I'll fix it.

EDIT: Fixed in the snapshot version, which is stable, btw.
« Last Edit: October 02, 2013, 05:21:58 pm by Putnam »
Logged

narhiril

  • Bay Watcher
  • [DUTY_BOUND]
    • View Profile
Re: Putnam's DFHack modder's utilities
« Reply #372 on: October 02, 2013, 05:22:01 pm »

The script doesn't crash, just throw an error. Of course, that's still damn annoying, so I'll fix it.

...Except it stops performing checks after throwing that error.  Not sure why - maybe that's a DFHack thing?

Anyway, I think this will work.

Code: [Select]
local function getMaterial(item)
    local material = dfhack.matinfo.decode(item)
    if itemsyndromedebug then
print(material)
end
    if material ~= nil then
    if material.mode ~= "inorganic" then
return nil
else
return material.material --the "material" thing up there contains a bit more info which is all pretty important, like the creature that the material comes from
end
end
end
« Last Edit: October 02, 2013, 05:29:14 pm by narhiril »
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Putnam's DFHack modder's utilities
« Reply #373 on: October 02, 2013, 05:23:06 pm »

Then it's a good thing I fixed it, eh?

(though it would have been better had I not been all naive about my return codes--reminder to self: never have a function return nil if the function is supposed to return a value!)

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Putnam's DFHack modder's utilities
« Reply #374 on: October 02, 2013, 05:40:38 pm »

the the currently included version in your download on DFFD includes a fix for this`?
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 ... 23 24 [25] 26 27 ... 44