Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 366 367 [368] 369 370 ... 373

Author Topic: DFHack 0.34.11 r3  (Read 1388826 times)

Urist Da Vinci

  • Bay Watcher
  • [NATURAL_SKILL: ENGINEER:4]
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #5505 on: May 30, 2014, 01:27:55 am »

By request, a lua script with function to insert pets if they don't already exist
Note this won't add the creature to the wagon, pack, mount, minion, or exotic lists - just as a pet.
The code is rather unoptimized for CPU usage.

Code: [Select]
--comment


local function insertPet(alpha,beta,gamma)
local exists=false
for k,v in pairs(df.global.world.entities.all) do
--ENTITY TYPES
--Civilization 0
--SiteGovernment 1
--VesselCrew 2
--MigratingGroup 3
--NomadicGroup 4
--Religion 5
--MilitaryUnit 6
--Outcast 7
if v.type==0 and v.entity_raw.code==alpha then --exclude bandits
--print(k)
--printall(v.resources.animals)
for kk,vv in pairs(v.resources.animals.pet_races) do
--print(kk,vv,v.resources.animals.pet_castes[kk])
local checkrace = df.creature_raw.find(vv)
local checkcaste = checkrace.caste[v.resources.animals.pet_castes[kk]]
--print(checkrace.creature_id, checkcaste.caste_id)
if checkrace.creature_id == beta and checkcaste.caste_id == gamma then exists=true end
end
if exists==true then
print("ERROR- civilization ",alpha," has creature ", beta, gamma)
else
--the civ doesn't have the creature as a pet
--add the creature as a pet
local racenum=-1
local castenum=-1
for kk,vv in pairs(df.global.world.raws.creatures.all) do
--print(vv.creature_id)
if vv.creature_id==beta then
racenum=kk
--print(kk)
--printall(vv.caste)
for kkk,vvv in pairs(vv.caste) do
--print(vvv.caste_id)
if vvv.caste_id==gamma then castenum=kkk end
end
break
end
end
if racenum > -1 and castenum > -1 then
--print("success!!")
--print(v)
v.resources.animals.pet_races:insert('#',racenum)
v.resources.animals.pet_castes:insert('#',castenum)
print("Inserted ", beta, gamma, " in civ ",k, alpha)
else
print(beta, gamma, " not found in raws")
end
end
end
exists=false
end
end




--for example add CREATURE:DOG to ENTITY:PLAINS and CREATURE:HORSE to ENTITY:FOREST?
--As in: Humans have dogs and elves have horses

insertPet("PLAINS","DOG","MALE")
insertPet("PLAINS","DOG","FEMALE")
insertPet("FOREST","HORSE","MALE")
insertPet("FOREST","HORSE","FEMALE")
insertPet("MOUNTAIN","DRAGON","MALE")
insertPet("MOUNTAIN","DRAGON","FEMALE")

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: DFHack 0.34.11 r3
« Reply #5506 on: May 30, 2014, 04:54:10 am »

By request, a lua script with function to insert pets if they don't already exist
Note this won't add the creature to the wagon, pack, mount, minion, or exotic lists - just as a pet.
The code is rather unoptimized for CPU usage.

Code: [Select]
--comment


local function insertPet(alpha,beta,gamma)
local exists=false
for k,v in pairs(df.global.world.entities.all) do
--ENTITY TYPES
--Civilization 0
--SiteGovernment 1
--VesselCrew 2
--MigratingGroup 3
--NomadicGroup 4
--Religion 5
--MilitaryUnit 6
--Outcast 7
if v.type==0 and v.entity_raw.code==alpha then --exclude bandits
--print(k)
--printall(v.resources.animals)
for kk,vv in pairs(v.resources.animals.pet_races) do
--print(kk,vv,v.resources.animals.pet_castes[kk])
local checkrace = df.creature_raw.find(vv)
local checkcaste = checkrace.caste[v.resources.animals.pet_castes[kk]]
--print(checkrace.creature_id, checkcaste.caste_id)
if checkrace.creature_id == beta and checkcaste.caste_id == gamma then exists=true end
end
if exists==true then
print("ERROR- civilization ",alpha," has creature ", beta, gamma)
else
--the civ doesn't have the creature as a pet
--add the creature as a pet
local racenum=-1
local castenum=-1
for kk,vv in pairs(df.global.world.raws.creatures.all) do
--print(vv.creature_id)
if vv.creature_id==beta then
racenum=kk
--print(kk)
--printall(vv.caste)
for kkk,vvv in pairs(vv.caste) do
--print(vvv.caste_id)
if vvv.caste_id==gamma then castenum=kkk end
end
break
end
end
if racenum > -1 and castenum > -1 then
--print("success!!")
--print(v)
v.resources.animals.pet_races:insert('#',racenum)
v.resources.animals.pet_castes:insert('#',castenum)
print("Inserted ", beta, gamma, " in civ ",k, alpha)
else
print(beta, gamma, " not found in raws")
end
end
end
exists=false
end
end




--for example add CREATURE:DOG to ENTITY:PLAINS and CREATURE:HORSE to ENTITY:FOREST?
--As in: Humans have dogs and elves have horses

insertPet("PLAINS","DOG","MALE")
insertPet("PLAINS","DOG","FEMALE")
insertPet("FOREST","HORSE","MALE")
insertPet("FOREST","HORSE","FEMALE")
insertPet("MOUNTAIN","DRAGON","MALE")
insertPet("MOUNTAIN","DRAGON","FEMALE")
Thank you. I will do some tests today and let you know how it goes. :)

Quote
Note this won't add the creature to the wagon, pack, mount, minion, or exotic lists - just as a pet.
Wagon, Pack and Mount is clear to me. But Minion and Exotic? I assume that Minion = For example trolls in goblin sieges. And Exotic is just exotic pets, which atm does not mean a big difference.

Is it impossible to add pack or mount or wagon animals for traders, or just something that this specific script cant do, but potentially could be written?
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 :::

Urist Da Vinci

  • Bay Watcher
  • [NATURAL_SKILL: ENGINEER:4]
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #5507 on: May 30, 2014, 08:56:22 am »

...
Thank you. I will do some tests today and let you know how it goes. :)

Quote
Note this won't add the creature to the wagon, pack, mount, minion, or exotic lists - just as a pet.
Wagon, Pack and Mount is clear to me. But Minion and Exotic? I assume that Minion = For example trolls in goblin sieges. And Exotic is just exotic pets, which atm does not mean a big difference.

Is it impossible to add pack or mount or wagon animals for traders, or just something that this specific script cant do, but potentially could be written?

I presume there could be something written such as "if this creature has the appropriate wagon/pack/mount tokens, also add it to those lists". See also https://github.com/angavrilov/df-structures/blob/master/df.entities.xml#L324

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: DFHack 0.34.11 r3
« Reply #5508 on: May 30, 2014, 10:44:32 am »

I assume that Minion = For example trolls in goblin sieges. And Exotic is just exotic pets, which atm does not mean a big difference.
Minion is indeed for trolls in goblin sieges. Exotic, I'm not 100% certain about.

Is it impossible to add pack or mount or wagon animals for traders, or just something that this specific script cant do, but potentially could be written?
There's no reason why it can't be done - in fact, the old "fixwagons" plugin I wrote for version 0.31.25 used this exact same method to add wagons to Human and Dwarven civilizations.  Additionally, if you add wagons to Elven civilizations, I'm pretty sure they will use them - though their ethics prevent them from being given access to wagons, they do not prevent them from using wagons if they are given access to them by other means.
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: DFHack 0.34.11 r3
« Reply #5509 on: May 30, 2014, 11:01:21 am »

Quietust: I dont know if you are aware, but my mod includes several races you can play. So my intention is to give one race access to one type of wagon, pack, pull, pet and mount animal (and now minion, since that is pretty neat). And give another race access to other types. And now the important part: Without any of the pets be available to multiple civs.

In the beginning I could use entity tags for this, use cavern, good, evil animals, but with 6 playable races (and more enemy-only ones), this has become impossible.

Maybe I should open a new thread, and ask around if anyone wants to work on the script. Its quite useful for mods with a lot of different invaders, for example Fortress Defense.
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 :::

expwnent

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #5510 on: May 30, 2014, 08:43:52 pm »

By request, a lua script with function to insert pets if they don't already exist
Note this won't add the creature to the wagon, pack, mount, minion, or exotic lists - just as a pet.
The code is rather unoptimized for CPU usage.

That's a nice script, and with the examples it's clear how to use it, but you really should name your variables better. Among mathematicians it's traditional to make variables meaningless one character symbols, but among programmers it's necessary to make it very clear what things are supposed to be (in case you didn't know, not a passive-aggressive comment).
Logged

Urist Da Vinci

  • Bay Watcher
  • [NATURAL_SKILL: ENGINEER:4]
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #5511 on: May 31, 2014, 02:46:00 pm »

By request, a lua script with function to insert pets if they don't already exist
Note this won't add the creature to the wagon, pack, mount, minion, or exotic lists - just as a pet.
The code is rather unoptimized for CPU usage.

That's a nice script, and with the examples it's clear how to use it, but you really should name your variables better. Among mathematicians it's traditional to make variables meaningless one character symbols, but among programmers it's necessary to make it very clear what things are supposed to be (in case you didn't know, not a passive-aggressive comment).

If you mean the function arguments, I copied that part from a template lua function, and didn't get around to changing it. "Replace with" in notepad can fix that quickly. I tend to make things work first before making them look better. Engineer, not programmer.

expwnent

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #5512 on: May 31, 2014, 09:53:53 pm »

I only criticized because people would likely copy+paste your script verbatim, which would make their stuff slightly harder to understand for new modders looking at examples, or worse, teach bad habits about variable naming. The (untested) "corrected" code is below:

Code: [Select]
--comment


local function insertPet(entity,creature,caste)
local exists=false
for k,v in pairs(df.global.world.entities.all) do
--ENTITY TYPES
--Civilization 0
--SiteGovernment 1
--VesselCrew 2
--MigratingGroup 3
--NomadicGroup 4
--Religion 5
--MilitaryUnit 6
--Outcast 7
if v.type==df.historical_entity_type.Civilization and v.entity_raw.code==entity then --exclude bandits
--print(k)
--printall(v.resources.animals)
for kk,vv in pairs(v.resources.animals.pet_races) do
--print(kk,vv,v.resources.animals.pet_castes[kk])
local checkrace = df.creature_raw.find(vv)
local checkcaste = checkrace.caste[v.resources.animals.pet_castes[kk]]
--print(checkrace.creature_id, checkcaste.caste_id)
if checkrace.creature_id == creature and checkcaste.caste_id == caste then exists=true end
end
if exists==true then
print("ERROR- civilization ",entity," has creature ", creature, caste)
else
--the civ doesn't have the creature as a pet
--add the creature as a pet
local racenum=-1
local castenum=-1
for kk,vv in pairs(df.global.world.raws.creatures.all) do
--print(vv.creature_id)
if vv.creature_id==creature then
racenum=kk
--print(kk)
--printall(vv.caste)
for kkk,vvv in pairs(vv.caste) do
--print(vvv.caste_id)
if vvv.caste_id==caste then castenum=kkk end
end
break
end
end
if racenum > -1 and castenum > -1 then
--print("success!!")
--print(v)
v.resources.animals.pet_races:insert('#',racenum)
v.resources.animals.pet_castes:insert('#',castenum)
print("Inserted ", creature, caste, " in civ ",k, entity)
else
print(creature, caste, " not found in raws")
end
end
end
exists=false
end
end




--for example add CREATURE:DOG to ENTITY:PLAINS and CREATURE:HORSE to ENTITY:FOREST?
--As in: Humans have dogs and elves have horses

insertPet("PLAINS","DOG","MALE")
insertPet("PLAINS","DOG","FEMALE")
insertPet("FOREST","HORSE","MALE")
insertPet("FOREST","HORSE","FEMALE")
insertPet("MOUNTAIN","DRAGON","MALE")
insertPet("MOUNTAIN","DRAGON","FEMALE")
« Last Edit: June 01, 2014, 11:25:07 am by expwnent »
Logged

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: DFHack 0.34.11 r3
« Reply #5513 on: June 01, 2014, 11:02:06 am »

Minor improvement: "if v.type==0" to "if v.type==df.historical_entity_type.Civilization". When possible, always use enum types instead of magic numbers.
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.

expwnent

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #5514 on: June 01, 2014, 11:25:19 am »

Fixed.
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: DFHack 0.34.11 r3
« Reply #5515 on: June 01, 2014, 06:02:53 pm »

I tested the script, and it works. With OnLoad.init in the raw folder even automatically when the game is loaded. Otherwise people would have to run the script manually.

Next logical step would be adding functionality for minions, pack, pull and mounts. And wagons. Especially the mount and minion is interesting for enemies, and pack/pull/wagons for allies.

One other thing I would like to test is if this allows adding pets to civs on the fly, while a game is running. Lets say you trade with humans. You try to order "Mastiffs" from humans, but obviously they dont have any. But your civ has some, and you can bring 2 to a specific workshop and run "trade a breeding pair of Mastiffs to the humans". This runs the script, and adds the creature mastiff to the human civ. Next time their liaison comes by, you try to order pets, and oh wonder, they do have access to mastiffs now.

You could also periodically upgrade the enemy. First siege of creature X has no mounts. But they have an interaction that runs this script with SyndromeTrigger and add mounts to their sieges. Second siege has these mounts. Now the mounts have an interaction that targets the creature riding it and gives another interaction, that unlocks the next difficulty of mounts. Third siege might have these better mounts then. Or minions. Same thing.

Edit: I assume its not as easy as making a copy of the script and replacing all pet_races and pet_castes with wagon_races and wagon_castes, or minion_races and minion_castes, etc. ?
« Last Edit: June 01, 2014, 06:19:03 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 :::

PeridexisErrant

  • Bay Watcher
  • Dai stihó, Hrasht.
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #5516 on: June 01, 2014, 09:21:06 pm »

In light of the planned July 1 release (yay!), can we please do an official dfhack r5 sometime in June? 
Logged
I maintain the DF Starter Pack - over a million downloads and still counting!
 Donations here.

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: DFHack 0.34.11 r3
« Reply #5517 on: June 01, 2014, 10:21:45 pm »

One other thing I would like to test is if this allows adding pets to civs on the fly, while a game is running. Lets say you trade with humans. You try to order "Mastiffs" from humans, but obviously they dont have any. But your civ has some, and you can bring 2 to a specific workshop and run "trade a breeding pair of Mastiffs to the humans". This runs the script, and adds the creature mastiff to the human civ. Next time their liaison comes by, you try to order pets, and oh wonder, they do have access to mastiffs now.
I'm fairly certain that it does.

I assume its not as easy as making a copy of the script and replacing all pet_races and pet_castes with wagon_races and wagon_castes, or minion_races and minion_castes, etc. ?
That's exactly what you need to do.
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: DFHack 0.34.11 r3
« Reply #5518 on: June 02, 2014, 05:01:56 am »

I assume its not as easy as making a copy of the script and replacing all pet_races and pet_castes with wagon_races and wagon_castes, or minion_races and minion_castes, etc. ?
That's exactly what you need to do.
Neat. Just to make sure, the correct lines are :
mount_races/castes
pack_races/castes
pull_races/castes
minion_races/castes
wagon_races/castes
exotic_races/castes (or maybe pet_exotic_races/castes?)
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 :::

meeneque

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #5519 on: June 02, 2014, 05:50:22 am »

Does embark anywhere work anymore? Or do I have to play with memory (offset not found)? I couldn't find any coherent answer.
Thanks.
Logged
Pages: 1 ... 366 367 [368] 369 370 ... 373