Modifying Stats For Skills

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!

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?

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

This code is working fine for me on latest experimental.

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.

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

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. √(-.-)/

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.