PDA

View Full Version : New Developer: How to modify NPC and PC hitpoints from tracker



Nose66
July 10th, 2019, 19:51
I am a brand new FG/Lua developer (although 30 years in Java). I've been hacking around with the GURPs ruleset and wanted to add +/- buttons to the tracker so the GM can quickly increase or decrease the HP for a PC or NPC.

I've gotten pretty far by modifying the ct_host.xml to include:


<buttoncontrol name="dec_hp">
<anchored to="hps" width="11" height="12" position="insidebottomright" offset="-3,0" />
<state icon="field_modifier_minus" />
<script>
function onButtonPress()
local node = window.getDatabaseNode();
Debug.console("Node", node);
local actor = ActorManager.getActorFromCT(node);
Debug.console("Actor:", actor);
if actor.sType == "npc" then
local id = actor.sCreatureNode;
Debug.console("id:", id);
local hp = node.getChild("attributes.hitpoints");
hp.setValue(hp.getValue() - 1);
Debug.console("HP:", hp.getValue());
end
end
</script>
</buttoncontrol>

Yes, I know I am hacking around like crazy, because I don't quite understand the database structure, or how to access data... but it works up to a point. I am able to reduce the HPs, but the combat tracker isn't updating. After pressing the button twice, the debug output looks like this:

Runtime Notice: s'Node' | databasenode = { combattracker.list.id-00007 }
Runtime Notice: s'Actor:' | { s'sType' = s'npc', s'sCreatureNode' = s'combattracker.list.id-00007', s'sCTNode' = s'combattracker.list.id-00007', s'sName' = s'Test' }
Runtime Notice: s'id:' | s'combattracker.list.id-00007'
Runtime Notice: s'HP:' | #4
Runtime Notice: s'Node' | databasenode = { combattracker.list.id-00007 }
Runtime Notice: s'Actor:' | { s'sType' = s'npc', s'sCreatureNode' = s'combattracker.list.id-00007', s'sCTNode' = s'combattracker.list.id-00007', s'sName' = s'Test' }
Runtime Notice: s'id:' | s'combattracker.list.id-00007'
Runtime Notice: s'HP:' | #3

And I have NO IDEA how to get to the character sheet to update the PC hitpoints. I can see the PC character sheet ID (in actor.sCreatureNode):

Runtime Notice: s'Node' | databasenode = { combattracker.list.id-00006 }
Runtime Notice: s'Actor:' | { s'sType' = s'pc', s'sCreatureNode' = s'charsheet.id-00001', s'sCTNode' = s'combattracker.list.id-00006', s'sName' = s'Greeneyes' }
Runtime Notice: s'id:' | s'charsheet.id-00001'
Runtime Notice: s'HP:' | #19

But when I try to get the node from the DB
DB.getValue("charsheet.id-00001")it just returns "nil".

I've been reading posts and dev guides and examples on how to make an extension for days, but this still eludes me ;-)

Can someone point me in the right direction?

Nose66
July 10th, 2019, 22:01
The db.xml entry looks like this:


<combattracker>
<public />
<list>
<public />
<id-00006>
<public />
<active type="number">0</active>
<attributes>
<public />
<dexterity type="number">12</dexterity>
<fatiguepoints type="number">11</fatiguepoints>
<health type="number">10</health>
<hitpoints type="number">14</hitpoints>
<intelligence type="number">10</intelligence>
<move type="string">5</move>
<perception type="number">13</perception>
<strength type="number">11</strength>
<will type="number">10</will>
</attributes>
<combat>
<public />
<block type="number">11</block>
<dodge type="number">8</dodge>
<dr type="string">1</dr>
<meleecombatlist>
<public />
</meleecombatlist>
<parry type="number">11</parry>
<rangedcombatlist>
<public />
</rangedcombatlist>
</combat>
<effects>
<public />
</effects>
<fps type="number">11</fps>
<friendfoe type="string">friend</friendfoe>
<hps type="number">16</hps>
<link type="windowreference">
<class>charsheet</class>
<recordname>charsheet.id-00001</recordname>
</link>
<name type="string">Greeneyes</name>
<reach type="number">0</reach>
<space type="number">1</space>
<speed type="number">5</speed>
<status type="string">Healthy</status>
<token type="token">portrait_id-00001_token</token>
<tokenscale type="number">1</tokenscale>
<tokenvis type="number">0</tokenvis>
<traits>
<public />
<sizemodifier type="string">+0</sizemodifier>
</traits>
</id-00006>
<id-00007>
<public />
<abilities>
<public />
<abilitieslist>
<public />
</abilitieslist>
</abilities>
<active type="number">0</active>
<attributes>
<public />
<basicspeed type="string">6</basicspeed>
<dexterity type="number">10</dexterity>
<fatiguepoints type="number">8</fatiguepoints>
<health type="number">10</health>
<hitpoints type="number">5</hitpoints>
<intelligence type="number">10</intelligence>
<move type="string">6</move>
<perception type="number">8</perception>
<strength type="number">10</strength>
<swing type="string">1d</swing>
<thrust type="string">1d</thrust>
<will type="number">8</will>
</attributes>
<combat>
<public />
<block type="number">0</block>
<dodge type="number">8</dodge>
<dr type="string">1</dr>
<meleecombatlist>
<public />
</meleecombatlist>
<parry type="number">8</parry>
<rangedcombatlist>
<public />
</rangedcombatlist>
</combat>
<effects>
<public />
</effects>
<fps type="number">4</fps>
<friendfoe type="string">foe</friendfoe>
<hps type="number">5</hps>
<isidentified type="number">1</isidentified>
<link type="windowreference">
<class>npc</class>
<recordname></recordname>
</link>
<locked type="number">1</locked>
<name type="string">Test</name>
<nonid_name type="string">Unidentified Creature</nonid_name>
<notes type="formattedtext">
<p></p>
</notes>
<pts type="number">0</pts>
<reach type="number">1</reach>
<sourcelink type="windowreference">
<class>npc</class>
<recordname>npc.id-00001</recordname>
</sourcelink>
<space type="number">1</space>
<speed type="number">6</speed>
<status type="string">Healthy</status>
<token type="token">tokens/Medium/t.png@Letter Tokens</token>
<tokenscale type="number">1</tokenscale>
<tokenvis type="number">1</tokenvis>
<traits>
<public />
<reach type="string">1</reach>
<sizemodifier type="string">0</sizemodifier>
</traits>
</id-00007>
</list>
<round type="number">1</round>
</combattracker>

Nose66
July 10th, 2019, 22:10
Ok, I think I solved it.


<buttoncontrol name="dec_hp">
<anchored to="hps" width="11" height="12" position="insidebottomright" offset="-3,0" />
<state icon="field_modifier_minus" />
<script>
function onButtonPress()
local node = window.getDatabaseNode();
Debug.console("Node", node);
local actor = ActorManager.getActorFromCT(node);
Debug.console("Actor:", actor);
local id = actor.sCreatureNode;
Debug.console("id:", id);
local hp1 = node.getChild("hps");
Debug.console("HP1:", hp1);
local hp2 = hp1.getValue();
Debug.console("HP2:", hp2);
hp1.setValue(hp2 - 1);
end
</script>
</buttoncontrol>

I was editing the wrong value in the structure. Once I changed "hps", updates occurred automatically (though some magic that I still don't understand :)).

damned
July 11th, 2019, 03:41
NPCs only live in the CT so they dont need to update another source.
PCs aso live in charsheet as well as combattracker so there is existing code in there to sync changes between the two sources for specific fields
this is done in ct\scripts\ct_entry.lua in the linkPCFields function

this is a sample from MoreCore - it sets up links between 6 new fields that MoreCore adds.



function linkPCFields()
local nodeChar = link.getTargetDatabaseNode();
-- Debug.console("linkPCFields:");
-- Debug.console(nodeChar);
if nodeChar then
name.setLink(nodeChar.createChild("name", "string"), true);
health.setLink(nodeChar.createChild("health", "number"), false);
defence.setLink(nodeChar.createChild("defence", "number"), false);
fieldthree.setLink(nodeChar.createChild("wounds", "number"), false);
initresult.setLink(nodeChar.createChild("initresult", "number"));
atk.setLink(nodeChar.createChild("attacks", "string"), true);
fieldfour.setLink(nodeChar.createChild("four", "number"), false);
fieldfive.setLink(nodeChar.createChild("five", "number"), false);
end
end