PDA

View Full Version : Wound Status on hover



DNH
February 6th, 2008, 16:25
Here's another of my little puzzles and riddles for you! What I am after this time is to be able to append a word or two to an NPC's name in the combat tracker to indicate wound status (ie healthy, light, heavy, DEAD). I already do this manually (for the dead ones anyway) and would like for FG2 to do it for me. Now, I already have all the code to work out the various percentages and so on, but ... erm ... I can't see where to put it!

I want this to show up immediately (as it does with manual changes), so that, say, when a monster drops below one-third hit points, a player can mouse over its token on the map and see its name as something like "Goblin - HEAVY".

Any thoughts?
Thanks.

Foen
February 7th, 2008, 06:39
As a start (presuming you are using a modified d20 ruleset) the triggering code should probably sit in the onValueChanged function of the wounds numbercontrol in the combattracker_entry window class.

I'd then get it to evoke an updateStatus function at the window class level (which you'd put in combattracker_entry.lua) or in the token script file (combattracker_token.lua).

Cheers

Stuart

DNH
February 7th, 2008, 11:22
That did it! Thanks.

onValueChanged of the ct_entry windowclass now also calls an updateWoundStatus function. This function is in the ct_entry script and simply compares hp to wounds to determine the relative wound level and then appends "light", "moderate" etc to the npc's name (or rather, it replaces what is already there). The already-extant nameChanged function takes care of having this happen dynamically and immediately.

Thanks again.

Hamish
February 9th, 2008, 08:59
Sounds like a useful addition. Can you post the code here?

DNH
February 10th, 2008, 20:26
It's really rather simple.

This function needs to be defined in combattracker_entry.lua (the first part is adapted from moon_wizard's player tracker code):


function updateWoundStatus()
local woundstatus = "";
local percent_wounded = 0;
local remaining_hp = hp.getValue() - wounds.getValue();
if hp.getValue() > 0 then
percent_wounded = wounds.getValue() / hp.getValue();
end
if percent_wounded <= 0 then
woundstatus = "Healthy";
elseif percent_wounded <= .33 then
woundstatus = "Light";
elseif percent_wounded <= .66 then
woundstatus = "Moderate";
elseif percent_wounded <= 1 then
if remaining_hp == 0 then
woundstatus = "Disabled";
else
woundstatus = "Heavy";
end
else
if remaining_hp > -10 then
woundstatus = "Dying";
else
woundstatus = "Dead";
end
end

local oldname = name.getValue();
local newname = "";
if string.find(oldname, "-") then
newname = string.gsub(oldname, "- (.*)", "- " .. woundstatus);
else
newname = oldname .. " - " .. woundstatus;
end

name.setValue(newname);
end


This gets called by the line


window.updateWoundStatus();

which needs to be placed here:


- utility_combattracker.xml

--- combattracker_entry windowclass

----- wounds numbercontrol

------- <script> section

--------- function onValueChanged()
... place it just before the closing 'end' statement


And that, I believe, is it. You can, of course, play around with the status divisions, adding in a "Barely Wounded" for under 10% or a "Serious" at 50%. Whatever suits your style and your needs.