Working with rolld, I've been able to get it to roll the extra type die and keep the top two. Gotta figure out how to add in a modifier now.
Printable View
Working with rolld, I've been able to get it to roll the extra type die and keep the top two. Gotta figure out how to add in a modifier now.
Darned frustrating, trying to find nMod strings among all that other stuff, hours later, going to bed with no luck.
Quote:
---
--- Initialization
---
local sCmd = "factwelve";
-- MoreCore v0.60
function onInit()
CustomDiceManager.add_roll_type(sCmd, performAction, onLanded, true, "all");
end
function onInit()
Comm.registerSlashHandler("factwelve", processRoll);
GameSystem.actions["factwelve"] = { bUseModStack = true };
ActionsManager.registerModHandler("factwelve", onMod)
ActionsManager.registerResultHandler("factwelve", onRoll);
-- send launch message
local msg = {sender = "", font = "emotefont"};
msg.text = "Factor12 Dice loaded. Type \"/factwelve ?\" for usage.";
ChatManager.registerLaunchMessage(msg);
end
---
--- This is the function that is called when the factwelve slash command is called.
--- The default value for sParams is equal to "2d12+1d4+0 1"
---
function processRoll(sCommand, sParams)
if not sParams or sParams == "" then
sParams = "2d12+1d4+0 1";
end
if sParams == "?" or string.lower(sParams) == "help" then
createHelpMessage();
else
local rRoll = createRoll(sParams);
ActionsManager.roll(nil, nil, rRoll);
end
end
---
--- This function creates the roll object based on the parameters sent in
---
function createRoll(sParams)
local rRoll = {};
rRoll.sType = "factwelve";
rRoll.nMod = 0;
rRoll.sUser = User.getUsername();
rRoll.aDice = {};
rRoll.aDropped = {};
-- If no number to drop is specified, we will assume it is 1
if(not sParams:match("(%d+)d([%dF]*)+(%d+)d([%dF]*)+(%d+)%s(%d+)") and sParams:match("(%d+)d([%dF]+(%d+)d([%dF]*)+(%d+)+)")) then
sParams = sParams .. " 1"
end
-- Now we check that we have a properly formatted parameter, or we set the sDesc for the roll with a message.
if not sParams:match("(%d+)d([%dF]*)+(%d+)d([%dF]*)+(%d+)%s(%d+)") then
rRoll.sDesc = "Parameters not in correct format. Should be in the format of \"2d12+#d#+# #\"";
return rRoll;
end
local sNum, sSize, tNum, tSize, aMod, sDrop = sParams:match("(%d+)d([%dF]+)+(%d+)d([%dF]*)+(%d+)%s(%d+)");
local count = tonumber(sNum);
local comp = tonumber(tNum);
local drop = tonumber(sDrop);
if (drop > count + comp) then
rRoll.sDesc = "You cannot drop more results than the number of dice being rolled.";
return rRoll;
end
while count > 0 do
table.insert(rRoll.aDice, "d" .. sSize);
-- For d100 rolls, we also need to add a d10 dice for the ones place
if sSize == "100" then
table.insert(rRoll.aDice, "d10");
end
count = count - 1;
end
while comp > 0 do
table.insert(rRoll.aDice, "d" .. tSize);
-- For d100 rolls, we also need to add a d10 dice for the ones place
if sSize == "100" then
table.insert(rRoll.aDice, "d10");
end
comp = comp - 1;
end
rRoll.nDrop = drop;
return rRoll;
end
---
--- This function first sorts the dice rolls in ascending order, then it splits
--- the dice results into kept and dropped dice, and stores them as rRoll.aDice
--- and rRoll.aDropped.
---
function dropDiceResults(rRoll)
if #(rRoll.aDice) < 2 then return rRoll end
local len = #(rRoll.aDice) or 0;
local drop = tonumber(rRoll.nDrop) or 0;
local dropped = {};
local kept = {};
table.sort(rRoll.aDice, function(a,b) return a.result < b.result end);
local count = 1;
while count <= len do
if count <= drop then
table.insert(dropped, rRoll.aDice[count]);
else
table.insert(kept, rRoll.aDice[count]);
end
count = count + 1;
end
rRoll.aDice = kept;
rRoll.aDropped = dropped;
return rRoll;
end
---
--- This function creates a chat message that displays the results.
---
function createChatMessage(rSource, rRoll)
local rMessage = ActionsManager.createActionMessage(rSource, rRoll);
if #(rRoll.aDice) > 0 then
rMessage.text = rMessage.text .. "[KEPT]";
for _,v in ipairs(rRoll.aDice) do
rMessage.text = rMessage.text .. " " .. v.result;
end
end
if #(rRoll.aDice) > 0 and #(rRoll.aDropped) > 0 then
rMessage.text = rMessage.text .. "\n";
end
if #(rRoll.aDropped) > 0 then
rMessage.text = rMessage.text .. "[DROPPED]";
for _,v in ipairs(rRoll.aDropped) do
rMessage.text = rMessage.text .. " " .. v.result;
end
end
return rMessage;
end
---
--- This function creates the help text message for output.
---
function createHelpMessage()
local rMessage = ChatManager.createBaseMessage(nil, nil);
rMessage.text = rMessage.text .. "The \"/factwelve\" command is used to roll a set of dice, removing a number of the lowest results.\n";
rMessage.text = rMessage.text .. "You can specify the number of dice to roll, the type of dice, and the number of results to be dropped ";
rMessage.text = rMessage.text .. "by supplying the \"/factwelve\" command with parameters in the format of \"#d#+#d#+# #\".";
rMessage.text = rMessage.text .. "If no parameters are supplied, the default parameters of \"2d12+1d4+0 1\" are used.";
Comm.deliverChatMessage(rMessage);
end
---
--- This is the callback that gets triggered after the roll is completed.
---
function onRoll(rSource, rTarget, rRoll)
rRoll = dropDiceResults(rRoll);
rMessage = createChatMessage(rSource, rRoll);
rMessage.type = "dice";
Comm.deliverChatMessage(rMessage);
end
I will have a look tomorrow.
What are some valid dice test strings - with different sized dice?
/factwelve 2d12+1d4+1 1
/factwelve 2d12+1d8+4 1
Really, anything in that setup works (except for the mod) like
/factwelve 3d6+2d8+1 2
will drop the lowest 2 dice but won't add in the 1 mod.
I'm also having a problem getting it to work as a macro inside the MoreCore character sheet, but that's probably a function of having to set up "factwelve" withe the sheet scripts?
thanks. followed that, but getting script error:
Script Error: [string "common/scripts/morecore_rolls/lua"]:80: attempt to concatenate 'sParams' (a nil value}
Hi !
First thanks for this great "rule pak";
We use it to play hackmaster and it work ok.
However since last update as a GM i have encounter a little problem: I can't open the Old character selection screen ?
Now, instead i've got a scrolling list who looks exactly like the NPC list. (no portrait of the character only their name).
I can open Character sheet from this list but I cannot "own" them, export or import them. Only the create and erase option are available when right clicking in this list.
For Player who join a game the "old" character selction screen open once at the beginning and if they close it we didn't find a way to open it again.
I guess there is a new function that i'm not aware of.
Thanks for the pak anyway it's great !
Yep - this is an issue on Test - it is fixed in my current build but it wont be ready for release until closer to the 18th.
PM me if you need it.