Tabletop Simulator

Tabletop Simulator

View Stats:
Booplesnoots Aug 12, 2020 @ 4:18pm
Trying to add script to existing dice roller?
I have a scripted dice roller I like. I want to keep it but I want it to broadcast the the total of the roll of multiple dice. All it does is broadcast all the individual rolls in sequential order, but not the sum total of them all, which I would like it to do for DnD purposes.

Does anyone have a good script I can add and do you know where is best to add it? Or can I copy/paste it at the end? I know next to nothing about scripting aside from a bit of vocab like endgate, if/then, etc.

Thanks in advance for any help! <3
< >
Showing 1-6 of 6 comments
CaptainTenille Aug 12, 2020 @ 4:29pm 
This can easily be done. You can just use broadcastToAll(varA + varB + varC) where the variables are the dice to be added. Without any code to go off, this is really all the help I can provide.
Booplesnoots Aug 12, 2020 @ 4:42pm 
Originally posted by CaptainTenille:
This can easily be done. You can just use broadcastToAll(varA + varB + varC) where the variables are the dice to be added. Without any code to go off, this is really all the help I can provide.

That would be great if I understood how to properly start/end the process and where to place it, assuming it needs to be placed in a certain part of the script. There is also the issue of what to place in the script for it to understand the variables it is grabbing at any given time...
CaptainTenille Aug 12, 2020 @ 4:48pm 
Yup. Either start learning (it's not that difficult), or give us more information to work with.
Booplesnoots Aug 12, 2020 @ 4:57pm 
Originally posted by CaptainTenille:
Yup. Either start learning (it's not that difficult), or give us more information to work with.

I am using the scripted roller from this mod: https://steamcommunity.com/profiles/76561198025190893/myworkshopfiles/?appid=286160&browsefilter=mysubscriptions

and the broadcasting section of the script shows the pasted section below. I want to add something to make the rolled dice broadcast with a sum total at the end but I don't know what to add...

***********************************************************************************************

--Rolling


--Activates rolling process
function buttonClick_roll(_, rollerColor)
local dieOnPad = findDieOnPad()
if dieOnPad ~= nil then
if rollLock == false then
--Destroys old dice
buttonClick_clear(_, rollerColor)
--Spawns and rolls new nice
rollThisDieType(dieOnPad, rollerColor)
else
broadcastToColor("Please wait until the dice come to a complete stop before rolling again.", rollerColor, {1,1,1})
end
else
broadcastToColor("Place the die type you want to roll onto the pad and try again.", rollerColor, {1,1,1})
end
end

function rollThisDieType(dieOnPad, rollerColor)
function coroutine_rolling()
diceBeingRolled = {}
clearLock = true
rollLock = true
local angle = 360/howManyDice
for i=1, howManyDice do
local pos = findGlobalPosWithLocalDirection(self, distanceFromTool*self.getScale().x, angle*(i-1))
--Makes a duplicate of the die on the pad
local die = dieOnPad.clone({position=pos})
table.insert(diceBeingRolled, die)
--Gives it a random rotation and waits 1 frame for it to happen
die.setRotation(randomRotation())
coroutine.yield(0) coroutine.yield(0) coroutine.yield(0)

--Apply some rotational force in a random direction
--die.addTorque(randomRotation())
die.roll()

wait(0.05)
end
watchForDiceToStop(rollerColor)
return 1
end
startLuaCoroutine(self, "coroutine_rolling")
end



function watchForDiceToStop(rollerColor)
function coroutine_placing()
dieValueTable, rollString, totalRollValue = {}, "", 0
local angle = 360/howManyDice
local skillTest = 0
--Wait for dice to stop moving after their roll
for _, die in ipairs(diceBeingRolled) do
while die.resting == false do
coroutine.yield(0)
end
local rollValue = die.getValue()
local rollFace = die.getRotationValue()

totalRollValue = totalRollValue + rollValue
table.insert(dieValueTable, {die=die, val=rollValue, face=rollFace})
end
--Sort the dice by their .getValue() in ascending order
local sort_func = function(a,b) return a.val < b.val end
table.sort(dieValueTable, sort_func)

--Move the dice into order and/or prints
for i, entry in ipairs(dieValueTable) do
--Organizes dice
if organizeDice == true then
local pos = findGlobalPosWithLocalDirection(self, distanceFromTool*self.getScale().x, angle*(i-1))
pos.y = pos.y + 0.5
entry.die.setPositionSmooth(pos)
end
--Assembles print values
if i ~= 1 then rollString = rollString .. ", " end
rollString = rollString .. entry.face

end


if printResults == true then
broadcastToAll(Player[rollerColor].steam_name .. " rolled: " .. rollString, stringColorToRGB(rollerColor))
end

clearLock = false
rollLock = false

if autoCleanDelay ~= -1 then
Timer.create({
identifier="uniqueDelayName"..self.getGUID(),
delay=autoCleanDelay, function_owner=self, function_name="autoClearTimerFunction"
})
end

return 1
end
startLuaCoroutine(self, "coroutine_placing")
end

**********************************************************************************************
CaptainTenille Aug 12, 2020 @ 5:26pm 
Try this... replace the 4th "block" from the bottom with...

if printResults == true then
broadcastToAll(Player[rollerColor].steam_name .. " rolled: " .. rollString.."Total:".. totalRollValue, stringColorToRGB(rollerColor))
end
CaptainTenille Aug 12, 2020 @ 5:28pm 
If that doesn't work, I'll look at the mod itself. The mod link you gave is in your subscriptions, so it takes me to my subscriptions. What is the name of the mod?
Last edited by CaptainTenille; Aug 12, 2020 @ 5:29pm
< >
Showing 1-6 of 6 comments
Per page: 1530 50