Advertisement
Chaos_Cash

server API example

Mar 27th, 2025 (edited)
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.96 KB | None | 0 0
  1. -- This program is an example of how to use the server helper api, i might make a better documentation in the future but for now this is all you will get.
  2. -- This program turns on redstone output on the back of the computer if someon pays this computer 50 or more credits (with the "@computer pay" command). Then it pays the credits it got to the owner of the computer
  3.  
  4.  
  5.  
  6. os.loadAPI("server.lua")
  7. server.getOwner()
  8.  
  9.  
  10.     while true do
  11.     info1,info2,info3,info4 = os.pullEvent()
  12.    
  13.         if info1 == "rednet_message" then
  14.         local message = server.getMessageTable(info3)
  15.        
  16.             if message["action"] == "receivedPayment" and tonumber(message["amount"]) >= 50 then
  17.             server.pay(owner, message["amount"], "You have received " .. message["amount"] .. "c from your computer.")
  18.             redstone.setOutput("back",true)
  19.             sleep(5)
  20.             redstone.setOutput("back",false)
  21.             end
  22.            
  23.            
  24.             if message["action"] == "sendingOwner" then
  25.             owner = message["owner"]
  26.             end
  27.        
  28.         end
  29.        
  30.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement