Advertisement
kremnev8

Полицейский

Jan 26th, 2015
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 KB | None | 0 0
  1. local ami = peripheral.wrap("bottom")
  2. local commandBlock = peripheral.wrap("top")
  3. -------------------- Config ----------------------------------------------
  4. P1 = {x=21,y=70,z=235}
  5. P2 = {x=18,y=75,z=232}
  6. SpawnPos = {x=21,y=86,z=237}
  7. UTC = 3
  8. Admins = {"AlexCC","1Ridav","cyber01","gravityfolls",4}
  9. ---------------------------------------------------------------------------
  10.  
  11. local function GET(url)
  12.     local l = http.get(url)
  13.     if l then
  14.         local retValue = l.readAll()
  15.         l.close()
  16.         return retValue, true
  17.     else
  18.         return nil, false
  19.     end
  20.        
  21. end
  22.  
  23. function getWorldTime()
  24.     response, state = GET("http://www.timeapi.org/utc/in+" .. UTC .."+hours")
  25.     return string.sub(response, 1, 10)..'-'..string.sub(response, 12, 19)
  26. end
  27.  
  28. local function sayMsg(msg, userName)
  29.     commandBlock.setCommand("/tell "..userName.." "..msg)
  30.     commandBlock.runCommand()
  31. end
  32.  
  33. function pulse(Side,t)
  34. rs.setOutput(Side,true)
  35. sleep(t)
  36. rs.setOutput(Side,false)
  37. end
  38.  
  39. local function Offense(user_name, type_offense,Time)
  40. pulse("right",10)
  41. -- type here the punish:
  42.  
  43. end
  44.  
  45. function Check(ent)
  46. x,y,z = ent.getPosition()
  47. if (x>=P2.x and x<=P1.x) and (z>=P2.z and z<=P1.z) and (y>=P1.y and y<=P2.y) then
  48. return true
  49. else
  50. return false
  51. end
  52. end
  53.  
  54. function Statistic(user)
  55.  
  56. if fs.exists("offenders/" .. user) then
  57. f = fs.open("offenders/" .. user,"r")
  58. Read = f.readLine()
  59. f.close()
  60. sleep(0.3)
  61. f = fs.open("offenders/" .. user,"w")
  62. f.write(tostring(Read + 1))
  63. f.close()
  64. else
  65. f = fs.open("offenders/" .. user,"w")
  66. f.write(1)
  67. f.close()
  68. end
  69. end
  70.  
  71. function Log(user,Time,Type)
  72.  if fs.exists("log") then
  73.    f = fs.open("log","a")
  74.    f.writeLine(user .. " " .. Time .. " " .. Type)
  75.    f.close()
  76.  else
  77.    f = fs.open("log","w")
  78.    f.writeLine(user .. " " .. Time .. " " .. Type)
  79.    f.close()
  80. end
  81. end
  82.  
  83. function Tp(user,x,y,z)
  84.     commandBlock.setCommand("/tp "..user.." "..x.." "..y.." "..z)
  85.     commandBlock.runCommand()
  86. end
  87.  
  88. while true do
  89. AMI = {}
  90. AMI[1],AMI[2] = os.pullEvent()
  91.  
  92. if AMI[1] == "player_login" then
  93. Pl = ami.getPlayerByName(AMI[2])
  94. ent = Pl.asEntity()
  95. Find = Check(ent)
  96.  
  97. if Find then
  98. sleep(3)
  99. Time = getWorldTime()
  100. sayMsg("Offense, tp to spawn!",AMI[2])
  101. Tp(AMI[2],SpawnPos.x,SpawnPos.y,SpawnPos.z)
  102. Statistic(AMI[2])
  103. Log(AMI[2],Time,"Login into secured area")
  104. for i=1,Admins[5],1 do
  105. sayMsg("Warning! " .. Admins[i].. ", in bank offenders!",Admins[i])
  106. end
  107. Offense(AMI[2],"Login into secured area",Time)
  108.  
  109. end
  110. sleep(1)
  111. end
  112.  
  113. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement