Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 26 27 [28] 29 30 ... 42

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

expwnent

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #405 on: November 14, 2014, 11:28:52 pm »

Did you want remove syndrome by SYN_CLASS or by SYN_AFFECTED_CLASS? I implemented it for SYN_CLASS. It'll be in the next release.
« Last Edit: November 15, 2014, 12:20:44 am by expwnent »
Logged

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #406 on: November 16, 2014, 01:52:40 pm »

For SYN_CLASS, thanks!
Logged

expwnent

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #407 on: November 16, 2014, 05:16:10 pm »

New massive improvement in persistent table stuff! It should be dramatically easier this way than the old system.

Code: [Select]
local persistTable = require 'persist-table'
persistTable.GlobalTable.mana = {}
persistTable.GlobalTable.mana['3'] = '2'
print(persistTable.GlobalTable.mana['3']) --2
local manaTable = persistTable.GlobalTable.mana
mana['2'] = '3'
print(mana['2']) --3
mana['2'] = nil
print(mana['2']) --nil
persistTable.GlobalTable.mana = nil --don't worry about its descendents
print(persistTable.GlobalTable.mana) -- nil
--persistTable.GlobalTable.affinity['2']['3'] = '2' --error: indexing null table
persistTable.GlobalTable.affinity = {}
--etc

Right now you can only set strings and you can't directly access the child set but I can add that in later if you want.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #408 on: November 16, 2014, 05:19:27 pm »

Old stuff still compatible?

expwnent

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #409 on: November 16, 2014, 05:28:38 pm »

If you're using dfhack.persistent directly it should be compatible. If you're using an earlier version of the same script from a day or two ago then maybe.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #410 on: November 17, 2014, 12:37:00 am »

Is the new class system supposed to work in adventurer mode? I read up on the replacement and looked at the raws and to my understanding every adventurer should get their first ability at 15 kills, the next at 35, and after that doesn't matter for this example. However, I got 64 kills with a character and have yet to get any abilities in the x tab. The character was specifically a hero of blood and I've been killing dersites, imps, ogres, basilisks, and human bandits.

Did I forget something?

expwnent

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #411 on: November 17, 2014, 01:46:21 am »

Test it to be sure but *-trigger scripts tend to have a little trouble in adventure mode. Currently I don't guarantee it works there but I'd be interested to hear.
Logged

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #412 on: November 17, 2014, 05:00:31 am »

New massive improvement in persistent table stuff! It should be dramatically easier this way than the old system.

Code: [Select]
local persistTable = require 'persist-table'
persistTable.GlobalTable.mana = {}
persistTable.GlobalTable.mana['3'] = '2'
print(persistTable.GlobalTable.mana['3']) --2
local manaTable = persistTable.GlobalTable.mana
mana['2'] = '3'
print(mana['2']) --3
mana['2'] = nil
print(mana['2']) --nil
persistTable.GlobalTable.mana = nil --don't worry about its descendents
print(persistTable.GlobalTable.mana) -- nil
--persistTable.GlobalTable.affinity['2']['3'] = '2' --error: indexing null table
persistTable.GlobalTable.affinity = {}
--etc

Right now you can only set strings and you can't directly access the child set but I can add that in later if you want.

Very nice, is there only GlobalTable? And is there any limit to the depth of the table?

Is the new class system supposed to work in adventurer mode? I read up on the replacement and looked at the raws and to my understanding every adventurer should get their first ability at 15 kills, the next at 35, and after that doesn't matter for this example. However, I got 64 kills with a character and have yet to get any abilities in the x tab. The character was specifically a hero of blood and I've been killing dersites, imps, ogres, basilisks, and human bandits.

Did I forget something?

Hmm, I never tried it in adventure mode, only in Arena and Fortress. A simple test would be to uncomment line 66 in hack\scripts\base\classes.lua that will tell you if it is registering kills and adding experience correctly. If it is doing those things then it is entirely possible I messed something up somewhere. I will try and take a look at it sometime today.
Logged

expwnent

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #413 on: November 17, 2014, 06:40:22 am »

Nope, you can do as much as you want.
Logged

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #414 on: November 18, 2014, 11:50:42 am »

@Putnam: Sorry, I haven't had a chance to look at the class system yet, but could you post one of your classes so I can test it with that?

Nope, you can do as much as you want.

Excellent, now I just need to rewrite all of my code  :)

EDIT: For clarification, before I start to rewrite things

I can have as many entries as I want in persistentTable correct? So I can have persistentTable.GlobalTable, persistentTable.ClassTable, persistentTable.UnitTable, etc... ?

Can I set a persistentTable equal to an already constructed table? For instance if I have SampleTable = { { { } } }, can I just say persistentTable.ExampleTable = SampleTable?

What happens if I try and reference an index that is non-existent? Will it give an error or a nil result?
« Last Edit: November 19, 2014, 12:03:12 am by Roses »
Logged

expwnent

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #415 on: November 19, 2014, 01:17:10 am »

You should use persistTable.GlobalTable.roses.ClassTable, persistTable.GlobalTable.roses.UnitTable, etc.

You must initialize a subtable before accessing it.

Code: [Select]
local globalTable = require('persist-table').GlobalTable
print(globalTable.roses) --nil
globalTable.roses = globalTable.roses or {} --initializes it or reuses the old one
globalTable.roses.UnitTable = {} --deletes the old one if it exists
--print(globalTable.roses.ClassTable.foo) --error: attempt to index nil (unless ClassTable was already initialized in this save)
globalTable.roses = nil --explicitly erase the table and all subtables

You cannot do

Code: [Select]
local bob = {}
bob.foo = '1'
bob.bar = '2'
require('persist-table').GlobalTable.asdf = bob

That will fail with the message 'setting value to an invalid table'. If you really want it I can permit that sort of thing. It might make things convenient.

If you try something like

Code: [Select]
globalTable.asdf = globalTable.foo

then it won't crash but it will almost definitely lead to mysterious errors if you try to delete things. Unless globalTable.foo is a string. Then it'll be fine.
« Last Edit: November 19, 2014, 01:21:51 am by expwnent »
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #416 on: November 19, 2014, 01:31:00 am »

"...\Fortbent.Graphical\hack\lua\classes\establish-class.lua:6: attempt to index local 'unit' (a nil value)
stack traceback:
           ...\Fortbent.Graphical\hack\lua\classes\establish-class.lua:6: in function 'establishclass'
           ...rtbent.Graphical\hack\scripts/classes.add-experience.lua:65: in main chunk
           (...tail calls...)
           ...f fortress\Fortbent.Graphical\hack\scripts/something.lua:2: in main chunk
           (...tail calls...)"

When calling this script:

Code: [Select]
local amount=... or 1
dfhack.run_script('classes/add-experience','-unit',df.global.world.units.active[0].id,'-amount',amount)

It seems to be from add-experience.lua just sorta calling "establishclass(unit,classes)" without ever defining either, unless I'm expected to define both of those.

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #417 on: November 19, 2014, 06:21:45 am »

You should use persistTable.GlobalTable.roses.ClassTable, persistTable.GlobalTable.roses.UnitTable, etc.

You must initialize a subtable before accessing it.

Code: [Select]
local globalTable = require('persist-table').GlobalTable
print(globalTable.roses) --nil
globalTable.roses = globalTable.roses or {} --initializes it or reuses the old one
globalTable.roses.UnitTable = {} --deletes the old one if it exists
--print(globalTable.roses.ClassTable.foo) --error: attempt to index nil (unless ClassTable was already initialized in this save)
globalTable.roses = nil --explicitly erase the table and all subtables

You cannot do

Code: [Select]
local bob = {}
bob.foo = '1'
bob.bar = '2'
require('persist-table').GlobalTable.asdf = bob

That will fail with the message 'setting value to an invalid table'. If you really want it I can permit that sort of thing. It might make things convenient.

If you try something like

Code: [Select]
globalTable.asdf = globalTable.foo

then it won't crash but it will almost definitely lead to mysterious errors if you try to delete things. Unless globalTable.foo is a string. Then it'll be fine.

It would be convenient to be able to just say require('persist-table').GlobalTable.asdf = asdfTable, since my scripts are already creating a table and I could just store it with a single line. But I can also just make some adjustments so it's not really necessary. Actually I just realized it will be pretty easy because I already have to create the table by initializing everything. Right now I start with classes = {}, so I will just have to replace that with classes = persistTable.GlobalTable.roses.ClassTable (where I already initialized the roses and ClassTable portions with persistTable.GlobalTable.roses = {} and persistTable.GlobalTable.roses.ClassTable = {} )

"...\Fortbent.Graphical\hack\lua\classes\establish-class.lua:6: attempt to index local 'unit' (a nil value)
stack traceback:
           ...\Fortbent.Graphical\hack\lua\classes\establish-class.lua:6: in function 'establishclass'
           ...rtbent.Graphical\hack\scripts/classes.add-experience.lua:65: in main chunk
           (...tail calls...)
           ...f fortress\Fortbent.Graphical\hack\scripts/something.lua:2: in main chunk
           (...tail calls...)"

When calling this script:

Code: [Select]
local amount=... or 1
dfhack.run_script('classes/add-experience','-unit',df.global.world.units.active[0].id,'-amount',amount)

It seems to be from add-experience.lua just sorta calling "establishclass(unit,classes)" without ever defining either, unless I'm expected to define both of those.

Hmm, that is very odd, that works fine for me. Did I perchance upload a bugged version? Is this what your add-experience.lua looks like?

Code: [Select]
local split = require('split')
local utils = require 'utils'
local establishclass = require('classes.establish-class')
local read_file = require('classes.read-file')
local checkclass = require('classes.requirements-class')
local checkspell = require('classes.requirements-spell')

function addexperience(unit,amount,classes)
 kill_id = unit
 if kill_id >=0 then
  exps = amount
--  print('Add Experience to unit '..tostring(kill_id)..'. In the amount of '..tostring(amount))
  pers,status = dfhack.persistent.get(tostring(kill_id)..'_current_class')
  pers.ints[1] = pers.ints[1] + exps
  pers.ints[2] = pers.ints[2] + exps
  pers.ints[3] = pers.ints[3] + exps
  dfhack.persistent.save({key=tostring(kill_id)..'_current_class',value=pers.value,ints=pers.ints})
--  print('Total Experience is '..tostring(pers.ints[2]))
  if pers.value ~= 'NONE' then
   cpers,status = dfhack.persistent.get(tostring(kill_id)..'_'..pers.value)
   clevel = cpers.ints[2]
   if clevel < classes[pers.value]['LEVELS'] then
    cexp = tonumber(split(classes[pers.value]['EXP'][clevel+1],']')[1])
    if pers.ints[1] > cexp then
     cpers.ints[2] = cpers.ints[2] + 1
      print('LEVEL UP!! '..pers.value..' LEVEL '..tostring(cpers.ints[2]))
      if classes[pers.value]['B_PHYS'] then
       for i,x in pairs(classes[pers.value]['B_PHYS']) do
        dfhack.run_script('unit/attribute-change',table.unpack({'-unit',tostring(kill_id),'-physical',i,'-fixed','\\'..tostring(tonumber(split(x[cpers.ints[2]+1],']')[1]))}))
       end
      end
      if classes[pers.value]['B_MENT'] then
       for i,x in pairs(classes[pers.value]['B_MENT']) do
        dfhack.run_script('unit/attribute-change',table.unpack({'-unit',tostring(kill_id),'-mental',i,'-fixed','\\'..tostring(tonumber(split(x[cpers.ints[2]+1],']')[1]))}))
       end
      end
      if classes[pers.value]['B_SKILL'] then
       for i,x in pairs(classes[pers.value]['B_SKILL']) do
        dfhack.run_script('unit/skill-change',table.unpack({'-unit',tostring(kill_id),'-skill',i,'-fixed','\\'..tostring(tonumber(split(x[cpers.ints[2]+1],']')[1]))}))
       end
      end
      if classes[pers.value]['B_TRAIT'] then
       for i,x in pairs(classes[pers.value]['B_TRAIT']) do
        dfhack.run_script('unit/trait-change',table.unpack({'-unit',tostring(kill_id),'-trait',i,'-fixed','\\'..tostring(tonumber(split(x[cpers.ints[2]+1],']')[1]))}))
       end
      end
      if cpers.ints[2] == classes[pers.value]['LEVELS'] then
   print('REACHED MAX LEVEL FOR CLASS '..pers.value)
   if classes[pers.value]['A_UPGRADE'] then dfhack.run_script('classes/change-class',table.unpack({'-unit',tostring(kill_id),'-class',classes[pers.value]['A_UPGRADE']})) end
  end
     end
    end
   dfhack.persistent.save({key=tostring(kill_id)..'_'..cpers.value,value=cpers.value,ints=cpers.ints})
  end
 end
end

file = dfhack.getDFPath().."/raw/objects/classes.txt"
classes = read_file(file)

validArgs = validArgs or utils.invert({
 'help',
 'unit',
 'amount',
})
local args = utils.processArgs({...}, validArgs)

unit = df.unit.find(tonumber(args.unit))

establishclass(unit,classes)
addexperience(tonumber(args.unit),tonumber(args.amount),classes)
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #418 on: November 19, 2014, 03:10:25 pm »

Code: [Select]
local split = require('split')
local utils = require 'utils'
local establishclass = require('classes.establish-class')
local read_file = require('classes.read-file')
local checkclass = require('classes.requirements-class')
local checkspell = require('classes.requirements-spell')

function addexperience(unit,amount,classes)
 kill_id = unit
 if kill_id >=0 then
  exps = amount
  pers,status = dfhack.persistent.get(tostring(kill_id)..'_current_class')
  pers.ints[1] = pers.ints[1] + exps
  pers.ints[2] = pers.ints[2] + exps
  if pers.value ~= 'NONE' then
   cpers,status = dfhack.persistent.get(tostring(kill_id)..'_'..pers.value)
   clevel = cpers.ints[2]
   if clevel < classes[pers.value]['LEVELS'] then
    cexp = tonumber(split(classes[pers.value]['EXP'][clevel+1],']')[1])
    if pers.ints[2] > cexp then
     cpers.ints[2] = cpers.ints[2] + 1
      print('LEVEL UP!! '..pers.value..' LEVEL '..tostring(cpers.ints[2]))
      if classes[pers.value]['B_PHYS'] then
       for i,x in pairs(classes[pers.value]['B_PHYS']) do
        dfhack.run_script('unit/attribute-change',table.unpack({'-unit',tostring(kill_id),'-physical',i,'-fixed','\\'..tostring(tonumber(split(x[cpers.ints[2]+1],']')[1])-tonumber(split(x[cpers.ints[2]],']')[1]))}))
       end
      end
      if classes[pers.value]['B_MENT'] then
       for i,x in pairs(classes[pers.value]['B_MENT']) do
        dfhack.run_script('unit/attribute-change',table.unpack({'-unit',tostring(kill_id),'-mental',i,'-fixed','\\'..tostring(tonumber(split(x[cpers.ints[2]+1],']')[1])-tonumber(split(x[cpers.ints[2]],']')[1]))}))
       end
      end
      if classes[pers.value]['B_SKILL'] then
       for i,x in pairs(classes[pers.value]['B_SKILL']) do
        dfhack.run_script('unit/skill-change',table.unpack({'-unit',tostring(kill_id),'-skill',i,'-fixed','\\'..tostring(tonumber(split(x[cpers.ints[2]+1],']')[1])-tonumber(split(x[cpers.ints[2]],']')[1]))}))
       end
      end
      if classes[pers.value]['B_TRAIT'] then
       for i,x in pairs(classes[pers.value]['B_TRAIT']) do
        dfhack.run_script('unit/trait-change',table.unpack({'-unit',tostring(kill_id),'-trait',i,'-fixed','\\'..tostring(tonumber(split(x[cpers.ints[2]+1],']')[1])-tonumber(split(x[cpers.ints[2]],']')[1]))}))
       end
      end
      if cpers.ints[2] == classes[pers.value]['LEVELS'] then
   print('REACHED MAX LEVEL FOR CLASS '..pers.value)
   if classes[pers.value]['A_UPGRADE'] then dfhack.run_script('classes/change-class',table.unpack({'-unit',tostring(kill_id),'-class',classes[pers.value]['A_UPGRADE']})) end
  end
     end
    end
   dfhack.persistent.save({key=tostring(kill_id)..'_'..cpers.value,value=cpers.value,ints=cpers.ints})
  end
 end
end

file = dfhack.getDFPath().."/raw/objects/classes.txt"
classes = read_file(file)

validArgs = validArgs or utils.invert({
 'help',
 'unit',
 'amount',
})
local args = utils.processArgs({...}, validArgs)

establishclass(unit,classes)
addexperience(tonumber(args.unit),tonumber(args.amount),classes)

Yep, looks like it.

EDIT: The version you posted still uses unit before it's defined...
« Last Edit: November 19, 2014, 03:15:05 pm by Putnam »
Logged

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #419 on: November 20, 2014, 12:51:48 am »

No, at the very end you see

Code: [Select]
unit = df.unit.find(tonumber(args.unit))

establishclass(unit,classes)
addexperience(tonumber(args.unit),tonumber(args.amount),classes)
Logged
Pages: 1 ... 26 27 [28] 29 30 ... 42