# Increases Stats when skills raise

**URL:** https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773
**Category:** The Lab
**Created:** [June 9, 2015, 7:53pm UTC](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773 "2015-06-09T19:53:47Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![DeNarr](https://avatars.discourse-cdn.com/v4/letter/d/d6d6ee/32.png) [@DeNarr](https://discourse.cataclysmdda.org/u/DeNarr)
#### Post date: [June 9, 2015, 7:53pm UTC](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773/1 "2015-06-09T19:53:47Z")

</div>

So, I have modified the code so that whenever I hit levels 3, 6, and 9 of a skill, it will raise an appropriate stat (I like raising skills to mean something). I’ve got this to work, but I had to modify the src files in order to do so. I was wondering if anyone knew how to modify the src files with a mod. If not, is there a way to grab the current skill level using json?

As an example, here is a snippet of code that I added to characters.cpp.

` int barter_skill = get_skill_level("barter");
        if (barter_skill >= 3) {
            mod_int_bonus(1);
            if (barter_skill >= 6) {
                mod_int_bonus(1);
                if (barter_skill >= 9) {
                    mod_int_bonus(1);
                }
            }
        }`

---

<div class="post-metadata">

### Author: ![Coolthulhu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/coolthulhu/32/2446_2.png) [@Coolthulhu](https://discourse.cataclysmdda.org/u/Coolthulhu)
#### Post date: [June 9, 2015, 11:18pm UTC](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773/2 "2015-06-09T23:18:03Z")

</div>

With a json no, but it could be done with a lua script.

---

<div class="post-metadata">

### Author: ![CIB](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/cib/32/903_2.png) [@CIB](https://discourse.cataclysmdda.org/u/CIB)
#### Post date: [June 10, 2015, 12:40pm UTC](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773/3 "2015-06-10T12:40:26Z")

</div>

Yeah, it should be possible (if awkward) to modify stats based on current skill level at regular intervals.

---

<div class="post-metadata">

### Author: ![DeNarr](https://avatars.discourse-cdn.com/v4/letter/d/d6d6ee/32.png) [@DeNarr](https://discourse.cataclysmdda.org/u/DeNarr)
#### Post date: [June 10, 2015, 5:57pm UTC](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773/4 "2015-06-10T17:57:54Z")

</div>

Hmm, I’m not seeing any lua function that would get the current skill level. If this exists, can someone point me at it? Also, are there any good mods that use lua scripts that I can use for reference? The only ones that come stick are just a few lines of code to make single changes to zombies.

---

<div class="post-metadata">

### Author: ![CIB](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/cib/32/903_2.png) [@CIB](https://discourse.cataclysmdda.org/u/CIB)
#### Post date: [June 10, 2015, 6:50pm UTC](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773/5 "2015-06-10T18:50:44Z")

</div>

You’re right, the get\_skill\_level function isn’t in the class\_definitions.lua … Wonder why, I’ll try adding it and see what happens.

---

<div class="post-metadata">

### Author: ![CIB](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/cib/32/903_2.png) [@CIB](https://discourse.cataclysmdda.org/u/CIB)
#### Post date: [June 10, 2015, 7:26pm UTC](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773/6 "2015-06-10T19:26:25Z")

</div>

> <https://github.com/CleverRaven/Cataclysm-DDA/pull/12621/files>

Once this lands you should be able to use get\_skill\_level(“melee”) to get the skill level. You could e.g. use set\_str\_bonus to modify the strength stat.

---

<div class="post-metadata">

### Author: ![DeNarr](https://avatars.discourse-cdn.com/v4/letter/d/d6d6ee/32.png) [@DeNarr](https://discourse.cataclysmdda.org/u/DeNarr)
#### Post date: [June 10, 2015, 7:56pm UTC](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773/7 "2015-06-10T19:56:37Z")

</div>

Awesome, that will allow me to get the main body of the work done. Though do you know how lua’s get called? When I put the code into the src files, I just stuck it into the reset\_stats() function. The examples make it look like they are just making a static change on startup.

---

<div class="post-metadata">

### Author: ![DeNarr](https://avatars.discourse-cdn.com/v4/letter/d/d6d6ee/32.png) [@DeNarr](https://discourse.cataclysmdda.org/u/DeNarr)
#### Post date: [June 11, 2015, 5:45pm UTC](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773/8 "2015-06-11T17:45:16Z")

</div>

Yea, I’ve been looking into this more, and it really seems like the mods just get loaded in once you start. Does somebody know of a way around this? Where I can make my code be called based on a condition?

---

<div class="post-metadata">

### Author: ![joxer](https://avatars.discourse-cdn.com/v4/letter/j/f19dbf/32.png) [@joxer](https://discourse.cataclysmdda.org/u/joxer)
#### Post date: [June 11, 2015, 6:05pm UTC](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773/9 "2015-06-11T18:05:09Z")

</div>

I’m no programmer [size=7pt]so pardon me for cluttering the thread[/size]  
but if that’s truly the case i could see how sleeping or resting would call upon this function without much intrusion.

I’m actually quite interested in this mechanic, however i’d like to inquire a little about progression

[spoiler]  
a quote from a discussion for example, link provided

> [@Skill/Leveling rebalance feedback thread](https://discourse.cataclysmdda.org/t/skill-leveling-rebalance-feedback-thread/9237/21):
>
> Also, you need more perception to keep improving skills with inaccurate weapons.

Wouldn’t the ability to increase stats underline countermeasures described in that thread?

---

<div class="post-metadata">

### Author: ![DeNarr](https://avatars.discourse-cdn.com/v4/letter/d/d6d6ee/32.png) [@DeNarr](https://discourse.cataclysmdda.org/u/DeNarr)
#### Post date: [June 11, 2015, 6:17pm UTC](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773/10 "2015-06-11T18:17:54Z")

</div>

[quote=“joxer, post:9, topic:9773”]I’m no programmer [size=7pt]so pardon me for cluttering the thread[/size]  
but if that’s truly the case i could see how sleeping or resting would call upon this function without much intrusion.

I’m actually quite interested in this mechanic, however i’d like to inquire a little about progression

[spoiler]  
a quote from a discussion for example, link provided

> [@Skill/Leveling rebalance feedback thread](https://discourse.cataclysmdda.org/t/skill-leveling-rebalance-feedback-thread/9237/21):
>
> Also, you need more perception to keep improving skills with inaccurate weapons.

Wouldn’t the ability to increase stats underline countermeasures described in that thread?[/quote]

For your first part, the problem isn’t trying to find a good condition that can call on this, the problem is how to get the lua code to be called when performing that condition. (I’ve done this already when modifying the source code, just trying to get it to work with the mod format)

For the second part, it would actually work quite well. As you use guns more, you perception increases, allowing you to use less accurate guns while still increasing your skill. As opposed to never being able to use less accurate guns to raise skill, if you didn’t get your per really high to start.

---

<div class="post-metadata">

### Author: ![DeNarr](https://avatars.discourse-cdn.com/v4/letter/d/d6d6ee/32.png) [@DeNarr](https://discourse.cataclysmdda.org/u/DeNarr)
#### Post date: [June 12, 2015, 6:21pm UTC](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773/11 "2015-06-12T18:21:20Z")

</div>

[quote=“CIB, post:6, topic:9773”][https://github.com/CleverRaven/Cataclysm-DDA/pull/12621/files](https://github.com/CleverRaven/Cataclysm-DDA/pull/12621/files)

Once this lands you should be able to use get\_skill\_level(“melee”) to get the skill level. You could e.g. use set\_str\_bonus to modify the strength stat.[/quote]

Hmm, do you know if it is possible to create a variable with LUA that will last between reloads? Because setting a bonus is only temporary, and since the callback function only occurs once a day (at midnight), instead of on every turn, the bonus would just go away the very next turn. This can be fixed by setting the max value instead, but I would want a way to store what the user’s original starting stats were.

---

<div class="post-metadata">

### Author: ![CIB](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/cib/32/903_2.png) [@CIB](https://discourse.cataclysmdda.org/u/CIB)
#### Post date: [June 12, 2015, 8:00pm UTC](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773/12 "2015-06-12T20:00:15Z")

</div>

[quote=“DeNarr, post:11, topic:9773”][quote=“CIB, post:6, topic:9773”][https://github.com/CleverRaven/Cataclysm-DDA/pull/12621/files](https://github.com/CleverRaven/Cataclysm-DDA/pull/12621/files)

Once this lands you should be able to use get\_skill\_level(“melee”) to get the skill level. You could e.g. use set\_str\_bonus to modify the strength stat.[/quote]

Hmm, do you know if it is possible to create a variable with LUA that will last between reloads? Because setting a bonus is only temporary, and since the callback function only occurs once a day (at midnight), instead of on every turn, the bonus would just go away the very next turn. This can be fixed by setting the max value instead, but I would want a way to store what the user’s original starting stats were.[/quote]

Yes, you can use player.set\_var(“varname”, value). It would probably be pretty easy to add a per-turn callback, too, if you need that.

---

<div class="post-metadata">

### Author: ![DeNarr](https://avatars.discourse-cdn.com/v4/letter/d/d6d6ee/32.png) [@DeNarr](https://discourse.cataclysmdda.org/u/DeNarr)
#### Post date: [June 12, 2015, 9:15pm UTC](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773/13 "2015-06-12T21:15:08Z")

</div>

[quote=“CIB, post:12, topic:9773”][quote=“DeNarr, post:11, topic:9773”][quote=“CIB, post:6, topic:9773”][https://github.com/CleverRaven/Cataclysm-DDA/pull/12621/files](https://github.com/CleverRaven/Cataclysm-DDA/pull/12621/files)

Once this lands you should be able to use get\_skill\_level(“melee”) to get the skill level. You could e.g. use set\_str\_bonus to modify the strength stat.[/quote]

Hmm, do you know if it is possible to create a variable with LUA that will last between reloads? Because setting a bonus is only temporary, and since the callback function only occurs once a day (at midnight), instead of on every turn, the bonus would just go away the very next turn. This can be fixed by setting the max value instead, but I would want a way to store what the user’s original starting stats were.[/quote]

Yes, you can use player.set\_var(“varname”, value). It would probably be pretty easy to add a per-turn callback, too, if you need that.[/quote]

player.set\_var doesn’t appear to be an actual function. There’s an item.set\_var…

Eh, the idea of having your stats grow at the start of the next day works for me. Also, it avoids the issue where bonuses to str aren’t working properly, since I’d be changing the base value. For now I just have my mod marked to not change the starting stats. Honestly, if I knew how, I would just lock the starting stats during character creation, as the mod isn’t really intended for people to raise their starting stats manually. I figured if I couldn’t do that though, I’d at least make it recognize the stats.

---

<div class="post-metadata">

### Author: ![Agoelia](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/agoelia/32/435_2.png) [@Agoelia](https://discourse.cataclysmdda.org/u/Agoelia)
#### Post date: [June 26, 2015, 2:48pm UTC](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773/14 "2015-06-26T14:48:35Z")

</div>

Does this works with all multiple of 3, or only up to 9?

---

<div class="post-metadata">

### Author: ![Gelly](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@Gelly](https://discourse.cataclysmdda.org/u/Gelly)
#### Post date: [June 30, 2015, 3:00am UTC](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773/15 "2015-06-30T03:00:11Z")

</div>

Not sure if this is intentional so I’m reporting it as a bug.  
The code, as is, resets all stats to baseline (8) if relevant skills are not at sufficient levels to provide a bonus. Mutations that provide a stat bonus (like Perceptive, Dextrous, etc.) aren’t affected(IE: the stat bonus from the mutation is not removed), but any points you put into stats during character creation are wasted.

If this is intentional I’d suggest that you write a notice about it in the mod-description.

---

<div class="post-metadata">

### Author: ![kevin.granade](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/kevin.granade/32/1316_2.png) [@kevin.granade](https://discourse.cataclysmdda.org/u/kevin.granade)
#### Post date: [June 30, 2015, 5:11am UTC](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773/16 "2015-06-30T05:11:39Z")

</div>

Improvements only happen up to skill 9, and the mod makes stats solely based on skills and traits.

---

<div class="post-metadata">

### Author: ![Challtdow](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@Challtdow](https://discourse.cataclysmdda.org/u/Challtdow)
#### Post date: [July 29, 2015, 10:52am UTC](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773/17 "2015-07-29T10:52:23Z")

</div>

I haven’t figured out why yet, but this mod doesn’t seem to do anything when I compile on my Linux machine. I don’t get the daily message about stat increases, and my stats never improve. There aren’t any warning appearing during make either. Has anyone else tried compiling this on Linux?

Chall T. Dow

---

<div class="post-metadata">

### Author: ![troll\_from\_behind](https://avatars.discourse-cdn.com/v4/letter/t/779978/32.png) [@troll\_from\_behind](https://discourse.cataclysmdda.org/u/troll_from_behind)
#### Post date: [July 29, 2015, 10:58am UTC](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773/18 "2015-07-29T10:58:58Z")

</div>

EVEN, if this mod has its quirks, it still makes for far more progressive gameplay than without.  
Which is nice.  
Yeah, one can spend spring only reading and getting high stats (mostly int), but the bad thing is that the zeds evolve and doing something else gets way harder without better gear, that you could have your time looting/crafting.

---

<div class="post-metadata">

### Author: ![Coolthulhu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/coolthulhu/32/2446_2.png) [@Coolthulhu](https://discourse.cataclysmdda.org/u/Coolthulhu)
#### Post date: [July 29, 2015, 3:00pm UTC](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773/19 "2015-07-29T15:00:58Z")

</div>

> [@Challtdow](#):
>
> Has anyone else tried compiling this on Linux?

Yep. The problem was forgetting to compile with LUA=1

---

<div class="post-metadata">

### Author: ![Challtdow](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@Challtdow](https://discourse.cataclysmdda.org/u/Challtdow)
#### Post date: [July 30, 2015, 11:20am UTC](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773/20 "2015-07-30T11:20:00Z")

</div>

Thanks for the help. Since other mods work, I just assumed that lua support was included in the default build options.

Chall T. Dow

[Next page](https://discourse.cataclysmdda.org/t/increases-stats-when-skills-raise/9773.md?page=2)
