Skip to content

Commit

Permalink
updates to support more diverse hd field content
Browse files Browse the repository at this point in the history
  • Loading branch information
bmos committed Jul 18, 2023
1 parent 10dbce0 commit 2dfdb7d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions extension.xml
Expand Up @@ -6,7 +6,7 @@
<properties>
<loadorder>60</loadorder>
<name>Feature: Live Hitpoints</name>
<version>2.11</version>
<version>2.12</version>
<author>bmos (Wil Thieme)</author>
<description>This extension automates changes to hitpoints based on an ability score.</description>
<ruleset>
Expand All @@ -22,7 +22,7 @@
</luacheck>
</properties>

<announcement text="https://github.com/bmos/FG-PFRPG-Live-Hitpoints-from-Constitution\rPFRPG Live Hitpoints v2.11-hotfix.1:\rThis extension automates changes to hitpoints based on an ability score." icon="BandageLogo" font="emotefont" />
<announcement text="https://github.com/bmos/FG-PFRPG-Live-Hitpoints-from-Constitution\rPFRPG Live Hitpoints v2.12:\rThis extension automates changes to hitpoints based on an ability score." icon="BandageLogo" font="emotefont" />

<base>
<!-- Graphics -->
Expand Down
16 changes: 12 additions & 4 deletions scripts/livehitpoints_npc.lua
Expand Up @@ -29,7 +29,7 @@ end
-- It alerts the user and suggests that they report it on the bug report thread.
local function reportHdErrors(nodeNPC, sHd)
local sNpcName = DB.getValue(nodeNPC, 'name', '')
local sHdErrorEnd = sHd:find('%)', 1) or sHd:find('%;', 1) or sHd:find('planar', 1) or sHd:find('profane', 1) or sHd:find('sacred', 1)
local sHdErrorEnd = sHd:find('planar', 1) or sHd:find('profane', 1) or sHd:find('sacred', 1)
if not sHdErrorEnd or DB.getValue(nodeNPC, 'erroralerted') == 1 or sNpcName == '' then return end

if DataCommon.isPFRPG() then
Expand All @@ -43,7 +43,15 @@ end
--- This function finds the total number of HD for the NPC.
-- luacheck: globals processHd
function processHd(nodeNPC)
local sHd = DB.getValue(nodeNPC, 'hd', ''):gsub('%d+%s-HD;', ''):gsub(';.+', '')
local sHDField = DB.getValue(nodeNPC, "hd", ""):gsub('%d+%s-HD;', '')
local nHDFieldSemiColon = sHDField:find(";")
local sHd
if nHDFieldSemiColon then
sHd = StringManager.trim(sHDField:sub(1, nHDFieldSemiColon - 1))
else
sHd = StringManager.trim(sHDField)
end

reportHdErrors(nodeNPC, sHd)

sHd = sHd .. '+' -- ending plus
Expand All @@ -63,8 +71,8 @@ function processHd(nodeNPC)
local nHdEndPos = string.find(v, 'd', 1)
local nHd = tonumber(string.sub(v, 1, nHdEndPos - 1))
if nHd then nHdCount = nHdCount + nHd end
elseif string.match(v, '%d+', 1) then
nAbilHp = nAbilHp + tonumber(v)
elseif string.match(v, '%d+') then
nAbilHp = nAbilHp + tonumber(string.match(v, '(%d+)'))
end
end

Expand Down

0 comments on commit 2dfdb7d

Please sign in to comment.