Starfinder Playlist
  1. #1

    Help with new willpower ability save

    So my home brew setting has an ability called willpower whose modifier is the combined sum of both intelligence and wisdom modifiers, so if you had a +3 INT and +1 WIS your WIL is +4. I've got everything set, it shows up in the character sheet, the ability scores appropriately and is intractable. however I've got one problem left I don't know how to resolve. The sheet is expecting base 10 when WIL is base 0. Meaning a will score of 0 is giving a -5 modifier and a +4 is giving a -3 when it should be 0 for 0 and +4 for +4.
    Side note: it would be great if WIL was automatically filled by reading the characters INT and WIS modifiers and summing them together, but I have no clue how to do that.

    Here's the area that is impacted:

    Code:
    function getAbilityScore(rActor, sAbility)
    	if not sAbility then
    		return -1;
    	end
    	local sActorType, nodeActor = ActorManager.getTypeAndNode(rActor);
    	if not nodeActor then
    		return -1;
    	end
    	
    	local nStatScore = -1;
    	
    	local sShort = string.sub(string.lower(sAbility), 1, 3);
    	if sShort == "lev" then
    		if sActorType == "pc" then
    			nStatScore = DB.getValue(nodeActor, "level", 0);
    		else
    			local sHD = StringManager.trim(DB.getValue(nodeActor, "hd", ""));
    			nStatScore = 0;
    			for sLevelSub in sHD:gmatch("(%d+)[dD](%d+)") do
    				nStatScore = nStatScore + (tonumber(sLevelSub) or 0);
    			end
    		end
    	elseif sShort == "prf" then
    		if sActorType == "pc" then
    			nStatScore = DB.getValue(nodeActor, "profbonus", 0);
    		else
    			local nCR = tonumber(DB.getValue(nodeActor, "cr", ""):match("^%d+$")) or 0;
    			nStatScore = math.max(2, math.floor((nCR - 1) / 4) + 2);
    		end
    	elseif sShort == "str" then
    		nStatScore = DB.getValue(nodeActor, "abilities.strength.score", 0);
    	elseif sShort == "dex" then
    		nStatScore = DB.getValue(nodeActor, "abilities.dexterity.score", 0);
    	elseif sShort == "con" then
    		nStatScore = DB.getValue(nodeActor, "abilities.constitution.score", 0);
    	elseif sShort == "int" then
    		nStatScore = DB.getValue(nodeActor, "abilities.intelligence.score", 0);
    	elseif sShort == "wis" then
    		nStatScore = DB.getValue(nodeActor, "abilities.wisdom.score", 0);
    	elseif sShort == "cha" then
    		nStatScore = DB.getValue(nodeActor, "abilities.charisma.score", 0);
    	elseif sShort == "wil" then
    		nStatScore = DB.getValue(nodeActor, "abilities.willpower.score", 0);
    	elseif StringManager.contains(DataCommon.classes, sAbility) then
    		nStatScore = getClassLevel(nodeActor, sAbility);
    	end
    	
    	return nStatScore;
    end
    I figure that because the willpower score is listed among the rest of the scores, that's why this is happening. But I don't know if I can... maybe write a secondary block of the following:

    Code:
    	if sShort == "lev" then
    		if sActorType == "pc" then
    			nStatScore = DB.getValue(nodeActor, "level", 0);
    		else
    			local sHD = StringManager.trim(DB.getValue(nodeActor, "hd", ""));
    			nStatScore = 0;
    			for sLevelSub in sHD:gmatch("(%d+)[dD](%d+)") do
    				nStatScore = nStatScore + (tonumber(sLevelSub) or 0);
    			end
    		end
    	elseif sShort == "prf" then
    		if sActorType == "pc" then
    			nStatScore = DB.getValue(nodeActor, "profbonus", 0);
    		else
    			local nCR = tonumber(DB.getValue(nodeActor, "cr", ""):match("^%d+$")) or 0;
    			nStatScore = math.max(2, math.floor((nCR - 1) / 4) + 2);
    		end
    That could have the right math in it? I don't know if that would break FG or... how to go about getting a separate math rule established. I mean, right now I can just simply remove that whole calculation and just manually do the roll using the modifier control on the bottom left, in game, but I'm trying to make it automatic!

    Thanks in advance for your help!
    Last edited by Pentazer; November 12th, 2019 at 15:53. Reason: Thanking in advance

  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,362
    You don't mention which ruleset you're using, so I can't reliably point to you specifically where the code is.

    For D&D 5E look in the scripts\manager_actor2.lua file - in the getAbilityBonus function - this actually calls getAbilityScore but then does the bonus calculation with the result of getAbilityScore.
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  3. #3
    Oh whoops, you're right. This is D&D 5e.

    Okay I found the block you're talking about... can I just create a new one or something? This block affects all the core abilities but it's just the willpower one that works differently so it's the only one that has unique math. Can I just copy the block, add it below and change it to the following:

    Code:
    function getAbilityBonus(rActor, sAbility)
    	if not sAbility then
    		return 0;
    	end
    	local sActorType, nodeActor = ActorManager.getTypeAndNode(rActor);
    	if not nodeActor then
    		return 0;
    	end
    	
    	local nStatScore = getAbilityScore(rActor, sAbility);
    	if nStatScore < 0 then
    		return 0;
    	end
    	
    	local nStatVal = 0;
    	if StringManager.contains(DataCommon.abilities, sAbility) then
    		nStatVal = math.floor((nStatScore - 0));
    	else
    		nStatVal = nStatScore;
    	end
    	
    	return nStatVal;
    end
    But wouldn't that cause conflicts with the 6 core abilities? Or will FG know that there's two different "Getabilitybonus" codes?

  4. #4
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,362
    You can't just add new code with the same function name, you need to modify the current function only.

    I'd recommend you just put an if statement in the getAbilityBonus function that does different calculations if sAbility is willpower.

    Does your willpower ability have to be in DataCommon.abilities? Because if it isn't, the code is going to automatically do what you want - return nStatScore as the bonus:

    Code:
    	local nStatVal = 0;
    	if StringManager.contains(DataCommon.abilities, sAbility) then
    		nStatVal = math.floor((nStatScore - 10) / 2);
    	else
    		nStatVal = nStatScore;
    	end
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  5. #5
    Hmmm, okay. I'll try that out when I get a chance and see if I can rework things a little.

  6. #6
    Quote Originally Posted by Trenloe View Post
    Does your willpower ability have to be in DataCommon.abilities? Because if it isn't, the code is going to automatically do what you want - return nStatScore as the bonus:
    This fixed it! I see what the problem was. Because the ability was listed on datacommon it was being called as part of the math.floor action, so had the ability modifier. By taking it out of the datacommon.abilities part it's now just rolling as intended. It still says -5 on the sheet but it no longer has any impact on the roll, which is great.

    Is there a way to get it to remove the modifier read out? It's purely cosmetic at this point, but it'd be nice if I could finish polishing off the design.

    Thanks so much!

  7. #7
    Okay so, rethinking this, I found a better approach. By simply making it an untyped skill that you just don't apply proficiency to, it works and saves me the trouble of having to figure out programming way above my experience!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
STAR TREK 2d20

Log in

Log in