Author Topic: changing traits with lua  (Read 796 times)

Offline Cassumbra

  • Zombie Food
  • *
  • Posts: 8
    • View Profile
changing traits with lua
« on: May 06, 2017, 02:05:25 AM »
hi i'm new here and please don't remove lua support because i want to do stuff with it

is it possible to change the player's traits using lua? I saw someone use it to change player stats over time in another thread. i want to make a jekyll/hyde mod where you change at night and turn back in the morning

EDIT: aw shoot i think i put this in the wrong place. if this is supposed to be in the code help board then please put it there. sorry
« Last Edit: May 06, 2017, 02:07:46 AM by Cassumbra »

Offline Cassumbra

  • Zombie Food
  • *
  • Posts: 8
    • View Profile
Re: changing traits with lua
« Reply #1 on: May 08, 2017, 10:32:02 PM »
is there any documentation for lua support? i know that the wiki has a list of functions and attributes but many of the entries don't have a description so i'm not sure how they work

Offline Alec White

  • NPC
  • **
  • Posts: 215
  • I'm shy
    • View Profile
Re: changing traits with lua
« Reply #2 on: May 09, 2017, 03:46:33 AM »
is there any documentation for lua support?

As far as I know(and asked) this http://cddawiki.chezzo.com/cdda_wiki/index.php?title=Lua#player

Offline Zhilkin

  • NPC
  • **
  • Posts: 218
    • View Profile
Re: changing traits with lua
« Reply #3 on: May 13, 2017, 09:18:43 AM »
is there any documentation for lua support? i know that the wiki has a list of functions and attributes but many of the entries don't have a description so i'm not sure how they work
LUA functions are simply exported C++ functions, so they should work as their C++ counterparts.

Offline Cassumbra

  • Zombie Food
  • *
  • Posts: 8
    • View Profile
Re: changing traits with lua
« Reply #4 on: May 15, 2017, 04:58:15 AM »
oh ok cool! so are all functions exported or is it only the ones listed on the wiki?

Offline Zhilkin

  • NPC
  • **
  • Posts: 218
    • View Profile
Re: changing traits with lua
« Reply #5 on: May 15, 2017, 06:03:23 AM »
oh ok cool! so are all functions exported or is it only the ones listed on the wiki?
Everything available in LUA is gathered in https://github.com/CleverRaven/Cataclysm-DDA/blob/master/lua/class_definitions.lua

Offline Cassumbra

  • Zombie Food
  • *
  • Posts: 8
    • View Profile
Re: changing traits with lua
« Reply #6 on: May 15, 2017, 04:42:21 PM »
so I would use player.add_trait()? do you know if there's a list of trait ids or something similar I would use for this? sorry for being a bother

Offline Zhilkin

  • NPC
  • **
  • Posts: 218
    • View Profile
Re: changing traits with lua
« Reply #7 on: May 15, 2017, 05:08:38 PM »
so I would use player.add_trait()? do you know if there's a list of trait ids or something similar I would use for this? sorry for being a bother
I believe all traits are defined in https://github.com/CleverRaven/Cataclysm-DDA/blob/6d1b73231b7b70d53790b2851b90864d86cf7db1/data/json/mutations.json

Offline Alec White

  • NPC
  • **
  • Posts: 215
  • I'm shy
    • View Profile
Re: changing traits with lua
« Reply #8 on: May 15, 2017, 05:10:16 PM »
so I would use player.add_trait()? do you know if there's a list of trait ids or something similar I would use for this? sorry for being a bother

They are in mutation.json if I'm not wrong.

Offline Cassumbra

  • Zombie Food
  • *
  • Posts: 8
    • View Profile
Re: changing traits with lua
« Reply #9 on: May 15, 2017, 06:31:33 PM »
whenever I try to use add_traits or remove_mutation it tells me that I need to use userdata. how do I give it what it wants? :p

Offline Alec White

  • NPC
  • **
  • Posts: 215
  • I'm shy
    • View Profile
Re: changing traits with lua
« Reply #10 on: May 15, 2017, 06:46:24 PM »
I think for this maybe set_mutation would work best.

Offline Cassumbra

  • Zombie Food
  • *
  • Posts: 8
    • View Profile
Re: changing traits with lua
« Reply #11 on: May 15, 2017, 07:06:26 PM »
oh! it turned out I had to be using a : instead of a . . thanks for all the help guys, I'll start working on the mod thing when I get home

Offline Cassumbra

  • Zombie Food
  • *
  • Posts: 8
    • View Profile
Re: changing traits with lua
« Reply #12 on: May 16, 2017, 02:32:36 AM »
wait does lua support have callback functions? and if it does can someone give me a list of them?

Offline Zhilkin

  • NPC
  • **
  • Posts: 218
    • View Profile
Re: changing traits with lua
« Reply #13 on: June 11, 2017, 06:11:35 PM »
wait does lua support have callback functions? and if it does can someone give me a list of them?

There are four LUA callbacks, two of which are calendar-related:

    `on_new_player_created` -  called when starting the game (used in StatsThroughSkills mod)
    `on_skill_increased` -  called when player skill is increased (used in StatsThroughSkills mod)
    `on_day_passed` -  called once a day (at midnight)
    `on_minute_passed`- called once a minute