Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ComputerCraft D20 (or whatever-sided however-many dice)
- -- pastebin get ZYKQkUPB die
- local dx, dy = 3, 3
- local scr_x, scr_y = term.getSize()
- local vantage = 0
- local useQuips = false
- local dices = 1
- local range = {1,20} -- determines die size, basically random range
- local dice = {{0,512,512,8,8,512,512,0},{512,512,8,8,8,8,512,512},{2048,8,8,8,8,8,8,2048},{2048,512,8,8,8,8,512,2048},{0,2048,512,512,512,512,2048,0},{0,0,0,512,512,0,0,0}}
- local nums = { --numnumnum...
- [0] = {{1,1,1},{1,0,1},{1,0,1},{1,0,1},{1,1,1}},
- [1] = {{1,1},{0,1},{0,1},{0,1},{1,1,1}},
- [2] = {{1,1},{0,0,1},{0,1},{1},{1,1,1}},
- [3] = {{1,1},{0,0,1},{1,1},{0,0,1},{1,1,1}},
- [4] = {{1,0,1},{1,0,1},{1,1,1},{0,0,1},{0,0,1}},
- [5] = {{1,1,1},{1},{1,1,1},{0,0,1},{1,1,1}},
- [6] = {{1,1,1},{1},{1,1,1},{1,0,1},{1,1,1}},
- [7] = {{1,1,1},{0,0,1},{0,1},{0,1},{0,1}},
- [8] = {{1,1,1},{1,0,1},{0,1},{1,0,1},{1,1,1}},
- [9] = {{1,1,1},{1,0,1},{1,1,1},{0,0,1},{0,0,1}},
- }
- local quips = { --witty quips for your die!
- [1] = {"Rocks fall, everybody dies","You've ran out of dumb luck.","Goddamn it.","Hope you have a tampon for that stab wound.","Your dice hate you.","You miss and chop off your arm by mistake.","YOU HAVE NO CHANCE TO SURVIVE MAKE YOUR TIME .","HA HA HA HA ..."},
- [2] = {"Man, this sucks.","Let's hope that wasn't a dodge roll.","One is the loneliest number...","Stupid prime numbers.","That's as much as two ones. And that's terrible.","What is this, a roll for ants??"},
- [3] = {"Eh, this, uh, isn't good.","I hope that was a 'try to die' roll.","Honestly, two can be as bad as one.","Stupid primes."},
- [4] = {"TWO TIMES FOUR IS HALF OF SIXTEEN","You're a fifth there...!","Bad luck to all chinese players!"},
- [5] = {"You're a quarter there!","You are caught between vier and sechs.","Not a-good, no!","Stupid primes."},
- [6] = {"Your accuracy stat better be great.","Not as bad as it could've been...","Hahaha six sounds like sex hahaha."},
- [7] = {"A magical number...and it's mediocre.","I hate seven! Annoying to do math with.","Stupid primes."},
- [8] = {"gr8 m8 i r8 8/8","Eight. Eight. Eight.","Not a two, but...","It's a power of two, but..."},
- [9] = {"NEIN NEIN NEIN NEIN","You're getting there.","Your sword grazes the enemy!","Your sword glazes the enemy!"},
- [10] = {"Ooohhh, you're halfway there...","Four tens, and you've stolen a lot of cake.","...passable."},
- [11] = {"HEY IT'S A PALINDROME","Eleven is up there with 7 in terms of math.","Stupid primes."},
- [12] = {"Twelve...now THAT'S a number not to trifle with.","That's a solid number.","Good enought, I guess."},
- [13] = {"Stupid primes.","I'd call you unlucky, but this isn't a bad throw.","Amount of nobodies in Org. XIII"},
- [14] = {"What's worse than a seven? TWO sevens!!","Okay, now you're dealin' some damage","Statistically better than a 13."},
- [15] = {"Three quarters there!","You done pretty good for yourself!","Your sword stabs the enemy! YOU WIN!"},
- [16] = {"TWO TIMES FOUR IS HALF OF SIXTEEN","A nice, even power of two!","Fuck yes!","Hey, that's my age...","No cooler a number...besides "..range[2]},
- [17] = {"Goddamn primes!","Your arrow hits the orc from afar!","Hey-you're a lucky man!","Great scott!"},
- [18] = {"Your cleaver hits the ant, it drops 40 GOLD.","You perceive a small crack 600 feet away.","yay"},
- [19] = {"That's really good!","Don't despair! You've no need, honestly.","Noice.","Aren't you glad you're using CC?","Stupid primes."},
- [20] = {"You're a natural! (twenty)","Damn right!!","Nice...throw!","All your dreams...realized!","SMAAAAAAASH!!","You shot an ant from a mile away!","Fuck yeah!!","Eat shit, monster!!"},
- }
- local cwrite = function(txt,x,y)
- local _x,_y = term.getCursorPos()
- term.setCursorPos((x or math.ceil(scr_x/2))-(#txt/2),y or _y)
- write(txt)
- end
- local choice = function(input,verbose)
- if not input then
- input = "yn"
- end
- if verbose then
- write("[")
- for a = 1, #input do
- write(input:sub(a,a):upper())
- if a < #input then
- write(",")
- end
- end
- write("]?")
- end
- local evt,char
- repeat
- evt,char = os.pullEvent("char")
- until string.find(input:lower(),char:lower())
- if verbose then
- print(char:upper())
- end
- local pos = string.find(input:lower(),char:lower())
- return pos, char:lower()
- end
- local tc = function(value)
- if term.current().setVisible then
- term.current().setVisible(value)
- end
- end
- local render = function(x,y,number)
- tc(false)
- for a = 1, scr_y do
- term.setCursorPos(1,a)
- if a > scr_y/2 then
- term.setBackgroundColor(colors.brown)
- else
- term.setBackgroundColor(colors.yellow)
- end
- term.clearLine()
- end
- paintutils.drawImage(dice,x-dx,y-(dy-1))
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.lightBlue)
- cwrite(tostring(number),x+1,y)
- term.setCursorPos(1,scr_y-3)
- term.setBackgroundColor(colors.brown)
- term.setTextColor(colors.white)
- print("(1) "..range[2].." sides")
- print("(2) "..dices.." dice")
- write("(3) ")
- if vantage == 0 then
- write("Adds all dice")
- elseif vantage == 1 then
- write("Advantage")
- elseif vantage == -1 then
- write("Disadvantage")
- end
- tc(true)
- end
- local displayNum = function(number)
- local x,y = term.getCursorPos()
- local len = 4
- for a = 1, #tostring(number) do
- local n = tonumber(tostring(number):sub(a,a))
- if nums[n] then
- paintutils.drawImage(nums[n],x,y)
- x = x + len
- end
- end
- end
- local flash = function(times)
- local bg = term.getBackgroundColor()
- local flashes = {
- colors.black,
- colors.gray,
- colors.red,
- colors.lightGray,
- colors.white,
- colors.red,
- colors.gray,
- }
- for a = 1, times do
- for b = 1, #flashes do
- term.setBackgroundColor(flashes[b])
- term.clear()
- sleep(0)
- end
- end
- term.setBackgroundColor(colors.black)
- term.clear()
- sleep(0)
- term.setBackgroundColor(bg)
- end
- --os.queueEvent("key", keys.space)
- render(scr_x/2,-6,"")
- local lastnum
- local outcome
- while true do
- local evt, key = os.pullEvent()
- if (evt == "key" and (key == keys.space or key == keys.enter) or evt == "mouse_click") then
- if vantage == 0 then
- outcome = 0
- else
- outcome = {}
- end
- for d = 1, dices do
- for a = -2, math.floor(scr_y/2) do
- lastnum = math.random(range[1],range[2])
- render(scr_x/2,a,lastnum)
- sleep(0)
- end
- lastnum = math.random(range[1],range[2])
- if vantage == 0 then
- outcome = outcome + lastnum
- else
- table.insert(outcome,lastnum)
- end
- render(scr_x/2,(scr_y/2)-1,lastnum)
- term.setCursorPos(scr_x/2-2,scr_y/2+3)
- term.setBackgroundColor(colors.brown)
- write("*tck*")
- end
- sleep(0)
- render(scr_x/2,(scr_y/2),lastnum)
- if vantage == 1 then
- outcome = math.max(unpack(outcome))
- elseif vantage == -1 then
- outcome = math.min(unpack(outcome))
- end
- if outcome == range[2]*dices then
- flash(2)
- render(scr_x/2,math.floor(scr_y/2),lastnum)
- end
- term.setBackgroundColor(colors.yellow)
- if useQuips and (range[2] == 20) then
- if quips[lastnum] then
- term.setTextColor(colors.black)
- cwrite(quips[lastnum][math.random(1,#quips[lastnum])],nil,2)
- end
- elseif range[2] == 6 then
- if dices == 3 then
- term.setTextColor(colors.black)
- cwrite("For krist's sake...",nil,2)
- end
- end
- term.setCursorPos((scr_x/2)-(#tostring(lastnum)*2)+2,scr_y-5)
- displayNum(outcome)
- elseif key == keys.q then
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- sleep(0)
- return lastnum
- elseif key == keys.one then
- render(scr_x/2,-6,"")
- term.setCursorPos(1,1)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.yellow)
- write("# of sides? ")
- sleep(0)
- range[2] = tonumber(read()) or range[2]
- render(scr_x/2,-6,"")
- sleep(0)
- elseif key == keys.two then
- render(scr_x/2,-6,"")
- term.setCursorPos(1,1)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.yellow)
- write("# of dice? ")
- sleep(0)
- dices = tonumber(read()) or dices
- if dices <= 0 then
- dices = 0
- elseif dices >= 100 then
- dices = 1
- end
- render(scr_x/2,-6,"")
- sleep(0)
- elseif key == keys.three then
- render(scr_x/2,-6,"")
- term.setCursorPos(1,1)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.yellow)
- print("(1) Advantage")
- print("(2) Disadvantage")
- print("(3) Add")
- local utt
- sleep(0)
- repeat
- uut = choice("123",false)
- until uut >= 1 and uut <= 3
- if uut == 1 then
- vantage = 1
- elseif uut == 2 then
- vantage = -1
- else
- vantage = 0
- end
- render(scr_x/2,-6,"")
- sleep(0.15)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement