PDA

View Full Version : Comm.throwDice() TableManager support



pr6i6e6st
February 29th, 2020, 23:27
Hey guys!

So I’m trying to rig up the Panic Button in the Alien RPG ruleset so that when it rolls on the designated table, that if a checkbox (IsPanicking) is enabled and the die/table result from the processtableroll() function is lower than the previous one, that the result displayed is actually the last result + 1.

I’ve completely copied the manager_actions.lua and manager_table.lua into one called panic_roll.lua which is the active script for the buttonfield PanicRoll.

Here’s how I want it to go:
-Press panic button
-Check of character is panicking
-Roll on designated table named “Panic Roll” via processTableRoll() -remember that this code is copied into the buttons script for use.
-If IsPanicking then result = LastResult + 1
-elseif IsPanicking ==false and result is greater than 6, then IsPanicking == true

But it appears that once we get to the roll() function, it utilizes a Comm.throwDice() function, the unlockModifiers() function is called, and the code will work any way I please except to retrieve the die or table results.

Moon Wizard
February 29th, 2020, 23:40
You should probably bypass the existing rolls and table system completely; and just make your own custom "panic" roll type. You'll probably spend as much or more time trying to shoehorn into existing rolls/tables as you would just implementing your own.

Regards,
JPG

pr6i6e6st
February 29th, 2020, 23:49
You should probably bypass the existing rolls and table system completely; and just make your own custom "panic" roll type. You'll probably spend as much or more time trying to shoehorn into existing rolls/tables as you would just implementing your own.

Regards,
JPG

so, much like how i made the stress die, i make a "Panic die"? for example.

pr6i6e6st
March 1st, 2020, 04:06
You should probably bypass the existing rolls and table system completely; and just make your own custom "panic" roll type. You'll probably spend as much or more time trying to shoehorn into existing rolls/tables as you would just implementing your own.

Regards,
JPG

ok i almost have it now. i made a new roll for panic rolls. it works great, now i just need to wrap my head around how to only get a higher result than the last one rolled when the character is already panicking. the below works, i just can't wrap my head around making nTotal 1 higher than the last time the onRoll() function was called if window.Panic.getValue() == 1. and then reset that number to 0 when window.Panic.getValue() == 0.



function onRoll(rSource, rTarget, rRoll)

Debug.console("Panic_Roll onRoll called");
local PanicRoll = Interface.getString("TableName_PanicRoll");
local rMessage = ActionsManager.createActionMessage(rSource, rRoll);
if rRoll then
local nTotal = ActionsManager.total(rRoll);
if window.Panic.getValue() == 1 then
if nTotal < window.LastPanicResult.getValue() then
MorePanicMod = MorePanicMod + 1;
nTotal = LastResult + MorePanicMod;
end
end
if window.Panic.getValue() == 0 then
if nTotal > 6 then
StartPanicking();
end
end
processTableRoll("", "" .. PanicRoll .. ", -d " .. nTotal .."");
LastResult = nTotal;
window.LastPanicResult.setValue(nTotal);
end

Comm.deliverChatMessage(rMessage);
end

pr6i6e6st
March 1st, 2020, 04:35
Think i got it, no problems so far that i can see. . .



function onRoll(rSource, rTarget, rRoll)

Debug.console("Panic_Roll onRoll called");
local rMessage = ActionsManager.createActionMessage(rSource, rRoll);
local StressMod = window.stressmod.getValue();
local CombatType = window.combattype.getValue();
if CombatType == 0 then
PanicRoll = Interface.getString("TableName_SpacePanicRoll");
end
if CombatType == 1 then
PanicRoll = Interface.getString("TableName_PanicRoll");
end
if rRoll then

local nTotal = ActionsManager.total(rRoll);

if window.Panic.getValue() == 1 then
if nTotal < window.LastPanicResult.getValue() then
MorePanicMod = 1;
nTotal = LastResult + MorePanicMod;
end
end

if window.Panic.getValue() == 0 then
if nTotal > 6 then
StartPanicking();
end
end
PanicRollResultTotal = nTotal + StressMod;
if PanicRollResultTotal < 0 then
PanicRollResultTotal = 0;
end


processTableRoll("", "" .. PanicRoll .. ", -d " .. PanicRollResultTotal .."");
LastResult = nTotal;
window.LastPanicResult.setValue(nTotal);
end

Comm.deliverChatMessage(rMessage);
end

Trenloe
March 1st, 2020, 04:41
ok i almost have it now. i made a new roll for panic rolls. it works great, now i just need to wrap my head around how to only get a higher result than the last one rolled when the character is already panicking. the below works, i just can't wrap my head around making nTotal 1 higher than the last time the onRoll() function was called if window.Panic.getValue() == 1. and then reset that number to 0 when window.Panic.getValue() == 0.
Write the previous nTotal data to a field to the database for the character in question that stores the last result? It'll have to be per character to support players running multiple characters or GMs making a roll from the PC sheet. Then access that field in the onRoll function as required.

pr6i6e6st
March 1st, 2020, 05:57
Write the previous nTotal data to a field to the database for the character in question that stores the last result? It'll have to be per character to support players running multiple characters or GMs making a roll from the PC sheet. Then access that field in the onRoll function as required.

ok, so the following code works perfectly except for what you mentioned about multiple PC's. I'm sure this has been spelled out multiple times but i feel so slow at understanding this lately; how do you utilize the DB in this manner? sometimes i think i get it after reading examples and the reference guide, then i try it and know that i don't understand.

so my charsheet_main2.xml file has (minus lines not partaining to the issue):

a <number_ct_crosslink name="LastPanicResult" source="LastPanicResult">

and a <buttonfield name="panic_roll">
-----------<script file="Panic_Roll.lua" />
-------</buttonfield>

So i realize some of the parts i have set as window.WHATEVERHERE.getorsetValue(); need to change to something resembling DB.getDatabaseNode().getChild().getValue(WHATEVERH ERE, 0) but that's about as much as i've wrapped my head around.

then in the Panic_Roll.Lua


function onRoll(rSource, rTarget, rRoll)

Debug.console("Panic_Roll onRoll called");
local rMessage = ActionsManager.createActionMessage(rSource, rRoll);
local StressMod = window.stressmod.getValue();
local CombatType = window.combattype.getValue();
if CombatType == 0 then
PanicRoll = Interface.getString("TableName_SpacePanicRoll");
end
if CombatType == 1 then
PanicRoll = Interface.getString("TableName_PanicRoll");
end
if rRoll then

local nTotal = ActionsManager.total(rRoll);

if window.Panic.getValue() == 1 then
if nTotal < window.LastPanicResult.getValue() then
MorePanicMod = 1;
nTotal = LastResult + MorePanicMod;
end
end


PanicRollResultTotal = nTotal + StressMod;
if PanicRollResultTotal < 0 then
PanicRollResultTotal = 0;
end
if window.Panic.getValue() == 0 then
if PanicRollResultTotal > 6 then
StartPanicking();
end
end

processTableRoll("", "" .. PanicRoll .. ", -d " .. PanicRollResultTotal .."");
LastResult = nTotal;
window.LastPanicResult.setValue(LastResult);
end

Comm.deliverChatMessage(rMessage);
end

function CheckIfPanicking()
if window.Panic.getValue == 1 then
local IsPanicking = true;
else
local IsPanicking = false;
end
return true;
end
function StartPanicking()
window.Panic.setValue(1);

end


function CheckStressLevel()
nStress = window.stressroll.getValue();
return nStress;
end

function onButtonPress()
CheckStressLevel();
CheckIfPanicking();
performRoll2();

end

function performRoll2(draginfo, rActor, sCheck)
Debug.console("Panic_Roll performRoll2 called");
local rRoll = getRoll2(rActor, sCheck);


ActionsManager.performAction(draginfo, rActor, rRoll);
end

Trenloe
March 1st, 2020, 07:23
local sActorType, nodeActor = ActorManager.getTypeAndNode(rActor); - where rActor is rSource or rTarget, will give the actor type ("pc" or "npc") and the database node of the actor. For a PC this will be charsheet.id-XXXXX in the FG campaign database, where XXXXX is a unique number starting at 00001 for the first PC created.

Details on the databasenode API object here: https://www.fantasygrounds.com/refdoc/databasenode.xcp

So, maybe you add a panic.lastresult database field within the PC sheet using: DB.setValue(nodeActor, "panic.lastresult", "number", nTotal); to set the value to nTotal. Info on that API call here: https://www.fantasygrounds.com/refdoc/DB.xcp#setValue

You can get the value using DB.getValue: https://www.fantasygrounds.com/refdoc/DB.xcp#getValue

For example: nLastValue = DB.getValue(nodeActor, "panic.lastresult", 0);

So, with the above commands you can set and get the data in the PC database structure for the specific character in panic.lastvalue

pr6i6e6st
March 2nd, 2020, 04:21
so here's what i've tried last. the dummies i've set up don't show the last result and the panicstate isn't being toggled/set to 1. what am i missing/misunderstanding?

panic_roll.lua


function onRoll(rSource, rTarget, rRoll)
local sActorType, nodeActor = ActorManager.getTypeAndNode(rSource);
CheckIfPanicking(nodeActor);
Debug.console("Panic_Roll onRoll called");
local rMessage = ActionsManager.createActionMessage(rActor, rRoll);
local StressMod = window.stressmod.getValue();
local CombatType = window.combattype.getValue();
if CombatType == 0 then
PanicRoll = Interface.getString("TableName_SpacePanicRoll");
end
if CombatType == 1 then
PanicRoll = Interface.getString("TableName_PanicRoll");
end
if rRoll then

local nTotal = ActionsManager.total(rRoll);
local LastResult = DB.getValue(nodeActor, "panic.lastresult", 0);
local PanicStatus = DB.getValue(nodeActor, "Panic", 0);
if PanicStatus == 1 then
if nTotal < LastResult then
MorePanicMod = 1;
nTotal = LastResult + MorePanicMod;
end
end


PanicRollResultTotal = nTotal + StressMod;
if PanicRollResultTotal < 0 then
PanicRollResultTotal = 0;
end
if PanicStatus == 0 then
if PanicRollResultTotal > 6 then
DB.setValue(nodeActor, "Panic", "number", 1);
end
end
processTableRoll("", "" .. PanicRoll .. ", -d " .. PanicRollResultTotal .. "");
LastResult = nTotal;

DB.setValue(nodeActor, "panic.lastresult", "number", " .. PanicRollResultTotal .. ");
end

Comm.deliverChatMessage(rMessage, rActor);
end

function CheckIfPanicking(nodeActor)
if DB.getValue(nodeActor, "Panic", 0) == 1 then
local IsPanicking = true;
else
local IsPanicking = false;
end
return true;
end
function StartPanicking()

end


function CheckStressLevel()
nStress = window.stressroll.getValue();
return nStress;
end




Charsheet_main2.xml


<buttongroup_counter name="panickingshow">
<anchored to="stressroll" width="20">
<left parent="stressroll" anchor="right" offset="10" />
<top parent="stressroll" anchor="top" offset="-5" />
</anchored>
<sourcefields>
<current>Panic</current>
</sourcefields>
<values>
<maximum>1</maximum>
</values>
<tooltip textres="record_char_main2_panicking_tooltip" />

</buttongroup_counter>
<number_ct_crosslink name="LastPanicResult" source="panic.lastresult">
<min>0</min>
<color>34BF00</color>
<anchored to="panickingshow" position="right" offset="5,0" width="20" />
<delaykeyupdate />
</number_ct_crosslink>

<number_ct_crosslink name="Panic" source="Panic">
<min>0</min>
<color>34BF00</color>
<anchored to="LastPanicResult" position="right" offset="5,0" width="20" />
<delaykeyupdate />

</number_ct_crosslink>

<buttoncontrol name="panic_button">
<anchored to="stressback" position="insidetopleft" offset="4,20" width="25" height="25" />
<frame name="panic_button_up" offset="2,2,2,2" />
<color>000000</color>
<stateframe>
<pressed name="panic_button_down" offset="2,2,2,2" nobaseframe="true" />
</stateframe>
<pressed offset="1,1" />
<state>
<tooltip textres="record_char_main2_panic_tooltip" />
</state>
<script file="campaign/scripts/panic_roll.lua" />
</buttoncontrol>

Trenloe
March 2nd, 2020, 11:35
so here's what i've tried last. the dummies i've set up don't show the last result and the panicstate isn't being toggled/set to 1. what am i missing/misunderstanding?
Look at where your "Panic" control is actually storing the data in the database structure.

Open the campaign db.xml file (after issuing a chat \save command to write the latest data) and look at the charsheet.id-XXXXX hierarchy for the PC you're working with (you may find it easier to start a new campaign with only one PC). Where is the "Panic" DB field linked to the "Panic" control within this hierarchy?

Using the FG database is the best way to do anything like this - the GUI is not the best place to use as it can often change and data is only available via GUI controls if they've actually been created. Using in the database is a lot better all round as the structure is more readily seen (look in db.xml) and can be accessed even if the character sheet isn't open - e.g. making rolls from the CT. It can be a bit daunting at first, but it's well worth taking the time to get familiar with it - it will save you a lot of time in the long run.

High level info on the FG database structure an notation available here: https://www.fantasygrounds.com/wiki/index.php/Developer_Guide_-_Rulesets_-_Database
Info on database nodes here: https://www.fantasygrounds.com/refdoc/databasenode.xcp

Maybe it would be easier for us to give advice if you attach the whole ruleset, and steps to recreate, so we can give you detailed feedback on the exact DB structure and what's happening.

pr6i6e6st
March 2nd, 2020, 17:12
Look at where your "Panic" control is actually storing the data in the database structure.

Open the campaign db.xml file (after issuing a chat \save command to write the latest data) and look at the charsheet.id-XXXXX hierarchy for the PC you're working with (you may find it easier to start a new campaign with only one PC). Where is the "Panic" DB field linked to the "Panic" control within this hierarchy?

Using the FG database is the best way to do anything like this - the GUI is not the best place to use as it can often change and data is only available via GUI controls if they've actually been created. Using in the database is a lot better all round as the structure is more readily seen (look in db.xml) and can be accessed even if the character sheet isn't open - e.g. making rolls from the CT. It can be a bit daunting at first, but it's well worth taking the time to get familiar with it - it will save you a lot of time in the long run.

High level info on the FG database structure an notation available here: https://www.fantasygrounds.com/wiki/index.php/Developer_Guide_-_Rulesets_-_Database
Info on database nodes here: https://www.fantasygrounds.com/refdoc/databasenode.xcp

Maybe it would be easier for us to give advice if you attach the whole ruleset, and steps to recreate, so we can give you detailed feedback on the exact DB structure and what's happening.

ok so here's an example of where the Panic and LastPanicResult fields are ending up


<id-00002>
<holder name="Ben M" owner="true" />
<LastPanicResult type="number">10</LastPanicResult>
<Panic type="number">0</Panic>


Ruleset and the version i'm currently working on included below.

files that are specific to this new set of code is:

campaign/record_char_main2.xml - lines: 994 through 1022
campaign/scripts/panic_roll.lua - lines: 5 through 141

(following aren't required for the lines of code, but may cause issues if any name changes)
ct_entry.lua (lines 172-173)
template_ct.xml (lines 537-550)
ct_host.xml (lines 482 and 483).

Trenloe
March 2nd, 2020, 18:28
Thanks for posting. There were quite a few little things wrong with it:-
1) Use all lower case for database field names. This isn't specifically documented anywhere that I can find, but I've seen strange behavior with database field names not being updated through code if they have uppercase characters.
2) The CheckIfPanicking function wasn't returning any data (and it wasn't being used correctly when it was called).
3) This was the big one - onButtonPress didn't create and pass rActor to the performRoll2 function. So no information about the PC making the roll was available later in the process.

I've fixed the above, also made some minor changes. I've added a lot more debug within the rolling process - open the console before rolling to see the debug data. I'm not sure if this is working as planned, as I don't know the RPG system. But it is storing last result data and retrieving it as part of the next roll.

The two pieces of data are stored in panic.panic and panic.lastpanincresult which keeps them all in their own node in the charsheet DB:

<charsheet>
<id-00001>
...
<panic>
<lastpanincresult type="number">6</lastpanincresult>
<panic type="number">0</panic>
</panic>
...

The two files I modified are attached.

Hope this helps you move forward toward the functionality you're looking for.

pr6i6e6st
March 2nd, 2020, 18:42
.
oh man you have done it again. so i did a bit of tweaking, mostly just a couple of spots where i had to replace Panic with panic.panic, and i think it's working perfectly. and thank you for the detailed explanation and patience. with yours and Moonwizard's help, i should be able to use this knowledge to improve a lot of my code and maybe finally figure out damage and stuff via the combat tracker/drag and drop targeting.