Colin Posted August 13, 2022 Share Posted August 13, 2022 I'd like to reset character skill levels and xp through lua. I have found the function LoseLevel, but this would require lots of checking current level and various other wasteful calls. Is it possible to do a full reset of skill levels? Or will I need to build a custom function to run through all skills. -Colin Link to comment Share on other sites More sharing options...
Colin Posted August 13, 2022 Author Share Posted August 13, 2022 (edited) Temporarily I have written the following function to perform more or less what I want. --// --// Clear all skills and xp --// Author: Colin J.D. Stewart | Updated: 14.08.2022 --// local function clearSkillLevels(player) local pl = PerkFactory.PerkList; local xp = player:getXp(); for i = 0, pl:size()-1 do local info = pl:get(i); local pk = info:getType(); local curLevel = player:getPerkLevel(pk); if curLevel > 0 then for i = curLevel, 0, -1 do player:LoseLevel(pk); end; end; xp:setXPToLevel(pk, player:getPerkLevel(pk)); end; end; If there is no better way, then if someone can point me in right direction to also clear xp boosts for each skill. Thanks. Edited August 13, 2022 by Colin spoiler bbcode ruins code formatting Link to comment Share on other sites More sharing options...
Hugo Qwerty Posted August 13, 2022 Share Posted August 13, 2022 Maybe try: setPerkLevelDebug(PerkFactory.Perk perk, int int1) I don't know if it works, but its name suggests it will do what you want. There's also: player:level0(PerkFactory.Perk perk) https://zomboid-javadoc.com/41.65/zombie/characters/IsoGameCharacter.html Colin 1 Link to comment Share on other sites More sharing options...
Colin Posted August 14, 2022 Author Share Posted August 14, 2022 Great, level0 is ideal if curLevel > 0 then player:level0(pk); end; However, it still does not clear the xp boosts, the api docs don't have much info filled unfortunately.... Once I get home later tonight I will check through all the apis for what I need. Thanks. Link to comment Share on other sites More sharing options...
Tchernobill Posted August 14, 2022 Share Posted August 14, 2022 (edited) CharacterSave mod does it. Beware it is easy to confuse XpBoost and XpMultiplier. The first is related to profession and traits. --remove all previous profession, traits [..] (incldues XpBoost removal) character:getDescriptor():setProfession("unemployed"); character:getTraits():clear(); --alternative selective XpBoost removal (not tested) character:getXp():setPerkBoost(perk, 0) The second is related to skill books. --add player:getXp():addXpMultiplier(perk, multiplier, levelMin, levelMax); --remove player:getXp():getMultiplierMap():remove(perk) --alternative remove functional equivalent with current vanilla state (not tested) player:getXp():addXpMultiplier(perk, 1, levelMin, levelMax); Edited August 14, 2022 by Tchernobill add XpBoost removal exemple. Colin 1 Link to comment Share on other sites More sharing options...
Colin Posted August 14, 2022 Author Share Posted August 14, 2022 (edited) Thanks guys, this will do the job for now --// --// Clear all skills and xp --// Author: Colin J.D. Stewart | Updated: 15.08.2022 --// local function clearSkills(player) local pl = PerkFactory.PerkList; local xp = player:getXp(); for i = 0, pl:size()-1 do local pk = pl:get(i):getType(); player:level0(pk); --// Thanks Hugo Qwerty xp:setXPToLevel(pk, player:getPerkLevel(pk)); --//Thanks Tchernobill xp:setPerkBoost(pk, 0); xp:getMultiplierMap():remove(pk); end; end; Edited August 14, 2022 by Colin Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now