PDA

View Full Version : Dice Rolls in FG Core 3.0



Ardem
August 8th, 2013, 12:57
Wow from something I understood into a mess, I looked at 3.5 and 4.0 D&D but it got some complex, it did my head in I could not track down the final path.

My old code which worked was like similar to 3.5 dice template for a dice rolling field. This all worked fine, but now trying to get it to work in the new ruleset control.throwdice does not seem to work. What is the new way of throwing dice into the chat window. I am stumped and 3.5 and 4.0 examples are so complex I seem to run around in circles.

Thanks for any help

mainchar.xml

<number_charabilitybonus name="strengthtot" source="abilities.strengthtot">
<anchored>
<to>strength</to>
<position>insidetopleft</position>
<offset>90,0</offset>
<size>
<width>30</width>
<height>20</height>
</size>
</anchored>
<script>
function onInit()
super.onInit();
end

function action(draginfo)
ChatManager.d10Check(window.strengthtot.getValue() ,ModifierStack.getSum(),"Strength Attribute Check",TargetStack.getValue());
end

function onDragStart(button, x, y, draginfo)
return action(draginfo);
end

function onDoubleClick(x,y)
return action();
end
</script>
</number_charabilitybonus>

Template.xml

<template name="number_charabilitybonus">
<number_linked>
<anchored>
<position>right</position>
<offset>9,0</offset>
<size>
<width>36</width>
</size>
</anchored>
<frame>
<name>modifier</name>
<offset>4,4,4,4</offset>
</frame>
<readonly />
<showemptywidget />
<rollable />
<displaysign />
<modifiersize>mini</modifiersize>
</number_linked>
</template>

chat_manager.lua

function d10Check(number, modifer, description, targetno)
if control then
local aDice = {}; -- Specifying Dice is an Arrary
for i = 1, number, 1 do -- Counting the number of dice to use
table.insert(aDice, "d10"); -- Using d10 in the Array
end
control.throwDice("tncheck", aDice, modifer, description, targetno); -- Throwing the dice in chatwindow
end
end

chat_chat.lua

function onDiceLanded(draginfo)
if draginfo.getType() == "tncheck" then
targetcheck(draginfo); -- Function to check to see number of successes on a Target Number
elseif draginfo.getType() == "initiative" then
totalinitiative(draginfo); -- Function to total initiative
end

if ChatManager.getDieRevealFlag() then
draginfo.revealDice(true);
end

local handler = ChatManager.getDiceHandler(draginfo);

if handler then
return handler(draginfo);
elseif draginfo.isType("dice") then
applyModifierStackToRoll(draginfo);
end
end

function targetcheck(draginfo)
nSuccess=0;
nTarget=draginfo.getCustomData()+draginfo.getNumbe rData(); -- Get Target Number and modifier
local aDisplaydata = {}; -- Create Message Array
for i = 1, #(draginfo.getDieList()) do -- Gets the total number of dice in the list
if draginfo.getDieList()[i].result > nTarget then -- Compares the die result against Target Number
nSuccess = nSuccess + 1; -- Adds the number of successes over the Target number
end
end
if nSuccess > 0 then
aDisplaydata.text = draginfo.getDescription() .. " has " .. nSuccess .. " Successes against a TN of " .. nTarget; -- Displays the Success Message
aDisplaydata.font = "systemfont";
else
aDisplaydata.text = draginfo.getDescription() .. " has failed against a TN of " .. nTarget; -- Displays Failed Message
aDisplaydata.font = "systemfont_red";
end

aDisplaydata.dice = draginfo.getDieList();


if User.isHost() then -- Adds whos is sending the Message, GM or Player
if ChatManager.getDieRevealFlag() then
aDisplaydata.dicesecret = false;
end
aDisplaydata.sender = GmIdentityManager.getCurrent();
else
aDisplaydata.sender = User.getIdentityLabel();
end
deliverMessage(aDisplaydata);
end

Moon Wizard
August 9th, 2013, 00:02
I'm assuming that you are talking about the v3.0 alpha and CoreRPG base layer that is currently in testing.

Let me know either way, so I can best help.

If using v3.0 CoreRPG layer, one quick note is to avoid overwriting manager scripts in the CoreRPG layer. (such as ChatManager) A lot fo the ChatManager functionality from older rulesets has been pulled into the base layer and changed significantly.

If you are just looking for a new function to throw dice, try Comm.throwDice, which does not require you to have the handle of a chatentry control.

Regards,
JPG

Ardem
August 9th, 2013, 02:21
thanks moon,

I am meaning corerpg v3.0, also not been overwriting, perhaps a few additions but not taking away from the code.


I will try comm.throwdice() go today and let you know will you be updating the reference code for v3, i know it is in alpha, but i mean after it is released.

thanks again.

Ardem
August 9th, 2013, 10:39
Comm.throwDice() is a winner.

I re-engineered the code and made sure it has minor impact on any 3.0 RPG Core (minor addition entry in chat_window for capture)

How ever I think there going to be need some hard core notes on how to use the inbuilt dice throwing in 3.0 RPG Core, to understand how to use the new dice rolling ability.

Even my 'go to man' Dakadin is still trying to process how it works, I am sure he will but if he is trying to figure it out I have limited chance hahhaha.

Thanks again Moon

Moon Wizard
August 9th, 2013, 18:27
Yes, the layered rulesets and the CoreRPG base layer is still changing a bit, so I haven't provided any documentation on best practices or calls to make in the core layer. For now, it's by example from the 3.5E and 4E rulesets.

Regards,
JPG

Dakadin
August 9th, 2013, 21:17
I haven't had time to look at it yet. Once I do, I will see what I can do to help you with it, Ardem.