Changing traits with lua

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

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

As far as I know(and asked) this Lua - The Cataclysm: Dark Days Ahead Wiki

LUA functions are simply exported C++ functions, so they should work as their C++ counterparts.

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

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

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

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? :stuck_out_tongue:

I think for this maybe set_mutation would work best.

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

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