PDA

View Full Version : Question R.E. accessing character sheet info



Stv
January 4th, 2020, 21:47
I'm 'trying' to work on a small extension to automate the rogues Reliable Talent feat.
I've got most of the mechanics of it sorted, but I'm really struggling to find how to actually find if the players character has the feat on their character sheet in the 1st place.

Can anyone give me a shove in the right direction or a short code snippet of how to do this?

Thanks, Steve.

Moon Wizard
January 5th, 2020, 00:15
There's an example of something similar in CharManager script in the 5E ruleset (campaign/scripts/manager_char.lua).



if hasFeature(nodeChar, FEATURE_UNARMORED_DEFENSE) then
....
end


So, you could probably re-use that function, but you need to make sure you have the character's database node.



if hasFeature(nodeChar, "reliable talent") then
....
end


Regards,
JPG

Stv
January 5th, 2020, 00:22
I'll give it a shot, thanks for the reply :)

Moon Wizard
January 5th, 2020, 00:25
Actually, the example running from your own script would be below, since you need to call a function in another script. Just noticed I forgot that.



if CharManager.hasFeature(nodeChar, "reliable talent") then
....
end


Cheers,
JPG

Stv
January 5th, 2020, 20:00
OK, I'm about to show my total ignorance of how the underlying Lua/Db referencing works in Fantasy Grounds by explaining how I'm *thinking* I should be doing this.

In the onRoll function of manager_action_skill.lua, before the Comm.deliverChatMessage(rMessage) is actioned, I would like to check if the d20 die roll is <10, if so, change it to 10 then action the chatmessage.
BUT.....I 1st need to check if the character that rolled the dice has the reliable talent function. I am still puzzled how to do this, as I can't get any coding to get the characters node from the Db to work from within the onRoll function.
I'm sure I must be coming at this entirely the wrong way.

Thanks in advance for any more pointers you can give me

Trenloe
January 5th, 2020, 20:26
... I can't get any coding to get the characters node from the Db to work from within the onRoll function.
Most actions have record variables (actually LUA tables) that contain various pieces of information for an "actor" - where an actor is usually the source or the target of the action.

There is a very useful global script called ActorManager that has various helper functions to get info out of an actor record. This is in CoreRPG scripts\manager_actor.lua - functions to look at are getCTNode (if you want to operate against data in the combat tracker), getCreatureNode, etc. which can return the database node of the actor record. Depending on exactly what you want to do you may be better using getCTNodeName or getCreatureNodeName and then use individual DB.getValue commands using the node name (stored in a string variable). This is much more efficient, as a creature node will contain the whole node substructure and can take up a lot of resources (especially a PC node).

So, you could do something like this:

local sPCNodeName = ActorManager.getCreatureNodeName(rSource);
local nodeFeatureList = DB.getChild(sPCNodeName, "featurelist");

if nodeFeatureList then
for k, nodeFeature in pairs (nodeFeatureList.getChildren()) do
if DB.getValue(nodeFeature, "name", ""):lower() == "reliable talent" then
-- Do your code for reliable talent here.
break;
end
end
end

Note: I haven't tested this code, so it may not be 100% correct. And, you didn't mention the ruleset you're using, I've assumed 5E which uses "featurelist" to store the feature data in the charsheet database.

Stv
January 5th, 2020, 20:40
My bad, meant to include I was using 5e in my previous post.
Thank you for replying, something else for me to look at.

Cheers, Steve.

Stv
January 5th, 2020, 21:35
Trenloe, you Sir are a legend :)
But I have one more question...as I'm inserting my new code into the end of the manager_action_skill.lua file, I must copy the whole of that file to my new one and put the changes in there, as it's not a global script so I can't override the functions in there separately ?

Thanks again, Steve.

Trenloe
January 5th, 2020, 21:48
Trenloe, you Sir are a legend :)
I have my good days! ;)


But I have one more question...as I'm inserting my new code into the end of the manager_action_skill.lua file, I must copy the whole of that file to my new one and put the changes in there, as it's not a global script so I can't override the functions in there separately ?
manager_action_skill.lua is a global script - with a name of ActionSkill. So you can override it. Use ActionSkill.onRoll = {my new function} where {my new function} is your version of onRoll.

Stv
January 5th, 2020, 22:07
Once again, I thank you :)