Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 17 18 [19] 20 21 ... 44

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

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Putnam's DFHack modder's utilities
« Reply #270 on: July 31, 2013, 12:06:29 pm »

I just tried creating some gods using your two scripts (the one from here and the other you posted on reddit) but it does not quite work.

Here the creature file.
Code: [Select]
creature_armok

[OBJECT:CREATURE]

[CREATURE:ARMOK]
[DOES_NOT_EXIST]
[MALE]
[NAME:Armok:Armok:blood]
[CASTE_NAME:Armok:Armok:Armok]
[DESCRIPTION:The God of Blood.]
[CREATURE_CLASS:DFHACK_GOD]
[SPHERE:FORTRESSES]
[SPHERE:JEWELS]
[SPHERE:METALS]
[SPHERE:MINERALS]
[SPHERE:MOUNTAINS]
[SPHERE:WEALTH]

Script 1, changed Putnam to Armok
Code: [Select]
-- Makes everyone worship someone. Usage: [scriptname] [unit's first name]

local function findWorshipTarget(filter)
    for _,fig in ipairs(df.global.world.history.figures) do
        if fig.name.first_name == filter then return fig.id end
    end
end

local function setAllWorshippersInWorldToWorshipArmok(filter)
    local worshipTarget = findWorshipTarget(filter)
    for k,fig in ipairs(df.global.world.history.figures) do
        fig.histfig_links:insert('#',{new = df.histfig_hf_link_deityst,target_hf=worshipTarget,link_strength=9})
    end
end

setAllWorshippersInWorldToWorshipFig(tostring(args[1]))

And your moddable gods script:
Code: [Select]
-- Sets player-defined gods to correct civilizations.

--[[Here's an example of how to make a god:

[CREATURE:SHEOGORATH]
[DOES_NOT_EXIST]
[MALE]
[NAME:jovial man:Daedra:madness]
[CASTE_NAME:Sheogorath:Sheogorath:Sheogorath]
[DESCRIPTION:The Daedra of madness.]
[CREATURE_CLASS:DFHACK_GOD]
[SPHERE:MUSIC]
[SPHERE:ART]
[SPHERE:CHAOS]

]]


function findTemplateGodFig()
for k,fig in ipairs(df.global.world.history.figures) do
if fig.flags.deity then return fig end
end
end

function getCreatureClasses(creatureRaw)
local creatureClasses = {}
for _,caste in ipairs(creatureRaw.caste) do
for k,class in ipairs(caste.creature_class) do
table.insert(creatureClasses,class.value)
end
end
return creatureClasses
end

function deityIsOfSpecialCreature(creatureRaw)
for k,class in ipairs(getCreatureClasses(creatureRaw)) do
if class=="DFHACK_GOD" then return true end
end
return false
end

function scriptAlreadyRunOnThisWorld()
local figures = df.global.world.history.figures
for i=#figures-1,0,-1 do --goes through the table backwards because the particular hist figs involved are probably going to be the last
local figure = figures[i]
if not df.isnull(figure.flags) and figure.flags.deity and deityIsOfSpecialCreature(df.global.world.raws.creatures.all[figure.race]) then return true end
end
return false
end

function findAGod()
for k,fig in ipairs(df.global.world.history.figures) do
if fig.flags.deity then return fig end
end
return nil
end

function putListOfAllSpecialCreatureGodsTogether()
local specialCreatures = {}
for k,creatureRaw in ipairs(df.global.world.raws.creatures.all) do
if deityIsOfSpecialCreature(creatureRaw) then table.insert(specialCreatures,{creatureRaw,k}) end
end
return specialCreatures
end

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

function getRacesOfGod(god)
local civList={}
for k,class in ipairs(getCreatureClasses(god)) do
if stringStarts(class,"WORSHIP_ENTITY_") then table.insert(civList,string.sub(class,15)) end
end
return civList
end

function entityIsInGodsDomain(entity,entityRacesTable)
for k,v in ipairs(entityRacesTable) do
if v==entity.entity_raw.code then return true end
end
return false
end

function setUpTemplate(godFig,templateGod)
godFig.appeared_year=-1
godFig.born_year=-1
godFig.born_seconds=-1
godFig.curse_year=-1
godFig.curse_seconds=-1
godFig.old_year=-1
godFig.old_seconds=-1
godFig.died_year=-1
godFig.died_seconds=-1
godFig.name.has_name=true
godFig.breed_id=-1
godFig.flags:assign(templateGod.flags)
godFig.id = df.global.hist_figure_next_id
godFig.info = df.historical_figure_info:new()
godFig.info.spheres={new=true}
godFig.info.secret=df.historical_figure_info.T_secret:new()
end

function setUpGod(god,godID,templateGod)
local godFig = df.historical_figure:new()
setUpTemplate(godFig,templateGod)
godFig.sex=god.caste[0].gender
godFig.race=godID
godFig.name.first_name=god.caste[0].caste_name[2] --the adjectival form of the caste_name is used for the god's name, E.G, [CASTE_NAME:god:god:armok]
for k,v in ipairs(god.sphere) do --assigning spheres
godFig.info.spheres:insert('#',v)
end
df.global.world.history.figures:insert('#',godFig)
df.global.hist_figure_next_id=df.global.hist_figure_next_id+1
return godFig
end

--[[this function isn't really working right now so it's dummied out
function setGodAsOfficialDeityOfItsParticularEntity(god,godFig)
local entityRaces=getRacesOfGod(god)
for k,entity in ipairs(df.global.world.entities.all) do
if entityIsInGodsDomain(entity,entityRaces) then
entity.unknown1b.worship:insert('#',godFig.id)
end
end
end
]]
function moddableGods()
if scriptAlreadyRunOnThisWorld() then print("Already run on world...") return false end
local gods = putListOfAllSpecialCreatureGodsTogether()
local templateGod=findAGod()
for k,v in ipairs(gods) do --creature raws first
local god = v[1]
local godID = v[2]
local godFig = setUpGod(god,godID,templateGod)
--setGodAsOfficialDeityOfItsParticularEntity(god,godFig)
end
end


dfhack.onStateChange.letThereBeModdableGods = function(state)
if state == SC_WORLD_LOADED and df.global.gamemode~=3 then --make sure that the gods show up only after the rest of the histfigs do
moddableGods()
end
end

dfhack.onStateChange.letThereBeModdableGods()

The errorlog I get from dfhack looks like this:


No Armok is worshipped by the dwarves... I run both scripts from the init, I just added their names. Does the worship-script have to be run after worldgen ?
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 #271 on: July 31, 2013, 12:38:32 pm »

Ah, whoops. The worship-script... I forgot a line. Just one line. Add this near the top:

Code: [Select]
args = {...}

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Putnam's DFHack modder's utilities
« Reply #272 on: July 31, 2013, 12:42:11 pm »

Code: [Select]
-- Makes everyone worship someone. Usage: [scriptname] [unit's first name]
args = {...}

local function findWorshipTarget(filter)
    for _,fig in ipairs(df.global.world.history.figures) do
        if fig.name.first_name == filter then return fig.id end
    end
end

local function setAllWorshippersInWorldToWorshipArmok(filter)
    local worshipTarget = findWorshipTarget(filter)
    for k,fig in ipairs(df.global.world.history.figures) do
        fig.histfig_links:insert('#',{new = df.histfig_hf_link_deityst,target_hf=worshipTarget,link_strength=9})
    end
end

setAllWorshippersInWorldToWorshipFig(tostring(args[1]))

Ok, I'll have another try tomorrow. Now its time for sleep.

EDIT: Of course its not, who am I kidding? I tried the script I posted, with the args on top, same errorlog.
« Last Edit: July 31, 2013, 01:03:34 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 :::

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Putnam's DFHack modder's utilities
« Reply #273 on: July 31, 2013, 01:22:29 pm »

...did you make sure to include "Armok" after?

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Putnam's DFHack modder's utilities
« Reply #274 on: July 31, 2013, 01:26:50 pm »

I do have this creature in the raws, yes. Can it be because I run the script on startup, and not in a already genned world?

Code: [Select]
creature_armok

[OBJECT:CREATURE]

[CREATURE:ARMOK]
[DOES_NOT_EXIST]
[MALE]
[NAME:Armok:Armok:blood]
[CASTE_NAME:Armok:Armok:Armok]
[DESCRIPTION:The God of Blood.]
[CREATURE_CLASS:DFHACK_GOD]
[SPHERE:FORTRESSES]
[SPHERE:JEWELS]
[SPHERE:METALS]
[SPHERE:MINERALS]
[SPHERE:MOUNTAINS]
[SPHERE:WEALTH]
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 #275 on: July 31, 2013, 01:45:35 pm »

No, not in the raws, in the script. It's [scriptname] "Armok" (yes, the argument needs quotes)

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Putnam's DFHack modder's utilities
« Reply #276 on: August 02, 2013, 02:36:35 am »

Still wont do much good... I tried both at startup and with a genned world in the site selector and ingame in fortress mode.



The word in the script I used to replace Putnam is Armok, and the creature ID in the raws is ARMOK, the name is Armok. No idea why it does not work.
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 #277 on: August 02, 2013, 02:49:46 am »

...nonono, not in the function name. Replace Armok with Fig. You weren't supposed to replace anything in that last version, I made it so you don't have to.

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Putnam's DFHack modder's utilities
« Reply #278 on: August 02, 2013, 03:06:44 am »

You know, I cant follow you. "latest version"? I am talking about the script you posted on reddit, I only have one version of it. Its not "moddable gods" from this thread that is showing any errorlogs.

So where do I replace Armok with Fig? Here?

Quote
local function setAllWorshippersInWorldToWorshipArmok(filter)
local function setAllWorshippersInWorldToWorshipFig(filter)
    local worshipTarget = findWorshipTarget(filter)
    for k,fig in ipairs(df.global.world.history.figures) do
        fig.histfig_links:insert('#',{new = df.histfig_hf_link_deityst,target_hf=worshipTarget,link_strength=9})
    end
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 #279 on: August 02, 2013, 03:59:43 am »

Yes, there. The one on Reddit didn't need replacing anymore and I guess I forgot to remove that part whoops.

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Putnam's DFHack modder's utilities
« Reply #280 on: August 03, 2013, 02:40:24 am »

I replaced it with "Fig" and it does get rid of the errorlog. The script works, I have a custom god no that is worshipped. Sadly, this god is Nil Ilidzasir, Gem Setter. Everyone worships him, even he himself.



Another problem is that the script adds him as a worship target every time the game is started. So if people safe and load a game, he will be in the list twice. After 10 times, it will look like this:



Seems to me that the script is not quite working as intended. I dont know if you want to fiddle around with it, or if I made a mistake, or if you want to abandon it, just let me know what the plan is.
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 #281 on: August 03, 2013, 05:29:27 am »

I'll have to add a way to check if it's already been run that world. Also, did you include "Armok" (with quotes!) after the script's name?

HavingPhun

  • Bay Watcher
    • View Profile
Re: Putnam's DFHack modder's utilities
« Reply #282 on: August 05, 2013, 06:22:38 pm »

Sooo.. I forced 5 goblin sieges and 10 elf sieges :P. 30+ elf sieges have happened. They are never-ending. When I got to around 1000 invaders the lag was unbearable. I think I broke something.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Putnam's DFHack modder's utilities
« Reply #283 on: August 05, 2013, 07:25:55 pm »

(i am not to be held liable for any damage done to a user's system or fortress in the process of using these scripts)

HavingPhun

  • Bay Watcher
    • View Profile
Re: Putnam's DFHack modder's utilities
« Reply #284 on: August 05, 2013, 09:54:15 pm »

Oh no, it's fine. I found it funny.  ;D It's my fault for doing it anyways.
« Last Edit: August 05, 2013, 10:09:19 pm by HavingPhun »
Logged
Pages: 1 ... 17 18 [19] 20 21 ... 44