Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Lua scripts?  (Read 565 times)

deepspaceprobe9

  • Bay Watcher
  • "Personal" Text
    • View Profile
Lua scripts?
« on: November 18, 2014, 05:42:15 pm »

I have some experience with lua, but none with using it with dfhack. Where would I get started with that? What would I refer to when trying to modify the raws and or individual creatures? Or maybe even stuff like Urist D'Vinci with battle calculations, or Putnam with his irl to df unit material calculators?
Logged
   (*) Stopped zombies from interrupting your sleep to ask if they can help you with something

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Lua scripts?
« Reply #1 on: November 18, 2014, 06:13:08 pm »

The df-to-unit is actually a python script; it operates completely independently of DF. I coulda made it in C++ or whatever, and I even did make it in C++ way back when, but I decided that making people download .exe files would be too much hassle (for the security-minded).

As for DFHack with Lua: the Lua API has real nice documentation.. Modifying raws in-game will be ineffective; it'll work while you're playing, but items already made of materials won't be affected AFAIK and all raw changes will be reset upon the world being regenerated anyway (unless you modify the raw files with Lua directly). Changing individual creatures is fairly easy; you don't even need scripting experience, just highlight them and type "gui/gm-editor". If you want to make a script to automate that kind of thing, you're going to have to learn about the data structures... which gm-editor will do just fine, as long as you remember that everything you use "enter" to enter in gm-editor can be accessed in Lua like so.

For example (for this example, define "->" as "press enter on"):

unit->status->current_soul->personality->emotions

can be accessed with Lua like so:

unit.status.current_soul.personality.emotions

deepspaceprobe9

  • Bay Watcher
  • "Personal" Text
    • View Profile
Re: Lua scripts?
« Reply #2 on: November 18, 2014, 06:18:30 pm »

I have an intermediate mastery of Lua, but I just need to know
A) What to refer to; i.e."current_soul"(What is that? The creature under the cursor?)
B) How to insert the code files into DFHack
C) How to look at the scripts DFHack comes with to learn more
Logged
   (*) Stopped zombies from interrupting your sleep to ask if they can help you with something

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Lua scripts?
« Reply #3 on: November 18, 2014, 06:22:57 pm »

a) current_soul is a pointer to the unit's current soul. You need to worry more about getting the unit, since every unit that has a soul at all will have current_soul.

b) .lua files in hack/scripts

c) Read the .lua files in hack/scripts, which can be opened in any text editor.

deepspaceprobe9

  • Bay Watcher
  • "Personal" Text
    • View Profile
Re: Lua scripts?
« Reply #4 on: November 18, 2014, 06:46:32 pm »

Thanks
Logged
   (*) Stopped zombies from interrupting your sleep to ask if they can help you with something