DICE PACKS BUNDLE
Page 1 of 5 123 ... Last
  1. #1

    FG 2 LUA - Easy D20 skill/ability rolls

    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:

    Code:
    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">:

    Code:
    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">

    Code:
    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:
    Code:
    --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:

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

  2. #2

    Join Date
    Dec 2004
    Location
    Chicago-ish
    Posts
    2,234
    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

  3. #3
    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.

  4. #4

    Join Date
    Dec 2004
    Location
    Chicago-ish
    Posts
    2,234
    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

  5. #5
    Thats why you copy this into a d20 ruleset you rename. Leave the default one the same.

  6. #6
    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.

  7. #7
    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.

  8. #8
    Great script joshuha!

  9. #9
    Valarian's Avatar
    Join Date
    Mar 2007
    Location
    Worcestershire, UK
    Posts
    2,567
    Yay! Automatic die rolling as in GRIP. Thanks for this Joshuha
    Using Ultimate license - that means anyone can play.
    Valarian's Fantasy Grounds Rulesets

  10. #10
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
FG Spreadshirt Swag

Log in

Log in