Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Simple timer to update stats on screen.
- function getWireless()
- local peripherals = peripheral.getNames()
- local wirelessSide = nil
- local gotWireless = false
- for i=1, #peripherals do
- print("Checking " .. peripherals[i])
- if peripheral.getType(peripherals[i]) == "modem" then
- print("It is a Modem")
- if peripheral.call(peripherals[i],"isWireless") then
- print("It is also Wireless")
- wirelessSide = peripherals[i]
- gotWireless = true
- end
- end
- if gotWireless then
- break
- end
- end
- return wirelessSide
- 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 showStats(p)
- stats.setBackgroundColor(colors.black)
- stats.clear()
- stats.setCursorPos(2,3)
- stats.write("Conversion Rate: $1 equals " .. conversionRate .. " Credits")
- stats.setCursorPos(2,4)
- stats.write("Stand On The PIM Then Click Buttons To Use")
- if p then
- stats.setCursorPos(2,1)
- stats.write("Balance in Money: $" .. math.floor(p.balance/conversionRate) .. " Remaining Credits: " .. p.balance%conversionRate)
- stats.setCursorPos(2,2)
- stats.write("Player: " .. p.name)
- stats.setCursorPos(mW - string.len("Credits: " .. p.balance)- 1,2)
- stats.write("Credits: " .. p.balance)
- end
- end
- pim = peripheral.find("pim")
- m = peripheral.find("monitor")
- m.setTextScale(.5)
- mW,mH = m.getSize()
- stats = window.create(m,2,mH-3,mW-2,4)
- lastPlayerName = "pim"
- player = nil
- conversionRate = 10
- rednet.open(getWireless())
- server = 267
- showStats(nil)
- while true do
- timer = os.startTimer(.5)
- while true do
- _,eTimer = os.pullEvent("timer")
- if eTimer == timer then
- break
- end
- end
- print("got timer, getting player standing on the pim")
- -- Get player standing on pim and update monitor to display name and credits
- playerName = assert(pim.getInventoryName(),"PIM Seems to be missing or not wrapped")
- if playerName ~= "pim" then
- if lastPlayerName ~= playerName then
- lastPlayerName = playerName
- msg = getPlayer(playerName)
- -- continue if message was recieved back from server
- if msg ~=nil then
- player = textutils.unserialize(msg)
- print(player)
- showStats(player)
- end
- end
- else
- if lastPlayerName ~= "pim" then
- lastPlayerName = "pim"
- player = nil
- showStats(player)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment