PDA

View Full Version : FG 2 LUA - Easy D20 skill/ability rolls



joshuha
April 25th, 2007, 17:16
The default D20 ruleset with the FG 2.0 makes use of templates to control how fields inherit when creating a ruleset. This means you can assign properties to a template field (like an abilitybonus or savebonus) and have those properties inherit to every field declared on the sheet with that template. In the end what this does is make thing easier so common properties don't have to be typed over and over.

What I did was to use this along with the script function which means I can easily assign a set of fields the same function without having to type in the code over and over.

The example below is just a few lines of real code but what it does is very helpful. First, I define a function that inputs some parameters to throw a dice, this is rather generic. Then I define in the ability bonus and skill total a double click event that calls this function and passes it info. In effect, every ability bonus box and skill total box has these functions with only a few lines of code.

So the end effect is you double click your Diplomacy total and out pops a d20 on the screen with the right modifier and label. Since this is being triggered from a die hitting the screen, the modifier box is applied to. This is done for your abiltiy bonuses too. So just double click and watch for yourself!



In the chatmanager.lua file:



function d20Check(type, bonus, name)
if control then
local dice = {};
table.insert(dice, type);
control.throwDice("dice", dice, bonus, name);
end
end


In the charsheet_template.xml file add the following under the script section for <template name="abilitybonus">:



function onDoubleClick(x,y)
ChatManager.d20Check("d20", getValue(), sources[scorefield[1]].getName());
return true;
end


In the charsheet_skills.xml file, add the following under the script section for the <numberfield name="total">



function onDoubleClick(x,y)
ChatManager.d20Check("d20", getValue(), window.label.getValue());
return true;
end


That's it. Now every ability score bonus and every skill total can be double-clicked for a d20 check!

You can also apply the code to the Save totals in the template file but its as simple as adding the same above lines. The only tricky part is getting the label right (I just used other examples from within the same file).

If you want everything to look nice and maintain the same capitalization add this function to the chatmanager.lua file:


--returns proper case formatting
function propercase(strInput)
local iPosition = 1;
local strOutput = "";

--loop through input by space upper the first character of a "word", lower the rest
while string.find(strInput, " ", iPosition) ~= nil do
iSpace = string.find(strInput, " ", iPosition);
strOutput = strOutput .. string.upper(string.sub(strInput, iPosition, iPosition));
strOutput = strOutput .. string.lower(string.sub(strInput, iPosition + 1, iPosition + iSpace - iPosition));
iPosition = iSpace+1;
end

strOutput = strOutput .. string.upper(string.sub(strInput, iPosition, iPosition));
strOutput = strOutput .. string.lower(string.sub(strInput, iPosition + 1));

return strOutput;
end


and then change the d20 check function like so:



function d20Check(type, bonus, name)
if control then
local dice = {};
table.insert(dice, type);
control.throwDice("dice", dice, bonus, propercase(name));
end
end

richvalle
April 25th, 2007, 17:32
That sounds very, very cool. I'll have to work on getting it working. Thanks!

Is this how scripts are going to work in general? I thought, maybe, they would be .lua files that we could drop in somewhere and make use of them.

rv

joshuha
April 25th, 2007, 17:41
It depends on what you are trying to do. For new things like treasure table rollers or what not a seperate file is the way to go. But in this case I am modifying things that are built into the ruleset to begin with so you have to modify the places you want them to appear.

richvalle
April 26th, 2007, 03:27
Hmmm, before I mess around with this...

Any changes made are going to get blown away every day by the updates coming out... no? Well, probably. I'm sure it depends on what files they update.

rv

joshuha
April 26th, 2007, 04:45
Thats why you copy this into a d20 ruleset you rename. Leave the default one the same.

sunbeam60
April 26th, 2007, 09:36
Nice, very nice. I wish there was some kind of extension mechanism, where you could specify "where" to add code and then it would get re-added every time a ruleset is updated. Obviously the developers are going to be worried about adding this functionality into the default ruleset as they'd be getting closer to "playing d20" for us, which requires a license for WotC.

joshuha
April 26th, 2007, 12:36
Well the automation part of the OGL specifies that it can't make the resolutions for you which this isn't doing. It is the same as dragging the mod over to the mod box and rolling the die.

Now if the code say, automatically rolled your attack die, compared to the AC of your target, determined if you hit, and then rolled your damage you are probably violating parts of the OGL about automation. Note the above is possible with some extensive LUA but I would only do it for another system where I wasn't afraid of violating a part of the license.

DrDeth
April 26th, 2007, 15:17
Great script joshuha!

Valarian
April 26th, 2007, 15:23
Yay! Automatic die rolling as in GRIP. Thanks for this Joshuha

Necron99
April 26th, 2007, 18:12
This function is really such a plus that the devs should just make it standard ruleset.

Dang Josh, considering all the work you do (and did all through beta) SM should be paying you a retainer.

thrylax
June 25th, 2007, 09:59
This function is really such a plus that the devs should just make it standard ruleset.

Dang Josh, considering all the work you do (and did all through beta) SM should be paying you a retainer.

I agree 110% about including this in the standard rules, but this works great as is and I have already included it in my custom rules.....thanks for the scripts.

I just have a quick question. Whenever I click to roll an ability score, rather than listing which ability score is being rolled in chat, it just says "Score" no matter which ability scores are rolled. The skills sections works just fine however. But anyway, what would I need to do to make this display in chat which ability score is being checked?
Again, thanks for the scripts

Tropico
June 26th, 2007, 15:11
I just added this to my 'd20custom' ruleset and it is a godsend. Really should be the default way it works (and indeed, in my first game it was the first thing I intuitively tried to do).

Thanks Joshuha.



I just have a quick question. Whenever I click to roll an ability score, rather than listing which ability score is being rolled in chat, it just says "Score" no matter which ability scores are rolled. The skills sections works just fine however. But anyway, what would I need to do to make this display in chat which ability score is being checked?

I would also like to know this, plus it would be nice to have it work for the Saves boxes and the Initiative box as well :) though I'm sure that with a little time we can figure it out from what Joshuha has already shown us.



Now if the code say, automatically rolled your attack die, compared to the AC of your target, determined if you hit, and then rolled your damage you are probably violating parts of the OGL about automation. Note the above is possible with some extensive LUA but I would only do it for another system where I wasn't afraid of violating a part of the license.

One could do something like this for their own personal use though, no?

Not that I will.. I mean I would if I could, but I think I have a ways to go before actually knowing how to.. but I'm working on it ;)

joshuha
June 26th, 2007, 15:25
Hmm I think my ability scores still work fine. Will need to double check. If not its due to an update that I don't have incorporated into the code that references the name differently.

Tropico
June 26th, 2007, 16:06
Well, I managed to get the Saves on the combat sheet to make the roll when double clicked... by adding the OnDoubleClick function to the <template name="save"> part of charsheet_templates.xml.

BUT it gives me an error because I don't know how to reference the description text of the save properly :( I'm going crazy here trying to find the right syntax.. description.text, description[1], description.text[1], description.getValue(), description.text.getValue()... none works :(

I can only get it to work fine by putting just a static string like "Save" on the string parameter of the function call.


Edit -> Fine, I got it to work by simply repeating the function on every individual Save box on the charsheet_combat.xml file, with the a string for the description. So for Reflex:



<save name="reflexsave" source="saves.reflex.total">
<anchored>
<to>fortitudesave</to>
</anchored>
<root>reflex</root>
<stat>dexterity</stat>
<description>
<text>Reflex save</text>
</description>
<script>
function onDoubleClick(x,y)
ChatManager.d20Check("d20", getValue(), "Reflex save");
return true;
end
</script>
</save>

Yeah it's a bit ugly but it'll do until I actually learn what's going on.


Later edit -> K, by now I've repeated the same thing on every ability bonus, every save and the initiative boxes on the main and combat sheets... every thing works a-OK with the proper names :)

joshuha
June 26th, 2007, 17:09
Ok for the abilitybonus template replace the check with this:



ChatManager.d20Check("d20", getValue(), self.description[1].text[1]);


That format should work for the saves too. This allows the control to get at its own description.text XML value.

Tropico
June 26th, 2007, 17:28
Awesome! :D

thrylax
June 30th, 2007, 11:29
Ok for the abilitybonus template replace the check with this:



ChatManager.d20Check("d20", getValue(), self.description[1].text[1]);

That format should work for the saves too. This allows the control to get at its own description.text XML value.
Sweet!
Thanks for the info.....works perfectly!!

On a related note, could somebody please tell me which files I need to edit to add the same double-click functionality to the character sheets initiative rolls as well? I can't seem to find a reference for it in charsheet_templates.xml.

thrylax
June 30th, 2007, 12:17
OK....I'm pretty sure I found it in charsheet_combat.xml but could I get some insight into where I would need to place the proper code in order to get double-click functionality on initiative rolls as well. I'm still very new to xml scripting, but I'm learning more every day. :)

thrylax
June 30th, 2007, 12:24
Nevermind.....got it figured out!!! :)

I simply added the following code..............

<script>
function onDoubleClick(x,y)
ChatManager.d20Check("d20", getValue(), self.description[1].text[1]);
return true;
end
</script> ....just below the section for <sheetbonus name="initiative" source="initiative.total"> like so.............................

<sheetbonus name="initiative" source="initiative.total">
<anchored>
<to>initiativeframe</to>
<position>insidetopleft</position>
<offset>90,22</offset>
<size>
<width>32</width>
<height>20</height>
</size>
</anchored>

<script>
function onDoubleClick(x,y)
ChatManager.d20Check("d20", getValue(), self.description[1].text[1]);
return true;
end
</script>
Works perfectly so far. Thank you VERY much for the help.....I'm finally starting to get my ruleset character sheet the way it "should" be.

Now all I need to do is find out where I need to edit in order to add this great functionality for Grapple checks.

Thanks for the help joshuha :-D

andro1d
August 11th, 2007, 15:39
I'm having difficulties locating the charsheet_template.xml and charsheet_skills.xml files. They don't appear in my fantasy grounds 2 main directory or in my fantasy grounds applications folder.

Could somebody point it out to me?

Much thanks,
Andro1d

thrylax
August 11th, 2007, 19:09
I'm having difficulties locating the charsheet_template.xml and charsheet_skills.xml files. They don't appear in my fantasy grounds 2 main directory or in my fantasy grounds applications folder.

Could somebody point it out to me?

Much thanks,
Andro1d To access these files you need to unpak the file called "d20.pak" located in your install directory. Basically its nothing more than a zip file. Once you unzip it it will have all the files you need to edit the ruleset with.
The unzipped files go into a folder which is titled whatever you want to call your ruleset. I call mine "d20+" for example.
Then place this folder in a folder labled "rulesets" located in your application data folder....for example, on my machine, it located here........"C:\Documents and Settings\Administrator\Application Data\Fantasy Grounds II\rulesets\d20+"
Hope this helps

Tailz Silver Paws
August 13th, 2007, 03:59
Great script idea joshuha, could you make my character sheet for me? Huh? Huh? Pleaseeeeeeeeeeee :)

andro1d
August 19th, 2007, 20:33
Thanks Thrylax!

One last question. How do you get modules that were created for d20 ruleset to show up in the game? For instance the core SRD books, etc.

I renamed my ruleset d20+.

Much thanks!
Andro1d

Hamish
August 19th, 2007, 20:56
Just add the following lines to your base.xml



<tokenroot source="tokens" />
<importinfo>
<acceptfrom ruleset="d20" />
</importinfo>
</root>

andro1d
August 19th, 2007, 23:01
Thanks Hamish!

andro1d
August 20th, 2007, 01:31
As I'm new to FG2, I was curious if some of you could give a little feedback. How much of a hassle is it to deal with updates to the program if you have created a custom ruleset and are running a campaign?

Can I expect a lot of lost data? Will my players have to re-enter all of their hotkey commands each update? Higher probability of corrupt files?

Just looking for some advice.

Peace!
Andr01d

Jozie
September 11th, 2007, 05:55
This is one of the most useful scripts for players. My group thanks you.

Jozie
September 12th, 2007, 05:48
How about spell failure. In the most basic form, I would like to be able to double click the spell failure and have it run a d100. In the best scenario it would be cool to roll a d100 and give a Succeed or Fail message if the roll fell within the Failure amount.

Can someone point me in the right direction, I am assuming it is similar to the d20 code Joshuha wrote.

Thanks

zifnab69_fr
September 12th, 2007, 08:00
just a small question.
this mods may just used in the "master" FG2 to be used by players ?
thank you

zifnab69_fr
September 12th, 2007, 10:48
hello,
i need a small help
i mod all the files and it work fine for the abilitis but not for initiative and saves...
i dont know why...

Ok, all is working fine, now.... i did not understand that the mod run only on the combat sheet and not the main. so i mod the charsheet_main.xml to and all work fine...
thank's a lot

Valarian
September 21st, 2007, 23:10
Has anyone figured out how to get the cascade skill description displaying in the automatic die roll? I get the skill name, but not the entered description for cascade skills.

Hamish
September 22nd, 2007, 09:28
I have no idea what you're talking about.... what do you mean by cascading skill descriptions?

Valarian
September 22nd, 2007, 20:27
The additional descriptions for Knowledge, Profession, Craft etc.
The bit that you type in.

maartenlogghe
September 23rd, 2007, 12:03
Hi,

I tried to add the call to d20Check on the ChatManager at a higher level.
So I added the following function at the bottom of the scripts/template_linkednumber.lua


function onDoubleClick(x,y)
if self.description == nil then
ChatManager.d20Check("d20", getValue(), "Not Identified");
else
ChatManager.d20Check("d20", getValue(), self.description[1].text[1]);
end
return true;
end

so this adds the double click event to every linked number. Since a modifiernumber is also linked number this covers quite a bit. ability modifiers, saving throws, intiative, melee..

however for some reason the skill check total modifiers are not 'linked numbers' so it doesn't work there.

Some numbers don't have a description that's why there's an extra if statement.

Anyway .. it's only marginally useful....

cheers,
maarten

Valarian
September 30th, 2007, 23:39
I found the code I needed for the cascade skills in the drag and drop functionality. This produces a roll description of, for example, Knowledge (Culture) instead of just Knowledge.

[EDIT]
In the charsheet_skills.xml file, add the following under the script section for the <numberfield name="total">



function onDoubleClick(x,y)
local label = window.getDatabaseNode().getChild("label").getValue();
local sublabel = window.getDatabaseNode().getChild("sublabel").getValue();

local desc = label;
if not sublabel or sublabel ~= "" then
desc = label .. " (" .. sublabel .. ")";
end

ChatManager.d20Check("d20", getValue(), desc);
return true;
end

zifnab69_fr
October 1st, 2007, 09:27
@valarian
Where do you put this new code ?
thank you :)

Valarian
October 1st, 2007, 12:07
Sorry ... this replaces the code in the charsheet_skills.xml file, under the script section for the <numberfield name="total">, posted by Joshuha in his original posting.

zifnab69_fr
October 1st, 2007, 21:18
@valarian
Thank you :)

Edit:
Work well, thank you :)

Valarian
October 15th, 2007, 00:04
An enhancement for the chatmanager.lua to add functionality to roll multiple dice. Add it under the d20Check function.


function dieCheck(number, type, bonus, name)
if control then
local dice = {};
for i = 1, number, 1 do
table.insert(dice, type);
end
control.throwDice("dice", dice, bonus, name);
end
end


This can be called as follows in the script sections.


<script>
function onDoubleClick(x,y)
ChatManager.dieCheck(2, "d6", getValue(), window.influence.getValue());
return true;
end
</script>

zifnab69_fr
October 15th, 2007, 17:52
Hello
in witch file must we add


<script>
function onDoubleClick(x,y)
ChatManager.dieCheck(2, "d6", getValue(), window.influence.getValue());
return true;
end
</script>

In the chatmanager.lua
or in In the charsheet_template.xml, the charsheet_skills.xml file,...
Thank you

Valarian
October 15th, 2007, 20:58
The script section is in whichever XML file that the number field to double click is in. The example above is for the Babylon 5 Influence rules, which throw 2d6 plus your bonus to get the result. The number fields you want to throw dice for may be in any of the charsheet XML files.

talking_fish
December 5th, 2007, 21:27
How about spell failure. In the most basic form, I would like to be able to double click the spell failure and have it run a d100. In the best scenario it would be cool to roll a d100 and give a Succeed or Fail message if the roll fell within the Failure amount.

Can someone point me in the right direction, I am assuming it is similar to the d20 code Joshuha wrote.

Thanks

Just to let you know, the OGL does NOT allow the implimentation of this sort of code. The OGL states, from what I understand, that any software based on it should not be an interactive game i.e. tell you whether something failed or succeded. You need to do that yourself.

See https://www.wizards.com/default.asp?x=d20/oglfaq/20040123i for more information particularly 'Q: What is different if I use the d20 System License?'

Sorry :(

Just want to keep you on the safe side of the law :p

Tom

Thore_Ironrock
December 5th, 2007, 22:05
https://www.wizards.com/default.asp?x=d20/oglfaq/20040123i
Tom

Tom ... exactly what portion of this FAQ are you referring to specifically?

Tailz Silver Paws
December 5th, 2007, 22:22
Depends what defines an: an interactive game.

Valarian
December 5th, 2007, 22:34
My opinion would be that it's probably okay to automatically roll the dice, but when you start calculating the successes and embedding the tables in the code then you're heading toward the grey areas. Not being a lawyer, I tend to be cautious when it comes to legal stuff.

Sorontar
December 5th, 2007, 22:36
Tom ... exactly what portion of this FAQ are you referring to specifically?

He's referring to the rules about automation in an interactive game which a Spell Failure Check would fall under I, the double click functions should be fine.

Thore_Ironrock
December 5th, 2007, 23:28
Depends what defines an: an interactive game.

Hmm ... I agree with Tailz. The statement about the embedded tables is pretty clear, and that part I can't argue with. For d20, you cannot "tell" the characters what their specific result is when it is found in a table. In case people haven't noticed, there is no experience points table in the d20 license. The only thing you can reference in that regard is a Challenge Rating.

That all said, I'm not 100% convinced that FG is an "interactive game" by the definition they are giving. If it were, WOTC would have shut it down years ago. My guess is this applies more to traditional computer games, or "software gaming assistants" that have been popping up around the Net. This could change though for 4E, which would prevent us from doing 4E OGL in FG.

As for Josh's potential code, there is nothing preventing him from developing it for another gaming system ... and then if people want to modify it for personal use more power to them. :)

talking_fish
December 6th, 2007, 18:03
Sorry for the confusion :o . I'm not a lawyer or anything, I have just been looking into it as I am writing a ruleset based on the OGL mongoose runequest rules, and have had to read over and try to understand wizards FAQ

What I meant to say was:

Rolling the dice any way you like is fine, I believe

BUT

If the PROGRAM tells the player what the roll MEANS (Success / Fail), there might be a problem with the OGL.

I was just trying to let you know so that no one gets on the wrong side of wizards and they come around knocking.

Sorry for any confusion :o

Tom

Thore_Ironrock
December 6th, 2007, 23:22
Sorry for the confusion :o . I'm not a lawyer or anything, I have just been looking into it as I am writing a ruleset based on the OGL mongoose runequest rules, and have had to read over and try to understand wizards FAQ

Tom,

FYI ... Runequest is not OGL in the way d20 is; it is a publisher-to-publisher license that Mongoose is being allowed to distribute. I know, I've spoken directly to Matt Sprange about it. The Runequest "OGL licensing" is a bit deceptive at first glance. Mongoose has the final say in anything RQ related right now. When I asked Matt about Runequest I was told "not at this time" for any software-related products. That was a year ago.

Sakusammakko
April 17th, 2010, 19:04
I feel really late to the game on this, but I've just implemented this code for the C&C ruleset and it works really well. I had always wondered why it wasn't possible to double-click certain rolls.

Now I don't care why it was never added, I've done it myself! With your help, of course.

Thank you very much for helping to make our gaming experience better.