# Modifying Stats For Skills

**URL:** https://discourse.cataclysmdda.org/t/modifying-stats-for-skills/14219
**Category:** The Toolbox
**Created:** [September 10, 2017, 8:04pm UTC](https://discourse.cataclysmdda.org/t/modifying-stats-for-skills/14219 "2017-09-10T20:04:27Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![InaneOctopus](https://avatars.discourse-cdn.com/v4/letter/i/c5a1d2/32.png) [@InaneOctopus](https://discourse.cataclysmdda.org/u/InaneOctopus)
#### Post date: [September 10, 2017, 8:04pm UTC](https://discourse.cataclysmdda.org/t/modifying-stats-for-skills/14219/1 "2017-09-10T20:04:27Z")

</div>

Hello! I’m having difficulty changing how StatsforSkills is working and I’d appreciate some guidance.

I’m currently running the MacOS tileset. I’ve tried going into the file tree and opening the main.lua file in the StatsforSkills folder and making modifications there. I haven’t gotten any results yet, is that where I should be making the change or is there something else I need to do?

I’m trying to increase the rate at which you gain stats by tweaking the math a little more to my liking but I’m not seeing the expected results on my existing character or on any new characters. I also changed the welcome message for new characters to test if anything was even happening and guess what, nothing changed!

Thanks for any help!

---

<div class="post-metadata">

### Author: ![Zhilkin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zhilkin/32/3749_2.png) [@Zhilkin](https://discourse.cataclysmdda.org/u/Zhilkin)
#### Post date: [September 10, 2017, 9:05pm UTC](https://discourse.cataclysmdda.org/t/modifying-stats-for-skills/14219/2 "2017-09-10T21:05:59Z")

</div>

Do you have this lua mod enabled in your world? Is your game version lua-compatible?

Can you provide the updated code of main.lua?

---

<div class="post-metadata">

### Author: ![InaneOctopus](https://avatars.discourse-cdn.com/v4/letter/i/c5a1d2/32.png) [@InaneOctopus](https://discourse.cataclysmdda.org/u/InaneOctopus)
#### Post date: [September 10, 2017, 9:14pm UTC](https://discourse.cataclysmdda.org/t/modifying-stats-for-skills/14219/3 "2017-09-10T21:14:42Z")

</div>

The game world has StatsforSkills enabled and it works normally, so I assume lua is enabled.

[code]–Increasing stats by skill  
local MOD = {}

local version = 2

local str\_skills = { “mechanics”, “swimming”, “bashing”, “cutting”, “melee”, “throw” }  
local dex\_skills = { “driving”, “survival”, “tailor”, “traps”, “dodge”, “stabbing”, “unarmed” }  
local int\_skills = { “barter”, “computer”, “cooking”, “electronics”, “fabrication”, “firstaid”, “speech” }  
local per\_skills = { “archery”, “gun”, “launcher”, “pistol”, “rifle”, “shotgun”, “smg” }

mods[“StatsThroughSkills”] = MOD

function MOD.on\_new\_player\_created()  
game.add\_msg(“New player starting with TESTEST”)  
player:set\_value(“StatsThroughSkills”, tostring(version))  
calculate\_bonuses()  
end

function MOD.on\_skill\_increased()  
calculate\_bonuses()  
end

function calculate\_bonuses()  
game.add\_msg(“Calculating new stats based off skills”)

```
handle_previous_version()

local prev_str = player.str_max
local prev_dex = player.dex_max
local prev_int = player.int_max
local prev_per = player.per_max

remove_existing_bonuses()

local str_bonus = calc_bonus(str_skills)
local dex_bonus = calc_bonus(dex_skills)
local int_bonus = calc_bonus(int_skills)
local per_bonus = calc_bonus(per_skills)

player:set_value("str_bonus", tostring(str_bonus))
player:set_value("dex_bonus", tostring(dex_bonus))
player:set_value("int_bonus", tostring(int_bonus))
player:set_value("per_bonus", tostring(per_bonus))

player.str_max = player.str_max + str_bonus
player.dex_max = player.dex_max + dex_bonus
player.int_max = player.int_max + int_bonus
player.per_max = player.per_max + per_bonus

print_results(player.str_max,"Str",prev_str)
print_results(player.dex_max,"Dex",prev_dex)
print_results(player.int_max,"Int",prev_int)
print_results(player.per_max,"Per",prev_per)

player:recalc_hp()

```

end

function remove\_existing\_bonuses()  
local str\_bonus = tonumber(player:get\_value(“str\_bonus”))  
local dex\_bonus = tonumber(player:get\_value(“dex\_bonus”))  
local int\_bonus = tonumber(player:get\_value(“int\_bonus”))  
local per\_bonus = tonumber(player:get\_value(“per\_bonus”))

```
if(str_bonus) then player.str_max = player.str_max - str_bonus end
if(dex_bonus) then player.dex_max = player.dex_max - dex_bonus end
if(int_bonus) then player.int_max = player.int_max - int_bonus end
if(per_bonus) then player.per_max = player.per_max - per_bonus end

```

end

function calc\_bonus(skills\_set)  
local skill\_total = 0  
for \_,s in ipairs(skills\_set) do  
skill\_total = skill\_total + player:get\_skill\_level(skill\_id(s))  
game.add\_msg("Skill total for “…tostring(skills\_set)…” is "…tostring(skill\_total))  
end  
– Edited value ‘2.46’ to ‘1.5’ to achieve faster curve  
return (skill\_total \> 3 and math.floor(math.pow((skill\_total - 3), (1 / 1.5))) or 0)  
end

function print\_results(cur\_stat,stat,prev\_stat)  
if (prev\_stat \< cur\_stat) then  
game.add\_msg("Raising “…stat…” to "…tostring(cur\_stat))  
elseif (prev\_stat \> cur\_stat) then  
game.add\_msg("Lowering “…stat…” to "…tostring(cur\_stat))  
end  
end

function handle\_previous\_version()  
local loaded\_version = tonumber(player:get\_value(“StatsThroughSkills”))  
local is\_older\_than\_day = game.get\_calendar\_turn():days() \>= 1  
if( (not loaded\_version or loaded\_version \< 2) and is\_older\_than\_day) then --handle upgrading from original StatsThroughSkills to version 2  
game.add\_msg(“Migrating from version 1”)

```
    local str_bonus = get_stat_bonus_for_skills_version_1(str_skills)
    local dex_bonus = get_stat_bonus_for_skills_version_1(dex_skills)
    local int_bonus = get_stat_bonus_for_skills_version_1(int_skills)
    local per_bonus = get_stat_bonus_for_skills_version_1(per_skills)

    player.str_max = player.str_max - str_bonus
    player.dex_max = player.dex_max - dex_bonus
    player.int_max = player.int_max - int_bonus
    player.per_max = player.per_max - per_bonus

    player:set_value("StatsThroughSkills", tostring(2))
end

```

end

function get\_stat\_bonus\_for\_skills\_version\_1(skill\_set)  
local total\_bonus = 0  
for \_,v in ipairs(skill\_set) do  
local skill\_level = player:get\_skill\_level(skill\_id(v))  
local stat\_bonus = 0  
if (skill\_level / 3 \< 3) then  
stat\_bonus = stat\_bonus + skill\_level / 3  
else  
stat\_bonus = stat\_bonus + 3  
end  
total\_bonus = total\_bonus + math.floor(stat\_bonus)  
end  
return total\_bonus  
end[/code]

The two changes are on lines 13 where I alter the new character message, and line 77 where I change a value from 2.46 to 1.5

---

<div class="post-metadata">

### Author: ![Zhilkin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zhilkin/32/3749_2.png) [@Zhilkin](https://discourse.cataclysmdda.org/u/Zhilkin)
#### Post date: [September 10, 2017, 9:58pm UTC](https://discourse.cataclysmdda.org/t/modifying-stats-for-skills/14219/4 "2017-09-10T21:58:26Z")

</div>

This code is working fine for me on latest experimental.

---

<div class="post-metadata">

### Author: ![Theundyingcode](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/theundyingcode/32/500_2.png) [@Theundyingcode](https://discourse.cataclysmdda.org/u/Theundyingcode)
#### Post date: [September 10, 2017, 9:59pm UTC](https://discourse.cataclysmdda.org/t/modifying-stats-for-skills/14219/5 "2017-09-10T21:59:22Z")

</div>

It should work, I change the math on mine completely so it it didn’t do much until I got really high level skills (curves the other way) to stop me reading everything to lv.2 and becoming OP. I even did it in the middle of a game. It didn’t take effect until I leveled up a skill but than it dropped all the stats to match.

---

<div class="post-metadata">

### Author: ![Zhilkin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zhilkin/32/3749_2.png) [@Zhilkin](https://discourse.cataclysmdda.org/u/Zhilkin)
#### Post date: [September 11, 2017, 1:58am UTC](https://discourse.cataclysmdda.org/t/modifying-stats-for-skills/14219/6 "2017-09-11T01:58:15Z")

</div>

> [@Theundyingcode](#):
>
> It didn’t take effect until I leveled up a skill but than it dropped all the stats to match.

That is expected - Lua callback functions work at certain moment of time in game.

---

<div class="post-metadata">

### Author: ![Theundyingcode](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/theundyingcode/32/500_2.png) [@Theundyingcode](https://discourse.cataclysmdda.org/u/Theundyingcode)
#### Post date: [September 11, 2017, 2:25am UTC](https://discourse.cataclysmdda.org/t/modifying-stats-for-skills/14219/7 "2017-09-11T02:25:00Z")

</div>

> [@Zhilkin](#):
>
> [quote=“Theundyingcode, post:5, topic:14219”]It didn’t take effect until I leveled up a skill but than it dropped all the stats to match.

That is expected - Lua callback functions work at certain moment of time in game.[/quote]

That’s why I mentioned it, InaneOctopus was asking for help with working code so I thought that was likely the problem. √(-.-)/

---

<div class="post-metadata">

### Author: ![InaneOctopus](https://avatars.discourse-cdn.com/v4/letter/i/c5a1d2/32.png) [@InaneOctopus](https://discourse.cataclysmdda.org/u/InaneOctopus)
#### Post date: [September 12, 2017, 2:18am UTC](https://discourse.cataclysmdda.org/t/modifying-stats-for-skills/14219/8 "2017-09-12T02:18:59Z")

</div>

I really appreciate the responses, thanks everyone! The real problem was a little bit embarassing. The file I was modifying was maybe an old version or installation, just unzipped in some document folder. I was finding what I thought was the right file by opening finder and searching for StatsthroughSkills. Turns out that when I went into my applications folder and dug into the package from there I was able to modify the right file and everything started working perfectly.

Wah wah waaaaaaah.
