Bay 12 Games Forum

Please login or register.

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

Author Topic: DFHack Script Collection  (Read 67187 times)

milo christiansen

  • Bay Watcher
  • Something generic here
    • View Profile
Re: DFHack Script Collection
« Reply #30 on: March 10, 2014, 11:42:16 am »

Why isn't this a sticky?
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

troy49er3

  • Bay Watcher
    • View Profile
Re: DFHack Script Collection
« Reply #31 on: March 10, 2014, 06:45:00 pm »

I'm currently in the process of updating hackwish to (optionally) only allow stockpilable items to be made and (again, optionally) have even stricter requirements so that only items that can technically be made in-game can be made (say, only allowing weapons to be made of ITEMS_WEAPON materials).

I may also integrate it with spawnUnit if you try to make a pet, but that would be far more complex and would also kinda require spawnunit to be a lua library.

WIP:

Code: [Select]
-- Allows for script-based wishing.

function getCreatureID(creatureRaw)
    return df.global.world.creatures.list_creature[creatureRaw.caste[0].index]
end

function createItem(mat,itemType,quality,pos)
    local item=df[df.item_type.attrs[itemType[1]].classname]:new() --incredible
    item.id=df.global.item_next_id
    df.global.world.items.all:insert('#',item)
    df.global.item_next_id=df.global.item_next_id+1
    item:setSubtype(itemType[2])
    item:setMaterial(mat[1])
    item:setMaterialIndex(mat[2])
    item:categorize(true)
    item.flags.removed=true
    item:setSharpness(1,0)
    item:setQuality(quality-1)
    dfhack.items.moveToGround(item,{x=pos.x,y=pos.y,z=pos.z})
end
 
function qualityTable()
    return {{'None'},
    {'-Well-crafted-'},
    {'+Finely-crafted+'},
    {'*Superior*'},
    {string.char(240)..'Exceptional'..string.char(240)},
    {string.char(15)..'Masterwork'..string.char(15)}
    }
end
 
local script=require('gui/script')
 
function showItemPrompt(text,item_filter,hide_none)
    require('gui.materials').ItemTypeDialog{
        prompt=text,
        item_filter=item_filter,
        hide_none=hide_none,
        on_select=script.mkresume(true),
        on_cancel=script.mkresume(false),
        on_close=script.qresume(nil)
    }:show()
   
    return script.wait()
end

function showMaterialPrompt(title, prompt, filter, inorganic, creature, plant) --the one included with DFHack doesn't have a filter or the inorganic, creature, plant things available
    require('gui.materials').MaterialDialog{
        frame_title = title,
        prompt = prompt,
        mat_filter = filter,
        use_inorganic = inorganic,
        use_creature = creature,
        use_plant = plant,
        on_select = script.mkresume(true),
        on_cancel = script.mkresume(false),
        on_close = script.qresume(nil)
    }:show()

    return script.wait()
end

function getMatFilter(itemtype)
        local itemTypes={
            SEEDS=function(mat,parent,typ,idx)
                return mat.flags.SEED_MAT
            end,
            PLANT=function(mat,parent,typ,idx)
                return mat.flags.STRUCTURAL_PLANT_MAT
            end,
            LEAVES=function(mat,parent,typ,idx)
                return mat.flags.LEAF_MAT
            end,
            MEAT=function(mat,parent,typ,idx)
                return mat.flags.MEAT
            end,
            CHEESE=function(mat,parent,typ,idx)
                return (mat.flags.CHEESE_PLANT or mat.flags.CHEESE_CREATURE)
            end,
            LIQUID_MISC=function(mat,parent,typ,idx)
                return (mat.flags.LIQUID_MISC_PLANT or mat.flags.LIQUID_MISC_CREATURE or mat.flags.LIQUID_MISC_OTHER)
            end,
            POWDER_MISC=function(mat,parent,typ,idx)
                return (mat.flags.POWDER_MISC_PLANT or mat.flags.POWDER_MISC_CREATURE)
            end,
            DRINK=function(mat,parent,typ,idx)
                return (mat.flags.ALCOHOL_PLANT or mat.flags.ALCOHOL_CREATURE)
            end,
            GLOB=function(mat,parent,typ,idx)
                return (mat.flags.STOCKPILE_GLOB)
            end,
            WOOD=function(mat,parent,typ,idx)
                return (mat.flags.WOOD)
            end,
            THREAD=function(mat,parent,typ,idx)
                return (mat.flags.THREAD_PLANT)
            end,
            LEATHER=function(mat,parent,typ,idx)
                return (mat.flags.LEATHER)
            end
        }
        return itemTypes[df.item_type[itemtype]] or getRestrictiveMatFilter(itemtype)
end

function getRestrictiveMatFilter(itemType)
    if not args.veryRestrictive then return nil else
    local itemTypes={
            WEAPON=function(mat,parent,typ,idx)
                return (mat.flags.ITEMS_WEAPON or mat.flags.ITEMS_WEAPON_RANGED)
            end,
            AMMO=function(mat,parent,typ,idx)
                return (mat.flags.ITEMS_AMMO)
            end,
            ARMOR=function(mat,parent,typ,idx)
                return (mat.flags.ITEMS_ARMOR)
            end,
            SHOES,SHIELD,HELM,GLOVES=ARMOR,ARMOR,ARMOR,ARMOR,
            INSTRUMENT=function(mat,parent,typ,idx)
                return (mat.flags.ITEMS_HARD)
            end,
            GOBLET,FLASK,TOY,RING,CROWN,SCEPTER,FIGURINE=INSTRUMENT,INSTRUMENT,INSTRUMENT,INSTRUMENT,INSTRUMENT,INSTRUMENT,
            AMULET=function(mat,parent,typ,idx)
                return (mat.flags.ITEMS_SOFT or mat.flags.ITEMS_HARD)
            end,
            EARRING,BRACELET=AMULET,AMULET,
            ROCK=function(mat,parent,typ,idx)
                return (mat.flags.IS_STONE)
            end,
            BOULDER=ROCK,
            BAR=function(mat,parent,typ,idx)
                return (mat.flags.IS_METAL or mat.flags.SOAP or mat.id==COAL)
            end
        }
    return itemTypes[df.item_type[itemtype]]
    end
end
 
function hackWish(posOrUnit)
    local pos = df.unit:is_instance(posOrUnit) and posOrUnit.pos or posOrUnit
    script.start(function()
--        local amountok, amount
        local matFilter
        local itemok,itemtype,itemsubtype=showItemPrompt('What item do you want?',nil,true)
        if not args.noMatRestriction then
            matFilter=getMatFilter(itemtype)
        end --for stockpiling reasons
        local matok,mattype,matindex=showMaterialPrompt('Wish','And what material should it be made of?',matFilter)
        local qualityok,quality=script.showListPrompt('Wish','What quality should it be?',COLOR_LIGHTGREEN,qualityTable())
--        repeat amountok,amount=script.showInputPrompt('Wish','How many do you want? (numbers only!)',COLOR_LIGHTGREEN) until tonumber(amount)
        if mattype and itemtype then
--            for i=1,tonumber(amount) do
            createItem({mattype,matindex},{itemtype,itemsubtype},quality,pos)
--            end
        end
    end)
end
 
args={...}

for k,v in ipairs(args) do
    if v=='all' then args.noMatRestriction=true end
    if v=='startup' then args.startup=true end
    if v=='restrict' then args.veryRestrictive=true end
    if v=='unit' then unitNum=args[k+1] end
end
 
eventful=require('plugins.eventful')
 
print(args.veryRestrictive)
 
if not args.startup then
    local posOrUnit=#args<1 and dfhack.gui.getSelectedUnit(true) and dfhack.gui.getSelectedUnit(true) or not unitNum and df.global.cursor or unitNum and df.unit.find(unitNum) or {x=args[1],y=args[2],z=args[3]}
    hackWish(posOrUnit)
else
    eventful.onReactionComplete.hackWishP=function(reaction,unit,input_items,input_reagents,output_items,call_native)
        if not reaction.code:find('DFHACK_WISH') then return nil end
        hackWish(unit)
    end
end


Hey Putman, I cannot seem to get this work at all. Everytime I type in hackish it throws an error at me. Error loading module  GUI/Script and other stuff. Its suppose to be in the scripts folder right? Is there a way to send some sort of log so you can have a better look at it?  Btw thanks for all your stuff you do. Your awesome man 
« Last Edit: March 10, 2014, 07:05:33 pm by troy49er3 »
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack Script Collection
« Reply #32 on: March 10, 2014, 07:52:16 pm »

r3 has a missing close paren in the script file, so you'll probably want to use it with r4.

troy49er3

  • Bay Watcher
    • View Profile
Re: DFHack Script Collection
« Reply #33 on: March 10, 2014, 08:07:53 pm »

Thanks a bunch, I'll try that.
Logged

troy49er3

  • Bay Watcher
    • View Profile
Re: DFHack Script Collection
« Reply #34 on: March 10, 2014, 08:40:01 pm »

r3 has a missing close paren in the script file, so you'll probably want to use it with r4.

I tried r4 and still getting the same error. this is what Im getting

Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack Script Collection
« Reply #35 on: March 10, 2014, 08:45:10 pm »

DFHack r4, not LNP.

troy49er3

  • Bay Watcher
    • View Profile
Re: DFHack Script Collection
« Reply #36 on: March 10, 2014, 08:48:09 pm »

I did get it. From here http://dffd.wimbli.com/file.php?id=8068 I just copied all the files from it over to my existing dfhack file
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack Script Collection
« Reply #37 on: March 10, 2014, 08:49:16 pm »

Did you replace every file correctly?

troy49er3

  • Bay Watcher
    • View Profile
Re: DFHack Script Collection
« Reply #38 on: March 10, 2014, 09:00:00 pm »

LOL apparently not. I just recopied and pasted and now its working fine :o. Thanks for your help and all these awesome mods btw. Your awesome man.
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: DFHack Script Collection
« Reply #39 on: March 11, 2014, 05:55:20 am »

Why isn't this a sticky?
I wrote Toady a message, lets see if he agrees with making this a stickied thread or not.
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 :::

Bo-Rufus CMVII

  • Bay Watcher
    • View Profile
Re: DFHack Script Collection
« Reply #40 on: March 11, 2014, 11:31:59 pm »

I added a few scripts to the bottom of the list, with links to posts that have the code and describe them more fully.
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: DFHack Script Collection
« Reply #41 on: March 12, 2014, 06:07:11 am »

Toady said no to the sticky, because the first thread can be edited by anyone, opening grounds for spammers and trolls. Just wamted to let you guys know. He said that it would be different if someone governs the thread, as in : approves of suggested changes to the first post, but he will see how the forum discussion goes and how many people are pro/contra stickying this thread.
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 :::

Bo-Rufus CMVII

  • Bay Watcher
    • View Profile
Re: DFHack Script Collection
« Reply #42 on: March 15, 2014, 04:49:05 am »

Added show-speeds.

This is a very substantial revision of what I posted a week or two ago, now providing information on encumbrance and jobs that may be slowing Urist down.

Screenshot below; code at http://www.bay12forums.com/smf/index.php?topic=136748.msg5045463#msg5045463.

Some of the code is problematic (see internal comments); let me know if you spot something that needs fixing.


Logged

Urist McTeellox

  • Bay Watcher
    • View Profile
Re: DFHack Script Collection
« Reply #43 on: March 15, 2014, 06:01:30 am »

Toady said no to the sticky, because the first thread can be edited by anyone, opening grounds for spammers and trolls. Just wamted to let you guys know. He said that it would be different if someone governs the thread, as in : approves of suggested changes to the first post, but he will see how the forum discussion goes and how many people are pro/contra stickying this thread.

For what it's worth, I still have to press a button to trigger the top-post update (which I usually do when I see anyone post), so spammers are unlikely to get much in the way of instant gratification.

I think the actual risk of spammers is very low; needing to register a github account to update a markdown wiki to spam a DF board is a lot of work for a very specialised target. In the case that we ever do see spam, I can tweak my update procedures to show me the actual changes before committing them. (Really just a matter of adding a few more git commands to the current release code).

~ T
Logged

palu

  • Bay Watcher
    • View Profile
Re: DFHack Script Collection
« Reply #44 on: March 16, 2014, 08:33:14 pm »

Why not make a poll? And for the record, I think it should be stickied.
Logged
Hmph, palu showing off that reading-the-instructions superpower.
The internet encourages thoughtful, intelligent discussion and if you disagree I hate you.
Pages: 1 2 [3] 4 5