View Full Version : Roll based on numberfield
pr6i6e6st
August 7th, 2019, 08:08
Problem mostly solved. onto next steps:
1: get the name of the roll from dragdata to display in chat upon completion
2: get a "push" mechanic (add a level of stress, roll all dice again minus any 6's)
28346
28347
28348
28349
<!--Stress Points-->
<boxframe>
<bounds>260,45,230,80</bounds>
</boxframe>
<emptyframe name="stressback">
<bounds>270,55,210,60</bounds>
</emptyframe>
<label name="stressLabel">
<anchored to="stressback" position="insidetopleft" offset="20,10" />
<static text="Stress Level" />
</label>
<buttongroup_counter name="StressPoints">
<anchored to="stressback" position="insidetopleft" offset="20,25" />
<sourcefields>
<current>hp.stress</current>
</sourcefields>
<values>
<maximum>10</maximum>
</values>
</buttongroup_counter>
<basicnumber name="stressroll" source="stressroll.slot.amount">
<min>0</min>
<max>10</max>
<anchored to="stressLabel" position="right" offset="60,0" width="30" height="20" />
<script>
function onDoubleClick(x, y)
Comm.throwDice( "dice", {"dS"}, getValue(), description)
end
function onDragStart(button, x, y, dragdata)
dragdata.setType("dice");
dragdata.setDieList({ "dS" });
dragdata.setNumberData(getValue());
dragdata.setDescription("sSkillRollDesc");
return true;
end
</script>
</basicnumber>
pr6i6e6st
August 8th, 2019, 20:55
Like, i really don’t seem to grasp how scripting works, what’s a template and what’s native.
I basically just want
Function onDragStart()
nDice = stressroll.slot.amount.getValue()
tDie = getDice(“ dS ”)
For nDice do
dragdata.setDice((nDice*{tDie}))
End
Trenloe
August 8th, 2019, 21:14
Do a search (find in files) in various FG rulesets - search for "table.insert(aDice" in the 5E ruleset, for example, and there's an example where a number of dice are added to the aDice table:
for i = 1, nHDMult do
table.insert(aDice, "d" .. nHDSides);
end
You can't just add multiple dice to the aDice table in one command (i.e. doing multipliers like dice*number) , you need to use a for loop to add each dice at a time. So, maybe try something like this:
for i = 1, nDice do
table.insert(aDice, "dS");
end
But also keep in mind what I said here: https://www.fantasygrounds.com/forums/showthread.php?50148-requesting-help-Custom-Die-Results-from-character-sheet-roll&p=445975&viewfull=1#post445975
Trenloe
August 8th, 2019, 21:22
Actually, a better search to get lots of examples is to search (find in files) for "table.insert(rRoll.aDice" in the 3.5E ruleset.
Andraax
August 8th, 2019, 21:27
Actually, I believe you can.
aDice = { "d6", "dS", "d20" };
pr6i6e6st
August 8th, 2019, 21:40
Actually, I believe you can.
aDice = { "d6", "dS", "d20" };
That does work, but with static number of dice, where I need it to be a variable based on the number field you drag the dice from. Unless I’m missing something.
I’ll have to look later to see what I can find for the “for” function and determine if I know what the variable is for the number field. (In the instance I provided, I am to believe it’s “stressroll.slot.amount” as that works with the button_counter for the <sourcefield><current>
Trenloe
August 8th, 2019, 21:44
That does work, but with static number of dice, where I need it to be a variable based on the number field you drag the dice from.
See the second code block in post #3 above.
MadBeardMan
August 8th, 2019, 21:51
Here's an example out of the WOiN ruleset.
Very basically 'What's Old is New' builds a Dice Pool, you add your Stat + Skill + Modifier Dice and on top you can add Luck dice etc.
Here's the code, it reads from the 'Attack' field which is on the screen listed next to an attack (say a Pistol), then checks for Modifiers and then inserts the extra dice or removes them, as the Desktop +1, +2, -1, -2 are actual D6 to remove.
Hope this helps.
local nTotal = attack.getValue().."d6";
local aDice, nMod = StringManager.convertStringToDice(nTotal);
-- add Modifier dice
local bDescNotEmpty = true;
local sStackDesc, nStackMod = ModifierStack.getStack(bDescNotEmpty);
local modifierDice = nStackMod;
if modifierDice > 0 then
for i=1,modifierDice do
table.insert(aDice, "d6");
end
else
for i=1,-modifierDice do
table.remove(aDice);
end
end
Cheers,
MBM
pr6i6e6st
August 8th, 2019, 21:59
Here's an example out of the WOiN ruleset.
Very basically 'What's Old is New' builds a Dice Pool, you add your Stat + Skill + Modifier Dice and on top you can add Luck dice etc.
Here's the code, it reads from the 'Attack' field which is on the screen listed next to an attack (say a Pistol), then checks for Modifiers and then inserts the extra dice or removes them, as the Desktop +1, +2, -1, -2 are actual D6 to remove.
Hope this helps.
local nTotal = attack.getValue().."d6";
local aDice, nMod = StringManager.convertStringToDice(nTotal);
-- add Modifier dice
local bDescNotEmpty = true;
local sStackDesc, nStackMod = ModifierStack.getStack(bDescNotEmpty);
local modifierDice = nStackMod;
if modifierDice > 0 then
for i=1,modifierDice do
table.insert(aDice, "d6");
end
else
for i=1,-modifierDice do
table.remove(aDice);
end
end
Cheers,
MBM
I’ll have to give this a look, do I need to add any script.lua’s? Or are these available in CoreRPG?
See the second code block in post #3 above.
Yes, sorry, I meant to say I’ll need to check out what you’ve suggested.
MadBeardMan
August 8th, 2019, 22:02
Yes you will need to add it to the script wherever you 'build' your dice pool.
pr6i6e6st
August 8th, 2019, 22:43
Yes you will need to add it to the script wherever you 'build' your dice pool.
Ok, so it doesn’t need its own file in, say, “campaign/scripts/example.lua”?
Sorry, just making sure I understand
MadBeardMan
August 8th, 2019, 23:02
The example I gave you is the script section of the template code.
For example here's something similar from Traveller, this is for rolling the Initiative:
<template name="number_initiative">
<simplenumber>
<source mergerule="resetandadd" />
<script file="common/scripts/number_linked.lua" />
<frame mergerule="replace" name="fielddark" offset="7,5,7,5" />
<stateframe>
<keyedit name="fieldfocus" offset="7,5,7,5" />
<hover name="fieldfocus" offset="7,5,7,5" hidereadonly="true" />
<drophilight name="fieldfocus" offset="7,5,7,5" hidereadonly="true" />
</stateframe>
<script>
function action(draginfo)
local rActor = ActorManager.getActor("pc", window.getDatabaseNode());
ActionInit.performRoll(draginfo, rActor);
return true;
end
function onDragStart(button, x, y, draginfo)
return action(draginfo);
end
function onDoubleClick(x,y)
return action();
end
</script>
<rollable />
</simplenumber>
</template>
I can take a look at your stuff in your original posting but it's late here (11pm) and so I'm logging for the night.
Hope you can make progress
Cheers,
MBM
pr6i6e6st
August 9th, 2019, 06:51
uhg, i can't seem to get it to work.
i might be doing this quite wrong, as i say, i have little to no experience with xml/lua so please forgive me if i'm a pain in the butt about this.
i tried copying the code directly into the <basicnumber name="stressroll" source="stressroll.slot.amount"> spot, and tried modifying to suit my code where needed. but i think part of my problem is that i can't seem to figure out how to get the variable number from the <basicnumber> i'm writing the script into.
like i say, maybe i'm doing this wrong. perhaps i need to do up a template? because what i have now is all right in the record_char_main2.xml within the charsheet_main2 window. all the frames, <basicnumber>'s, and such are directly in there, i don't have a template "attributescore" or "attributecheck". i've been scripting directly into:
record_char_main2.xml (a copy of the CoreRPG "record_char_main.xml")
<window name="charsheet_main2">
<basicnumber name="stressroll" source="stressroll.slot.amount">
<script>
i've been putting my code in here
</script>
</basicnumber>
<window>
i feel like i'm close. i feel like trenloe's addition with the "for" commands was close to working, but i can't seem to reference the <basicnumber> from which i'm coding in. i can't seem to reference any numberfield source. so how do i set up the variable? from other examples i've seen, the following should theoretically work:
nDice = getValue();
but it often can't reference the "global: getValue()"
i tried MadBearMan's code, and i still may not know what to change, such as the ActionInit, i tried ActionManager to no avail.
if someone can help me figure out the Stress Roll part, then maybe i can figure out the rest of it. i just can't figure out how to assemble this.
(note, i will want other rolls to include the stressroll if the stresspoints are above 0)
stress points are in the "Alien RPG\campaign\record_char_main2.xml" file, starting at line 41, ending at line 81. the <basicnumber> section starts at line 61.
Trenloe
August 9th, 2019, 15:46
nDice = getValue();
but it often can't reference the "global: getValue()"
getValue(); should work - as long as the LUA script is running within the context of the control. If it's running in the window you'll need to use <control name>.getValue() - for example, stressroll.getValue();
i tried MadBearMan's code, and i still may not know what to change, such as the ActionInit, i tried ActionManager to no avail.
ActionInit is a predefined action. Actions are the usual way to do dice rolling in FG. See here for details of FG actions: https://www.fantasygrounds.com/forums/showthread.php?35531-Fantasy-Grounds-v3-X-CoreRPG-based-Actions-(dice-rolling)
pr6i6e6st
August 9th, 2019, 18:06
getValue(); should work - as long as the LUA script is running within the context of the control. If it's running in the window you'll need to use <control name>.getValue() - for example, stressroll.getValue();
i feel like this is what's holding me up the most really. the console keeps returning "script Error: [string"stressroll"]:1 attempt to call global 'getValue' (a nil value)" for just putting:
<script>
local nDice = getValue();
</script>
so i'm missing something here, because you say that should work, and i believe you, it looks like it should. but for some reason, it's not? i'll have to check back later.
thanks for being patient, sorry if you've explained yourself and i'm not grasping it.
Trenloe
August 9th, 2019, 20:15
<script>
local nDice = getValue();
</script>
You can't just have code in a script by itself. It needs to be in a function and that function needs to be either called from somewhere else, or tied to an event (buttonClick, onUpdate, etc.). FG is primarily an event driven application - something happens to trigger one or more events that do something else.
There are many events within FG - the exact event you can tie code off will depend on the control that's triggering the event.
In your code in post #1 you were using the onDoubleClick event - which is a good start. Details on that event here: https://www.fantasygrounds.com/refdoc/windowcontrol.xcp#onDoubleClick
pr6i6e6st
August 10th, 2019, 04:51
You can't just have code in a script by itself. It needs to be in a function and that function needs to be either called from somewhere else, or tied to an event (buttonClick, onUpdate, etc.). FG is primarily an event driven application - something happens to trigger one or more events that do something else.
There are many events within FG - the exact event you can tie code off will depend on the control that's triggering the event.
In your code in post #1 you were using the onDoubleClick event - which is a good start. Details on that event here: https://www.fantasygrounds.com/refdoc/windowcontrol.xcp#onDoubleClick
ok i think i'm kind of getting it, but i think i'm not referring to aDice properly or something here. i've tried a few different variations of (aDice), aDice, {aDice}, "aDice". ({" aDice "}) crashed the program haha. so what's off here?
<script>
function onDragStart(button, x, y, dragdata)
local nTotal = getValue().."dS";
local aDice, nMod = StringManager.convertStringToDice(nTotal);
local bDescNotEmpty = true;
local sStackDesc, nStackMod = ModifierStack.getStack(bDescNotEmpty);
local modifierDice = nStackMod;
if modifierDice > 0 then
for i=1,modifierDice do
table.insert(aDice, "dS");
end
else
for i=1,-modifierDice do
table.remove(aDice);
end
end
dragdata.setType("dice");
dragdata.setDieList(aDice);
dragdata.setNumberData(getValue());
dragdata.setDescription("Stress Roll");
return true;
end
function onDoubleClick(x,y)
local nTotal = getValue().."dS";
local aDice, nMod = StringManager.convertStringToDice(nTotal);
local bDescNotEmpty = true;
local sStackDesc, nStackMod = ModifierStack.getStack(bDescNotEmpty);
local modifierDice = nStackMod;
if modifierDice > 0 then
for i=1,modifierDice do
table.insert(aDice, "dS");
end
else
for i=1,-modifierDice do
table.remove(aDice);
end
end
Comm.throwDice( "dice", aDice, getValue(), description)
end
</script>
pr6i6e6st
August 10th, 2019, 05:52
NEVERMIND!!! I GOT IT! Holy crap i got it! Thank You guys SO MUCH!
<script>
function onDragStart(button, x, y, dragdata)
local description = "Stress Roll"
local nValue = getValue();
local aDice, nMod = StringManager.convertStringToDice(nTotal);
local bDescNotEmpty = true;
local sStackDesc, nStackMod = ModifierStack.getStack(bDescNotEmpty);
local modifierDice = nStackMod;
if nValue > 0 then
for i=1,nValue do
table.insert(aDice, "dS");
end
else
for i=1,-nValue do
table.remove(aDice);
end
end
dragdata.setType("dice");
dragdata.setDieList(aDice);
dragdata.setNumberData(getValue());
dragdata.setDescription("Stress Roll");
return true;
end
function onDoubleClick(x, y)
local nValue = getValue();
local nTotal = getValue().."dS";
local aDice, nMod = StringManager.convertStringToDice(nTotal);
local bDescNotEmpty = true;
local sStackDesc, nStackMod = ModifierStack.getStack(bDescNotEmpty);
local modifierDice = nStackMod;
if nValue > 0 then
for i=1,nValue do
table.insert(aDice, "dS");
end
else
for i=1,-nValue do
table.remove(aDice);
end
end
Comm.throwDice( "dice", aDice, getValue(), description)
end
</script>
pr6i6e6st
August 10th, 2019, 05:58
now if only i could get the description to show in chat for onDragStart. sometimes i can see the text being dragged, but it doesn't return in the chat with the rest. onDoubleClick works.
damned
August 10th, 2019, 06:44
aDice is a Lua array.
It (can) holds multiple pieces of data - eg 1d20, 1d20, 2d20, 1d20
debug aDice at various stages and see what is outputting
you are getting different results from onDragStart and onDoubleClick because you are running different things on those events
MadBeardMan
August 10th, 2019, 23:53
If you want, I can download your zip and take a look tomorrow, been caught up today on lots of stuff and trying to hurry up finishing Traveller2E.
LMK, Cheers
MBM
pr6i6e6st
August 11th, 2019, 00:06
If you want, I can download your zip and take a look tomorrow, been caught up today on lots of stuff and trying to hurry up finishing Traveller2E.
LMK, Cheers
MBM
Sure! Turns out I got the stress rolls added where needed. So now just labels on drag/drop, and a push roll.
Maybe eventually some rigging of the combat tracker and the weapons section of the inventory.
JimSocks
August 17th, 2019, 08:07
Man- this is AWESOME. All of the improvements you made are just aces. I love the way it includes the stress dice automatically in the skill check rolls now! My players are super grateful and loved it too- thank you so much.
pr6i6e6st
August 17th, 2019, 14:35
Man- this is AWESOME. All of the improvements you made are just aces. I love the way it includes the stress dice automatically in the skill check rolls now! My players are super grateful and loved it too- thank you so much.
Hey thanks! Make sure to check the extensions subforum, as I made a post dedicated to it there and have made an update there.
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.