Ardem
August 1st, 2013, 13:39
I am sure this is an easy one for the genius in here but for the life of me I cannot figure it out.
I want to return the 'total' from a dice roll to the initiative total field.
charsheet_mail.xml
<number_charabilitybonus name="initiativetot">
<anchored>
<to>initiative</to>
<position>insidetopleft</position>
<offset>90,0</offset>
<size>
<width>30</width>
<height>20</height>
</size>
</anchored>
<frame>
<name>modifier</name>
<offset>4,4,4,4</offset>
</frame>
<script>
function onInit()
super.onInit();
end
function onDoubleClick(x,y)
local result=1;
local mydata = window.getDatabaseNode();
ChatManager.d10Init(1,window.initiative.getValue() ,"Initiative",mydata);
end
</script>
</number_charabilitybonus>
chatmanager.lua
function d10Init(number, modifer, description, customData)
if control then
local result = 1;
local aDice = {}; -- Specifying Dice is an Arrary
local mydata = customData
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("initiative", aDice, modifer, description, customData); -- Throwing the dice in chatwindow
print(mydata)
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 totalinitiative(draginfo)
nTotal=0;
nMod=draginfo.getNumberData()
mydata=draginfo.customData()
local aDisplaydata = {}; -- Create Message Array
for i = 1, #(draginfo.getDieList()) do -- Gets the total number of dice in the list
nTotal = nTotal + draginfo.getDieList()[i].result; -- Adds the number of successes over the Target number
end
nTotal=nTotal + nMod;
DB.setValue(mydata,"number", nTotal) -- Displays Total in Field
aDisplaydata.text = "Initative";
aDisplaydata.font = "systemfont";
aDisplaydata.dice = draginfo.getDieList();
aDisplaydata.dicedisplay = 1;
aDisplaydata.diemodifier = draginfo.getNumberData()
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
I want to return the 'total' from a dice roll to the initiative total field.
charsheet_mail.xml
<number_charabilitybonus name="initiativetot">
<anchored>
<to>initiative</to>
<position>insidetopleft</position>
<offset>90,0</offset>
<size>
<width>30</width>
<height>20</height>
</size>
</anchored>
<frame>
<name>modifier</name>
<offset>4,4,4,4</offset>
</frame>
<script>
function onInit()
super.onInit();
end
function onDoubleClick(x,y)
local result=1;
local mydata = window.getDatabaseNode();
ChatManager.d10Init(1,window.initiative.getValue() ,"Initiative",mydata);
end
</script>
</number_charabilitybonus>
chatmanager.lua
function d10Init(number, modifer, description, customData)
if control then
local result = 1;
local aDice = {}; -- Specifying Dice is an Arrary
local mydata = customData
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("initiative", aDice, modifer, description, customData); -- Throwing the dice in chatwindow
print(mydata)
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 totalinitiative(draginfo)
nTotal=0;
nMod=draginfo.getNumberData()
mydata=draginfo.customData()
local aDisplaydata = {}; -- Create Message Array
for i = 1, #(draginfo.getDieList()) do -- Gets the total number of dice in the list
nTotal = nTotal + draginfo.getDieList()[i].result; -- Adds the number of successes over the Target number
end
nTotal=nTotal + nMod;
DB.setValue(mydata,"number", nTotal) -- Displays Total in Field
aDisplaydata.text = "Initative";
aDisplaydata.font = "systemfont";
aDisplaydata.dice = draginfo.getDieList();
aDisplaydata.dicedisplay = 1;
aDisplaydata.diemodifier = draginfo.getNumberData()
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