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?
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?