PDA

View Full Version : Maximum NPC hitpoints



GeneralChaos
November 15th, 2011, 01:41
Currently in FG there's either the option to use average HP (default) or randomize NPC hp when they're dropped into the tracker.

How hard would it be to add an option for maximum hp?


I'm running a 6 player game and they're steamrolling and dry cleaning everything I throw at them, this seems like a a good way to extend fights slightly.

Trenloe
November 15th, 2011, 07:26
How hard would it be to add an option for maximum hp?

Not too hard - would need to do a few steps:

1) need to change the RHPS code in manager_options.lua to add a Max option :


registerOption("RHPS", false, "House Rules (GM)", "CT: Randomize NPC hit points", "option_entry_radio",
{ labels = "On|Max|Off", values = "on|max|off", optionwidth = 70, default = "off" });

2) code for this in ct.lua -> addNpc function:


-- HP
if sOptRHPS == "on" then
local nRandomHP = StringManager.evalDiceString(NodeManager.get(sourc e, "hd", ""), true);
win.hp.setValue(nRandomHP);
elseif sOptRHPS == "max" Then
-- *** Work out the maximum HP here ***

else
win.hp.setValue(NodeManager.get(source, "hp", 0));
end

Sorry, don't know off hand the best way to get the max result from a dice string. Perhaps copy StringManager.evalDiceString (in manager_string.lua) and create a new function evalDiceStrinMax and change the math.random call to math.max???

GeneralChaos
November 22nd, 2011, 09:55
Spot on, Brilliant! :D

Trenloe
November 23rd, 2011, 00:03
Spot on, Brilliant! :D

No worries, glad it worked for you... :)

Dershem
November 23rd, 2011, 17:56
Did this work for you? It's something I wouldn't mind having an option of. Especially on big bad fights.

madman
November 24th, 2011, 03:17
can someone say Extension!

Chris

GeneralChaos
November 24th, 2011, 11:31
It sure worked.

I don't know how to make an extension, but I've uploaded the modified files here (www.general-chaos.com/MaxNPCHP.zip)

madman
November 24th, 2011, 18:41
I was going to do the extension for this, But i am missing something.

If someone with more code levels could look at it.

ERROR:Script Error: [string "ct/scripts/ct.lua"]:22: attempt to call global 'getNextWindow' (a nil value)


Madman

Trenloe
November 25th, 2011, 03:51
I was going to do the extension for this, But i am missing something.

If someone with more code levels could look at it.

ERROR:Script Error: [string "ct/scripts/ct.lua"]:22: attempt to call global 'getNextWindow' (a nil value)


Madman

Joshuha mentions the issue in post #16 in this thread (http://www.fantasygrounds.com/forums/showthread.php?t=15683) when MurghBpurn was having a similar problem.

Basically, having the "<script name="ct" file="ct/scripts/ct.lua"/>" in extension.xml loads that script (and so executes it's onInit function) too early - before the Combat Tracker has been constructed and so getNextWindow fails (as there's no window to get).

So, in this case, we need to add into the extension the xml file that constructs the CT and references ct.lua - which is ct\ct_host.xml. Then we need to reference that file in extension.xml so that it will use any scripts in the extension first (in our case the modified ct.lua). And, we need to remove the ct.lua script reference from extension.xml. Hope my explanation makes sense?

Attached is the extension with the change made, so you can see what I mean in practice. And, it works fine with just this change.

Thanks Madman for putting this together... :)

2187

madman
February 18th, 2012, 15:47
Changed the text in the extension. Forgot to say Trenloe was the one who came up with the code. Thanks by the way.

Chris