Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dieCount = 0
- dice = {}
- results = {}
- --This detects when a die6 is placed on the notecard and registers it.
- -- A die can only be registered once.
- function onCollisionEnter(collision_info)
- l_colObj = collision_info.collision_object
- if string.find(l_colObj.name, "Die_6") == nil then
- print("Can only register 6-sided dice")
- return
- end
- if dieCount > 0 then
- for i = 1, dieCount do
- if l_colObj.guid == dice[i].guid then
- print("This die is already registered!")
- return
- end
- end
- end
- dieCount = dieCount + 1
- extendResults()
- dice[dieCount] = l_colObj
- infiltrateDie(l_colObj)
- --l_colObj.colEnter = l_colObj.onCollisionEnter
- --print("dannach")
- --function l_colObj:onCollisionEnter (collision_info)
- -- print("Collsion")
- -- l_colObj.colEnter(collision_info)
- --end
- print("New die registered, " .. (dieCount) .. " dice registered")
- end
- function onLoad()
- refreshDescription()
- end
- function onDiceRolled(dice)
- dice.setVar("rolledRecently", true)
- end
- function infiltrateDie(die)
- stuffToAdd = "getObjectFromGUID(\"" .. self.getGUID() .. "\").call(\"onDiceRolled\", self)"
- die_script = die.getLuaScript()
- posi = string.find(die_script, "function onRandomize")
- if(posi != nil) then
- print(string.sub(die_script, posi, posi + 20))
- else
- die_script = die_script .. "\nfunction onRandomize() " .. stuffToAdd .. " end"
- die.setLuaScript(die_script)
- die.reload() --only call once!
- end
- end
- function update()
- if dieCount == 0 then
- return -- Returns when no die has been registered yet
- end
- if(dice[1].getVar("rolledRecently")) then
- if(dice[1].resting) then
- dice[1].setVar("rolledRecently", false)
- sum = 0
- for i = 1, dieCount do
- sum = sum + dice[i].getValue()
- end
- results[sum] = results[sum] + 1
- refreshDescription()
- end
- end
- end
- function extendResults()
- for i = ((dieCount-1)*6)+1, (6*dieCount) do
- results[i] = 0
- end
- end
- function refreshDescription()
- if dieCount == 0 then
- return
- end
- descr = ""
- for i = 1, (6*dieCount) do
- descr = descr .. i .. ": " .. results[i] .. "\n"
- end
- self.setDescription(descr)
- end
- function createBaseXml()
- height = 90 + (dieCount*40)
- xmlTable = {
- }
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement