Runnetty

PowerReg

May 26th, 2021 (edited)
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.loadAPI("accounts")
  2. a = accounts.getAccounts()
  3. local d={}
  4.  
  5. for i =1, #a do
  6. table.insert(d,#d+1,peripheral.wrap("energyDetector_"..a[i].modem))
  7. end
  8.  
  9. pTick=1000
  10. dollPerPTick=0.1
  11. function calcDeduction(a)
  12.     t=a
  13.     amount=0
  14.     while t >=pTick do
  15.         t=t-pTick
  16.         amount=amount+1
  17.     end
  18.     return ((1+dollPerPTick)*amount)-1    
  19. end
  20.  
  21. while true do
  22. a = accounts.getAccounts()
  23.     for i =1, #a do
  24.         if a[i].cash<=0 then
  25.             d[i].setTransferRateLimit(0)
  26.         else
  27.             d[i].setTransferRateLimit(900000)
  28.         end
  29.         a[i].FPT=d[i].getTransferRate()
  30.         a[i].used=a[i].used+a[i].FPT
  31.         if a[i].used>=pTick then
  32.         t = calcDeduction(a[i].used)
  33.             --if(a[i].cash-t>0) then
  34.                 a[i].cash=a[i].cash-t
  35.                 a[i].used=0
  36.            -- else
  37.           --      g=a[i].cash
  38.             --    a[i].cash=0
  39.                
  40.                
  41.            -- end
  42.         end
  43.        
  44.         accounts.updateAccount(a[i])  
  45.     end
  46.     sleep(0.5)
  47. end
Add Comment
Please, Sign In to add comment