PDA

View Full Version : CoreRPG Combat Tracker



damned
September 22nd, 2014, 14:27
Righto... I probably shouldnt even be looking at this... but I am...

Im looking at the CoreRPG Combat Tracker.

I would like some pointers on 2 things (initially...):

1. I want to grab the Initiative Value (char.init) from the Character or Personality and populate the Order field and then let the autosort work.
2. An extended option would be to allow the Character (own entry only) or the GM (all entries) double click the Order field and re-roll Initiative and then let step 1 above do its thing.

Any suggestions, tips, (simple) examples?

regards
Damian

damned
September 22nd, 2014, 16:11
so CoreRPG is storing something like this:



<id-00002>
....
<char>
<public />
<init type="number">59</init>
</char>
....
<initresult type="number">3</initresult>
....


init is the Character Sheet Initiative
initresult is the CoreRPG field for the initiative (Order) in the Combat Tracker

And there will be multiple actors in the Combat Tracker...
So I need to first reference each Actor
> get the DB value char.int
> write it to DB value initresult

Im trying a function onInit() and even when I specify the node its not writing...
So im obviously messing this up...

But I seem to be doing it wrong...

Trenloe
September 22nd, 2014, 16:27
And there will be multiple actors in the Combat Tracker...
So I need to first reference each Actor
> get the DB value char.int
> write it to DB value initresult

Im trying a function onInit() and even when I specify the node its not writing...
So im obviously messing this up...
Where's you're onInit() function?

Are you writing the value in the combat tracker record, not the charsheet record?

damned
September 22nd, 2014, 16:51
from post #2 above that is in \ct\ct_host.xml
i tried to add a function in the script section of:
<number_ct_crosslink name="initresult">

whilst doing the dishes I had a thought... maybe Im doing this the hard way... and I tried to change the initresult entries to char.init (3 files ct_host.xml, ct_client.xml, manager_combat2.lua) instead of reading char.init and writing to initresult but that didnt seem to work either... :(

damned
September 22nd, 2014, 17:00
and yes - this is from thecombattracker records in the db.xml so above post is off track... except that there IS a char.init record also in combattracker... wonder if that means that at some point I did write something from the CT back to char.init in the CT?

Trenloe
September 22nd, 2014, 17:25
It's more than likely that all of the info you're looking for is not available during the onInit() function of a specific control.

The best way to do this (taking char.init from the charsheet actor as they are added to the CT) is to do this in the addPC code in the combat managers. The quick way to do it would be to modify the addPC function in scripts\manager_combat.lua. But the best way would be to use the fCustomAddPC functionality in scripts\manager_combat.lua - which is specifically there for writing a custom addPC function:


Copy scripts\manager_combat2.lua from CoreRPG to your own ruleset.
Activate this script in your new ruleset by adding <script name="CombatManager2" file="scripts/manager_combat2.lua" /> to base.xml in your new ruleset.
From the CoreRPG scripts\manager_combat.lua copy the addPC function to the scripts\manager_combat2.lua file in your ruleset.
In the addPC function you've just copied to scripts\manager_combat2.lua file in your ruleset, remove the 3 lines at the beginning of the addPC function beginning with if fCustomAddPC then
Add CombatManager.setCustomAddNPC(addNPC); to the onInit function in the scripts\manager_combat2.lua file in your ruleset.

This will now result in the addPC function in scripts\manager_combat2.lua file in your ruleset, all without making any changes to the base CoreRPG scripts\manager_combat.lua file.

Now you can do your custom code in the addPC function in the scripts\manager_combat2.lua file in your ruleset.

Within that function you have access to the databasenode of the entry in the combat tracker (nodeEntry) and the charsheet databasenode (nodePC). So you can access char.init from nodePC and set the value in initresult through entryNode.

damned
September 23rd, 2014, 01:07
thank you very much for your detailed response.

in Point 4. we are referencing addNPC but the function we copied over is addPC - do I use addPC, do i add another function addNPC or should this work anyway?

Trenloe
September 23rd, 2014, 01:17
in Point 4. we are referencing addNPC but the function we copied over is addPC - do I use addPC, do i add another function addNPC or should this work anyway?
Sorry, that was thinking ahead of my myself. Everything I mentioned above should be addPC, not addNPC.

But... you'll need to do it for addNPC soon... ;)

damned
September 23rd, 2014, 01:29
thanks :)

Any hints for this error message?
Script Error: [string "scripts/manager_combat2.lua"]:28: createChild: Invalid argument 1
Line 28 is in Bold. It doesnt like CT_LIST?


function addPC(nodePC)
-- if fCustomAddPC then
-- return fCustomAddPC(nodePC);
-- end

-- Parameter validation
-- Debug.console("This far?");
if not nodePC then
return;
end

-- Create a new combat tracker window
local nodeEntry = DB.createChild(CT_LIST);
if not nodeEntry then
return;
end

damned
September 23rd, 2014, 01:34
it looks like that was caused by /scripts/manager_combat.lua not loading....
my understanding is I shouldnt be loading this in my extension - you are suggesting to allow CoreRPG to run that...?
if I specify it in extension base.xml I dont get that error... hmmm... I may be doing something wrong.

Trenloe
September 23rd, 2014, 01:36
it looks like that was caused by /scripts/manager_combat.lua not loading....
my understanding is I shouldnt be loading this in my extension - you are suggesting to allow CoreRPG to run that...?
if I specify it in extension base.xml I dont get that error... hmmm... I may be doing something wrong.
No, don't load manager_combat.lua in your extension. The whole reason you're using the customer addPC in manager_combat2.lua is to avoid having more CoreRPG base code in your extension - and so help it be more future proof.

Change CT_LIST in post #9 above to be "combattracker.list".

damned
September 23rd, 2014, 03:39
Change CT_LIST in post #9 above to be "combattracker.list".

Where did you get combattracker.list from?
Its defined as:
CT_LIST = "combattracker.list";
in manager_combat.lua so its kinda the same thing... but manager_combat2.lua is not getting any value(s)...?

it returns:

Script Error: [string "scripts/manager_combat2.lua"]:28: attempt to index global 'combattracker' (a nil value)

Same line... but different error:

Script Error: [string "scripts/manager_combat2.lua"]:28: createChild: Invalid argument 1

Trenloe
September 23rd, 2014, 03:58
Include the quotes around "combattracker.list" - it's referring to the name of a node in the database so you need the quotes.

damned
September 23rd, 2014, 04:30
freakydeak! I didnt even try that!
that works beautifully... so Im guessing I now should look in the manager_combat.lua for the Next Round button and copy that over and also reapply the INIT values then as I usually leave my characters in the CT for the whole session...

and then replicate for NPCs....

Trenloe
September 23rd, 2014, 04:37
To be clear - manager_combat2.lua is not replacing manager_combat.lua - it is extending it, but only through specific custom handlers. You'll only need to copy onTurnEnd to manager_combat2.lua and register it if you plan to modify it.

Look in the 3.5e version of manager_combat2.lua for some examples of these custom functions: sortfunc, onDrop, addNPC, getNPCSpaceReach, onTurnStart, onTurnEnd and resetInit.

damned
September 23rd, 2014, 05:16
To be clear - manager_combat2.lua is not replacing manager_combat.lua - it is extending it, but only through specific custom handlers. You'll only need to copy onTurnEnd to manager_combat2.lua and register it if you plan to modify it.

understood


Look in the 3.5e version of manager_combat2.lua for some examples of these custom functions: sortfunc, onDrop, addNPC, getNPCSpaceReach, onTurnStart, onTurnEnd and resetInit.

i want a function that runs on ROUND start or end rather than on an individuals turn start/end. i will check those out.

Trenloe
September 23rd, 2014, 05:32
i want a function that runs on ROUND start or end rather than on an individuals turn start/end. i will check those out.
There's an onRoundStart custom function as well. Look in the manager_combat2.lua file in your favourite ruleset (C&C).

Valarian
September 23rd, 2014, 06:47
You need to specify it in the base.xml to override the CoreROG version, unless its referenced directly in a script tag. You can just copy the line from the CoreRPG base file.

Fate Core has a customised combat tracker. Could look at that. The initiative could just be done as a linked field if it's on the character sheet.

Trenloe
September 23rd, 2014, 07:00
You need to specify it in the base.xml to override the CoreROG version, unless its referenced directly in a script tag. You can just copy the line from the CoreRPG base file.
Thanks for spotting that - I didn't include that in the steps in post #6.

damned
September 23rd, 2014, 07:49
Hi Valarian - i did include manager_combat2.lua in my base.xml - is that what you are referring to?
also - the INIT is on the character (and NPC) sheets - really at this stage I just want the INIT and Order by INIT - at the moment I have the PCs populating INIT into initresult thanks to Trenloe's patience...
will look at C&C ruleset as that has an option to recalc initiative at the start of every round - I would like it to re-read the initiative and adjust if required at the start of the round.
it does seem like an easier option - taking the value straight from the character sheet/db but as it is on its way now I think I will continue this way. I will check out Fate Core too - thanks.

damned
September 23rd, 2014, 15:25
Hi Trenloe - what things am I looking at for extending this to include NPCs?
Am i duplicating the function addPC(nodePC) and modifying or am i sticking with that function and doing some if/then?

Im getting this error:
Script Error: [string "scripts/manager_combat2.lua"]:38: attempt to call field 'getNodeName' (a nil value)

From this statement (38 in red):

-- Set up the CT specific information
DB.setValue(nodeEntry, "link", "windowreference", "npc", nodeNPC.getNodeName());
DB.setValue(nodeEntry, "friendfoe", "string", "friend");
nCharInit = DB.getValue(nodeNPC, "char.init", "number", "");
Debug.console("nCharInit");
DB.setValue(nodeEntry, "initresult", "number", nCharInit);


looking at db.xml I see a problem... there is no recordname in the NPCs in the combattracker section
<id-00012>
<public />
<active type="number">0</active>
<effects>
<public />
</effects>
<initresult type="number">0</initresult>
<link type="windowreference">
<class>npc</class>
<recordname></recordname>
</link>
<reach type="number">1</reach>
<space type="number">1</space>
<token type="token"></token>
<tokenscale type="number">1</tokenscale>
<tokenvis type="number">0</tokenvis>
</id-00012>


when i look at the characters:
<id-00007>
<public />
<active type="number">0</active>
<effects>
<public />
</effects>
<friendfoe type="string">friend</friendfoe>
<initresult type="number">43</initresult>
<link type="windowreference">
<class>charsheet</class>
<recordname>charsheet.id-00002</recordname>
</link>
<name type="string">Eavan Wainright</name>
<reach type="number">1</reach>
<space type="number">1</space>
<token type="token">Tokens/man062.png@Pulp Photo Tokens - Public Domain Images</token>
<tokenscale type="number">1</tokenscale>
<tokenvis type="number">0</tokenvis>
</id-00007>

Whats happening? Whats not happening is probably more accurate? Somewhere before I query that data its not getting set.

Trenloe
September 23rd, 2014, 17:21
Look at the reason for the error. This is what you need to do - don't jump ahead and try to look at the database after the event.

The error is attempt to call field 'getNodeName' (a nil value) This means that there is nothing/nil/zip/nada in relation to the getNodeName function call. This function is getting called with nodeNPC.getNodeName() which is correct syntax, so the only think that could be nil at this point is nodeNPC. That is the reason for your error - nodeNPC doesn't exist or isn't a databasenode.

Anyway, I'd not recommend doing what you're trying to do. Instead you should be copying the addNPC code from manager_combat.lua into manager_combat2.lua (as I eluded to earlier). But, when you look at this code, it gets a little more complicated - addNPC doesn't do much, the main code is in addNPCHelper. So:

copy both of these functions (addNPC *and* addNPCHelper) to your manager_combat2.lua file
remove the 3 lines beginning with if fCustomAddNPC then in addNPC in your manager_combat2.lua file
add CombatManager.setCustomAddNPC(addNPC); to onInit in manager_combat2.lua to register the custom addNPC function.
add CT_LIST = "combattracker.list"; at the top of the manager_combat2.lua (before onInit).

Then, do any of your custom code in the addNPCHelper function in manager_combat2.lua.

damned
September 24th, 2014, 00:38
I was torn between the two methods and I did try them both initially. I went back to the one above as the current addNPC from the manager_combat.lua was so much more complex - has lots more options...

anyways Ive grabbed the addNPC and addNPCHelper into my manager_combat2.lua
i stripped a bunch of code to do with renaming/numbering (for 2 reasons - i dont have those options and they were erroring and failing...) and some code on size and reach which was failing as I removed those options from the NPC character sheet so they will always be NIL...
the stripped down code is allowing NPCs to add to CT again
Ive checked both the existing code and the stripped code and I cant find any reference to INIT in there... so my NPCs are adding but without any INIT.

So Ive added the following code -

nNPCInit = DB.getValue(nodeNPC, "char.init", "number", "");
Debug.console("nNPCInit");
DB.setValue(nodeEntry, "initresult", "number", nNPCInit);

and it seems to be working.

Other than tracking on battlemaps - do you see any issue on removing the random numbering of NPC entries? (eg: Mercenary 2, Mercenary 13, Mercenary 6).

Trenloe
September 24th, 2014, 00:50
Other than tracking on battlemaps - do you see any issue on removing the random numbering of NPC entries? (eg: Mercenary 2, Mercenary 13, Mercenary 6).
I'd recommend including this now if you can - it's only enabling the options in the campaign options entry and leaving the code in addNPCHelper. I can pretty much guarantee very soon you'll want to have the NPC names unique - even if just to avoid confusion of identifying which token belongs to which entry on the combat tracker, but also if you introduce targeting, effects, etc., etc.. I don't think there is any specific functionality it will break, but having each NPC uniquely identified will avoid a lot of confusion in your game.

damned
September 24th, 2014, 01:28
Runtime Notice: s'sEntryName = Eavan Wainright'
Script Error: [string "scripts/manager_combat2.lua"]:151: attempt to call global 'stripCreatureNumber' (a nil value)

I think I know why I get the error... if I put the whole code - bar the reach and size - back in I get the above. The problem seems to be that the DB.getValue is NOT grabbing the NPC - it is grabbing the name of the FIRST EXISTING entry in the Combat Tracker... if there isnt one in there it adds the NPC successfully - if there is an existing PC or NPC it returns the name of the first one and errors and does not proceed... line 151 in red.

for _,v in pairs(DB.getChildren(CT_LIST)) do
local sEntryName = DB.getValue(v, "name", "");
Debug.console("sEntryName = " .. sEntryName);
local sTemp, sNumber = stripCreatureNumber(sEntryName);
if sTemp == sNameLocal then
nodeLastMatch = v;

local nNumber = tonumber(sNumber) or 0;
if nNumber > 0 then
nNameHigh = math.max(nNameHigh, nNumber);
table.insert(aMatchesWithNumber, v);
else
table.insert(aMatchesToNumber, v);
end
end

Trenloe
September 24th, 2014, 01:34
Use: CombatManager.stripCreatureNumber(sEntryName); instead of stripCreatureNumber(sEntryName);

The stripCreatureNumber function is in the manager_combat.lua file. Leave it there, it's fine where it is. You just need to reference the package name CombatManager. in front of any function you're using from manager_combat.lua if you're not making the call from within the same file.

damned
September 24th, 2014, 01:56
Great - that was the answer to the nextissue too! When I turned on Random numbering in the Options it also failed until adding that to the randomName function. i better see what else is doing that...