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