Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Slot machine
- "###########"
- "# STONERS #"
- "# SLOTS #"
- "###########"
- Goal: Create Slot machine with various rewards with rare chance to drop expensive items
- Drops:
- Low:
- Mid:
- High:
- _G["variable"]
- blood orb
- shuffle deck -
- load deck values to array
- until deck full
- choose random number between 1 and array length
- add card at chosen random number
- remove element at chosen random number
- (serverTime / id ) * numPulls
- --]]
- bgColor = colors.black
- multipliers = {
- "redTorch",
- "eye",
- "pick",
- "sword"
- }
- --[[
- Valid names for reels:
- "cow","mooshroom","creeper","pig","enderman","pigman","slime","chicken",
- "zombie","spider","brick","sBrick","snow","ice","grass","mycelium","redTorch",
- "eye","pick","sword"
- ]]--
- mobReel = {
- [1] = {
- "cow",
- "mooshroom",
- "creeper",
- "pig",
- "enderman",
- "pigman",
- "slime",
- "chicken",
- "zombie",
- "spider",
- "cow",
- "mooshroom",
- "creeper",
- "pig",
- "enderman",
- "pigman",
- "slime",
- "chicken",
- "zombie",
- "spider",
- "sword"
- },
- [2] = {
- "creeper",
- "slime",
- "pig",
- "zombie",
- "pigman",
- "cow",
- "enderman",
- "chicken",
- "spider",
- "mooshroom",
- "bow",
- "creeper",
- "slime",
- "pig",
- "zombie",
- "pigman",
- "cow",
- "enderman",
- "sword",
- "chicken",
- "spider",
- "mooshroom"
- },
- [3] = {
- "slime",
- "chicken",
- "mooshroom",
- "spider",
- "pig",
- "pigman",
- "creeper",
- "enderman",
- "cow",
- "zombie",
- "slime",
- "chicken",
- "mooshroom",
- "spider",
- "sword",
- "pig",
- "pigman",
- "creeper",
- "enderman",
- "cow",
- "zombie"
- }
- }
- reel = mobReel
- --[[
- ]]--
- -- all images
- slotImages = {
- ["blank"] = {
- {32768,32768,32768,32768,32768,32768,32768,32768,32768,32768},
- {32768,32768,32768,32768,32768,32768,32768,32768,32768,32768},
- {32768,32768,32768,32768,32768,32768,32768,32768,32768,32768},
- {32768,32768,32768,32768,32768,32768,32768,32768,32768,32768},
- {32768,32768,32768,32768,32768,32768,32768,32768,32768,32768},
- {32768,32768,32768,32768,32768,32768,32768,32768,32768,32768}
- },
- ["cow"] = {
- {16384,16384,16384,16384,1,1,256,16384,16384,16384},
- {32768,32768,16384,16384,1,256,16384,16384,32768,32768},
- {32768,32768,16384,16384,16384,16384,16384,16384,32768,32768},
- {16384,16384,16384,1,1,1,1,16384,16384,16384},
- {16384,16384,1,32768,256,256,32768,1,16384,16384},
- {16384,16384,1,256,256,256,256,1,16384,16384}
- },
- ["mooshroom"] = {
- {4096,4096,4096,4096,1,1,256,4096,4096,4096},
- {1,1,4096,4096,1,256,4096,4096,1,0},
- {32768,1,4096,4096,4096,4096,4096,4096,1,32768},
- {4096,4096,4096,1,1,1,1,4096,4096,4096},
- {4096,4096,1,32768,256,256,32768,1,4096,4096},
- {4096,4096,1,256,256,256,256,1,4096,4096}
- },
- ["creeper"] = {
- {32,8192,8192,8192,32,8192,32,8192,8192,32},
- {8192,32768,32768,32768,8192,8192,32768,32768,32768,8192},
- {32,32768,32768,32768,8192,32,32768,32768,32768,8192},
- {8192,8192,32,8192,32768,32768,8192,8192,32,8192},
- {32,8192,8192,32768,32768,32768,32768,32,8192,8192},
- {8192,32,8192,32768,32,8192,32768,8192,8192,32}
- },
- ["pig"] = {
- {64,64,64,64,64,64,64,64,64,64},
- {64,64,64,64,64,64,64,64,64,64},
- {64,32768,1,64,64,64,64,1,32768,64},
- {64,64,64,64,64,64,64,64,64,64},
- {64,64,64,4,64,64,4,64,64,64},
- {64,64,64,64,64,64,64,64,64,64},
- },
- ["enderman"] = {
- {32768,128,32768,32768,32768,32768,32768,32768,128,32768},
- {32768,32768,32768,128,32768,32768,128,32768,32768,32768},
- {32768,128,32768,32768,128,128,32768,32768,128,32768},
- {32768,1,64,1,32768,32768,1,64,1,32768},
- {128,32768,32768,128,32768,32768,128,32768,32768,128},
- {32768,32768,128,32768,32768,32768,32768,128,32768,32768}
- },
- ["pigman"] = {
- {1,1,1,32,16384,64,64,64,64,64},
- {1,12,32,16384,64,64,64,64,64,64},
- {32768,128,32,16384,64,64,64,64,1,32768},
- {1,1,1,4,16384,4,64,64,64,64},
- {1,32,32,1,32,16384,64,64,64,64},
- {32,16384,16384,16384,1,32,16384,64,64,64}
- },
- ["slime"] = {
- {32,32,32,32,32,32,32,32,32,32},
- {32,32768,32768,32768,32,32768,32768,32768,32,32},
- {32,32768,32768,32768,32,32768,32768,32768,32,32},
- {32,32,32,32,32,32,32,32,32,32},
- {32,32,32,32,32,32,32768,32768,32,32},
- {32,32,32,32,32,32,32,32,32,32}
- },
- ["chicken"] = {
- {32768,1,1,1,1,1,1,1,1,32768},
- {32768,1,32768,32768,1,1,32768,32768,1,32768},
- {32768,1,2,2,2,2,2,2,1,32768},
- {32768,32768,4096,4096,4096,4096,4096,4096,32768,32768},
- {32768,32768,32768,32768,16384,16384,32768,32768,32768,32768},
- {32768,32768,32768,32768,16384,16384,32768,32768,32768,32768}
- },
- ["zombie"] = {
- {8192,8192,8192,8192,8192,8192,8192,8192,8192,8192},
- {8192,8192,8192,8192,8192,8192,8192,8192,8192,8192},
- {8192,8192,8192,8192,8192,8192,8192,8192,8192,8192},
- {8192,32768,32768,32768,8192,8192,32768,32768,32768,8192},
- {8192,8192,8192,8192,32768,32768,8192,8192,8192,8192},
- {8192,8192,8192,8192,8192,8192,8192,8192,8192,8192}
- },
- ["spider"] = {
- {128,128,128,32768,32768,32768,32768,128,128,128},
- {128,16384,128,128,128,128,128,128,16384,128},
- {128,128,128,16384,128,128,16384,128,128,128},
- {32768,128,128,128,128,128,128,128,128,32768},
- {32768,32768,128,128,32768,32768,128,128,32768,32768},
- {128,128,128,32768,32768,32768,32768,128,128,128}
- },
- ["bricks"] = {
- {16384,16384,0,16384,16384,16384,16384,16384,16384,16384},
- {0,0,0,0,0,0,0,0,0,0},
- {16384,16384,16384,16384,16384,16384,0,16384,16384,16384},
- {16384,16384,16384,16384,16384,16384,0,16384,16384,16384},
- {0,0,0,0,0,0,0,0,0,0},
- {16384,16384,0,16384,16384,16384,16384,16384,16384,16384}
- },
- ["stoneBricks"] = {
- {256,256,128,256,256,256,256,256,256,256},
- {128,128,128,128,128,128,128,128,128,128},
- {256,256,256,256,256,256,128,256,256,256},
- {256,256,256,256,256,256,128,256,256,256},
- {128,128,128,128,128,128,128,128,128,128},
- {256,256,128,256,256,256,256,256,256,256}
- },
- ["snow"] = {
- {0,0,0,0,0,0,0,0,0,0},
- {4096,0,0,0,0,0,4096,4096,0,4096},
- {4096,4096,4096,0,4096,4096,4096,4096,4096,4096},
- {4096,4096,4096,4096,4096,4096,4096,4096,4096,4096},
- {4096,4096,4096,4096,4096,4096,4096,4096,4096,4096},
- {4096,4096,4096,4096,4096,4096,4096,4096,4096,4096}
- },
- ["ice"] = {
- {8,8,8,8,8,8,8,8,8,8},
- {8,8,0,8,8,8,0,8,8,8},
- {8,8,8,0,8,8,8,0,8,8},
- {8,0,8,8,8,8,8,8,8,8},
- {8,8,0,8,8,8,8,8,8,8},
- {8,8,8,8,8,8,8,8,8,8}
- },
- ["grass"] = {
- {8192,8192,8192,8192,8192,8192,8192,8192,8192,8192},
- {8192,8192,8192,8192,8192,8192,8192,8192,8192,8192},
- {8192,8192,8192,8192,8192,8192,8192,8192,8192,8192},
- {8192,8192,8192,8192,8192,8192,8192,8192,8192,8192},
- {8192,8192,8192,8192,8192,8192,8192,8192,8192,8192},
- {8192,4096,4096,4096,4096,8192,8192,8192,4096,4096}
- },
- ["mycelium"] = {
- {1024,1024,1024,1024,1024,1024,1024,1024,1024,1024},
- {1024,1024,1024,1024,1024,1024,1024,1024,1024,1024},
- {1024,1024,1024,1024,1024,1024,1024,1024,1024,1024},
- {1024,1024,1024,1024,1024,1024,1024,1024,1024,1024},
- {1024,1024,1024,1024,1024,1024,1024,1024,1024,1024},
- {1024,4096,4096,4096,4096,1024,1024,1024,4096,4096}
- },
- -- Multipli1er Images
- ["redstoneTorch"] = {
- {32768,32768,32768,16384,16384,16384,16384,32768,32768,32768},
- {32768,32768,16384,16384,16384,16384,16384,16384,32768,32768},
- {32768,32768,16384,16384,2,2,16384,16384,32768,32768},
- {32768,32768,32768,16384,4096,4096,16384,32768,32768,32768},
- {32768,32768,32768,32768,4096,4096,32768,32768,32768,32768},
- {32768,32768,32768,32768,4096,4096,32768,32768,32768,32768}
- },
- ["eyeOfEnder"] = {
- {32768,32768,2048,512,8192,8192,512,2048,32768,32768},
- {32768,2048,512,8192,32,32,8192,512,2048,32768},
- {2048,512,8192,32,32768,32768,32,8192,512,2048},
- {2048,512,8192,32,32768,32768,32,8192,512,2048},
- {32768,2048,512,8192,32,32,8192,512,2048,32768},
- {32768,32768,2048,512,8192,8192,512,2048,32768,32768}
- },
- ["pick"] = {
- {32768,32768,32768,512,512,512,32768,32768,32768,32768},
- {32768,32768,512,32768,4096,32768,512,32768,32768,32768},
- {32768,512,32768,32768,4096,32768,32768,512,32768,32768},
- {32768,32768,32768,32768,4096,32768,32768,32768,32768,32768},
- {32768,32768,32768,32768,4096,32768,32768,32768,32768,32768},
- {32768,32768,32768,32768,4096,32768,32768,32768,32768,32768}
- },
- ["sword"] = {
- {32768,32768,32768,32768,512,32768,32768,32768,32768,32768},
- {32768,32768,32768,32768,512,32768,32768,32768,32768,32768},
- {32768,32768,32768,32768,512,32768,32768,32768,32768,32768},
- {32768,32768,32768,32768,512,32768,32768,32768,32768,32768},
- {32768,32768,32768,256,256,256,32768,32768,32768,32768},
- {32768,32768,32768,32768,4096,32768,32768,32768,32768,32768}
- },
- ["bow"] = {
- {0,0,0,1,4096,0,0,0,0,0},
- {0,0,0,1,0,4096,0,0,0,0},
- {0,0,0,1,0,0,4096,0,0,0},
- {0,0,0,1,0,0,4096,0,0,0},
- {0,0,0,1,0,4096,0,0,0,0},
- {0,0,0,1,4096,0,0,0,0,0}
- },
- -- BG Images
- ["arrowl"] = {
- {2,2,0,0},
- {0,2,2,0},
- {0,0,2,2},
- {0,0,2,2},
- {0,2,2,0},
- {2,2,0,0}
- },
- ["arrowr"] = {
- {0,0,2,2},
- {0,2,2,0},
- {2,2,0,0},
- {2,2,0,0},
- {0,2,2,0},
- {0,0,2,2}
- },
- ["logo"] = {
- {0,0,16384,16384,16384,0,16384,16384,16384,0,16384,16384,16384,0,16384,16384,16384,0,16384,16384,16384,0,16384,16384,16384,0,16384,16384,16384},
- {0,0,16384,0,0,0,0,16384,0,0,16384,0,16384,0,16384,0,16384,0,16384,0,0,0,16384,0,16384,0,16384,0,0},
- {0,0,16384,16384,16384,0,0,16384,0,0,16384,0,16384,0,16384,0,16384,0,16384,16384,0,0,16384,16384,16384,0,16384,16384,16384},
- {0,0,0,0,16384,0,0,16384,0,0,16384,0,16384,0,16384,0,16384,0,16384,0,0,0,16384,16384,0,0,0,0,16384},
- {0,0,16384,16384,16384,0,0,16384,0,0,16384,16384,16384,0,16384,0,16384,0,16384,16384,16384,0,16384,0,16384,0,16384,16384,16384},
- {},
- {0,0,0,0,0,0,16384,16384,16384,0,16384,0,0,0,16384,16384,16384,0,16384,16384,16384,0,16384,16384,16384},
- {0,0,0,0,0,0,16384,0,0,0,16384,0,0,0,16384,0,16384,0,0,16384,0,0,16384,0,0},
- {0,0,0,0,0,0,16384,16384,16384,0,16384,0,0,0,16384,0,16384,0,0,16384,0,0,16384,16384,16384},
- {0,0,0,0,0,0,0,0,16384,0,16384,0,0,0,16384,0,16384,0,0,16384,0,0,0,0,16384},
- {0,0,0,0,0,0,16384,16384,16384,0,16384,16384,16384,0,16384,16384,16384,0,0,16384,0,0,16384,16384,16384}
- }
- }
- function toName(num,rnum)
- --print("Getting Name for reel " .. rnum .. " Position " .. num)
- if num > #reel[rnum] then
- num = num - #reel[rnum]
- --print("Too big, converted too " .. rnum)
- elseif num <= 0 then
- num = #reel[rnum] + num
- --print("Too small, converted too " .. rnum)
- end
- return reel[rnum][num]
- end
- function isMultiplier(num,rnum)
- name = toName(num,rnum)
- for i=1,#multipliers do
- if name == multipliers[i] then
- return true
- end
- end
- end
- function loadImage(s)
- return slotImages[s]
- end
- function drawImage(i,x,y)
- for j=1,#i do
- m.setCursorPos(x,y+j-1)
- for k=1,#i[j] do
- if i[j][k] == 0 then
- m.setBackgroundColor(bgColor)
- else
- m.setBackgroundColor(i[j][k])
- end
- m.write(" ")
- end
- end
- end
- function drawBG()
- m.setBackgroundColor(bgColor)
- m.clear()
- m.setCursorPos(1,1)
- -- Logo 27 long 11 high
- logo = loadImage("logo")
- drawImage(logo,logox,1+yspacing)
- m.setBackgroundColor(bgColor)
- showStats()
- local y = ((6 + yspacing) * 2) - 6 + topborder
- arrowl = loadImage("arrowl")
- local x = xspacing + sideborders - 5
- drawImage(arrowl,x,y)
- arrowr = loadImage("arrowr")
- x = ((10 + xspacing) * 3) + sideborders + 1
- drawImage(arrowr,x,y)
- end
- function draw(n1,n2,n3)
- nums = {n1,n2,n3}
- -- draw each reel
- for i=1,3 do
- local tnum = nums[i]
- --print("Drawing Reel " .. i .. " with value of " .. tnum)
- -- draw images to reels
- for j=1,3 do
- local x = ((10 + xspacing) * i) - 10 + sideborders
- local y = ((6 + yspacing) * j) - 6 + topborder
- local imname = toName(tnum + j - 2, i )
- --print("Drawing Image " .. j .. "- " .. imname .. " at X: " .. x.. " Y: " .. y)
- local timg = loadImage(imname)
- if timg == nil then
- --print("Image returned a nil value?!")
- end
- -- load and draw current random number image and images before and after it.
- drawImage( timg , x, y )
- m.setBackgroundColor(bgColor)
- end
- end
- end
- function showStats()
- m.setCursorPos(2,h-1)
- m.write("Stand On The PIM Then Click Screen To Play")
- if player.name then
- m.setCursorPos(2,h)
- m.clearLine()
- m.setCursorPos(2,h)
- m.write("Player: " .. player.name)
- m.setCursorPos(w - string.len("Credits: " .. player.balance)- 1,h)
- m.write("Credits: " .. player.balance)
- end
- end
- function tellResults(s,n)
- if s ~= "none" then
- local x = math.floor( (w/2 - 18) + .5)
- local y = ((6 + yspacing) * 3) + topborder + 1
- local amountx = math.floor( (w/2 - ( (string.len("+"..tostring(n))/2) * 6 ) ) + .5)
- local last = term.redirect(m)
- alphanumeric.stringToImg("WINNER",colors.red,x,y)
- alphanumeric.stringToImg("+"..tostring(n),colors.red,amountx,y + 6)
- term.redirect(last)
- end
- showStats()
- end
- function checkAPI()
- if not fs.exists("alphanumeric") then
- multishell.run("pastebin get YVtwWRBQ disk/alphanumeric")
- end
- end
- function modifyPlayer(p,num,t)
- print("Sending info for " .. p)
- rednet.send(server,"modify " .. p .. " " .. num .. " " .. t)
- local msg = nil
- local attempts = 1
- -- wait for message for 10 ticks retry 3 times
- repeat
- id,msg,proto = rednet.receive(.5)
- attempts = attempts + 1
- until msg or (attempts > 3 )
- if msg and id == server then
- print(msg)
- return textutils.unserialize(msg)
- end
- end
- function getPlayer(p)
- print("getting player info for " .. p)
- rednet.send(server,"get " .. p)
- local msg = nil
- local attempts = 1
- -- wait for message for 10 ticks retry 3 times
- repeat
- print("attempt " .. attempts)
- id,msg,proto = rednet.receive(.5)
- attempts = attempts + 1
- until msg or (attempts > 3 )
- if msg and id == server then
- print(msg)
- return msg
- else
- return nil
- end
- end
- function getWireless()
- local peripherals = peripheral.getNames()
- local wirelessSide = nil
- local gotWireless = false
- for i=1, #peripherals do
- if peripheral.getType(peripherals[i]) == "modem" then
- if peripheral.call(peripherals[i],"isWireless") then
- wirelessSide = peripherals[i]
- gotWireless = true
- end
- end
- if gotWireless then
- break
- end
- end
- return wirelessSide
- end
- -- Load Peripherals
- m = peripheral.find("monitor")
- pim = peripheral.find("pim")
- -- Define Constants
- pullCost = 5
- m.setTextScale(.5)
- w,h = m.getSize()
- logox = math.floor( (w - 27)/2 )
- xspacing = 2
- yspacing = 2
- slotwidth = 3 * (10 + xspacing)
- slotheight = 3 * (6 + yspacing)
- sideborders = math.floor((w - slotwidth )/2)
- topborder = (#slotImages["logo"] + yspacing) + 1
- server = 267
- tune = {1,5,8}
- -- Define Variables
- player = {}
- playerName = ""
- num1 = math.random(1,#reel[1])
- num2 = math.random(1,#reel[2])
- num3 = math.random(1,#reel[3])
- running = false
- if os.getComputerLabel() ~= "slot" then
- os.setComputerLabel("slot")
- end
- -- Pre Setup Functions
- rednet.open(getWireless())
- os.loadAPI("disk/alphanumeric")
- print("Size = w " .. w .. " h " .. h)
- print("Slot Width = " .. slotwidth )
- print("Border Size = " .. sideborders)
- print("Calculated Size = " .. sideborders * 2 + slotwidth)
- print("Computer ID = " .. os.getComputerID())
- print("Computer Label = " .. os.getComputerLabel())
- drawBG()
- draw(num1,num2,num3)
- -- Begin Logic Loop
- while true do
- -- Wait for a monitor touch event
- e,p1,p2,p3 = os.pullEvent()
- if e == "monitor_touch" then
- -- Check if slot is running already
- if not running then
- playerName = pim.getInventoryName()
- -- Make sure player is on PIM
- if playerName ~= "pim" then
- -- Get player info from server
- msg = getPlayer(playerName)
- -- continue if message was recieved back from server
- if msg ~=nil then
- player = textutils.unserialize(msg)
- print(player)
- -- make sure player has enough credits
- if player.balance >= pullCost or player.name == "BigD999" then
- -- begin slot pull
- player = modifyPlayer(player.name,pullCost*-1,"pull")
- running = true
- drawBG()
- print("Starting Randomizer")
- -- Spin cycle 1 - all three
- spin = math.random(30,50)
- local tuneIndex = 1
- for i=1,spin do
- num1 = num1 - 1
- num2 = num2 - 1
- num3 = num3 - 1
- if num1 < 0 then
- num1 = #reel[1]
- end
- if num2 < 0 then
- num2 = #reel[2]
- end
- if num3 < 0 then
- num3 = #reel[3]
- end
- --print(num1," ",num2," ",num3," ")
- draw(num1,num2,num3)
- sleep(.05)
- end
- -- Spin cycle 2 - reels 2 and 3
- spin = math.random(5,20)
- for i=1,spin do
- num2 = num2 - 1
- num3 = num3 - 1
- if num2 < 0 then
- num2 = #reel[2]
- end
- if num3 < 0 then
- num3 = #reel[3]
- end
- --print(num1," ",num2," ",num3," ")
- draw(num1,num2,num3)
- sleep(.05)
- end
- -- Spin cycle 3 - reel 3
- spin = math.random(5,20)
- for i=1,spin do
- num3 = num3 - 1
- if num3 < 0 then
- num3 = #reel[3]
- end
- --print(num1," ",num2," ",num3," ")
- draw(num1,num2,num3)
- sleep(.05)
- end
- -- Begin Result Checking
- print("Checking Results")
- amount = 0
- if toName(num1,1) == toName(num2,2) and toName(num2,2) == toName(num3,3) then
- -- three in a row
- if isMultiplier(num1,1) and isMultiplier(num2,2) and isMultiplier(num3,3) then
- -- JACKPOT!!!!
- result = "jackpot"
- amount = pullCost * 50
- print(result)
- else
- result = "three"
- print(result)
- amount = pullCost * 25
- end
- elseif toName(num1,1) == toName(num2,2) or toName(num2,2) == toName(num3,3) or toName(num1,1) == toName(num3,3) then
- -- We have a pair
- if isMultiplier(num1,1) or isMultiplier(num2,2) or isMultiplier(num3,3) then
- -- the pair contains a multiplier
- if (isMultiplier(num1,1) and isMultiplier(num2,2)) or ( isMultiplier(num2,2) and isMultiplier(num3,3) ) or ( isMultiplier(num1,1) and isMultiplier(num1,1) )then
- -- the pair is a pair of multipliers
- result = "pair++!"
- print(result)
- amount = pullCost * 4
- else
- result = "pair+"
- print(result)
- amount = pullCost * 4
- end
- else
- result = "pair"
- print(result)
- amount = pullCost * 2
- end
- elseif isMultiplier(num1,1) or isMultiplier(num2,2) or isMultiplier(num3,3) then
- result = "freespin"
- print(result)
- amount = pullCost
- else
- result = "none"
- print(result)
- end
- if amount > 0 then
- player = modifyPlayer(player.name,amount,"payoutSlots")
- end
- tellResults(result,amount)
- running = false
- else
- print("Player doesnt have enough money")
- showStats()
- end
- else
- print("Could not contact Mainframe!")
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment