richie3366

sas de contrôle du spawn

Aug 23rd, 2013
721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.34 KB | None | 0 0
  1. os.loadAPI("ocs/apis/sensor")
  2.  
  3. whitelist_items = {["Power Armor Chestplate"] = 1, ["Power Armor Boots"] = 1}
  4. whitelist_players = {richie3366 = 1, ralmn = 1, Elarcis = 1}
  5.  
  6. --table.insert(whitelist, "Power Armor Chestplate", 1)
  7. --table.insert(whitelist, "Power Armor Boots", 1)
  8.  
  9. s = sensor.wrap("front")
  10. p = peripheral.wrap("back")
  11. q = peripheral.wrap("top")
  12.  
  13. function setTPActive(bool)
  14.   redstone.setOutput("right", bool)
  15. end
  16.  
  17. function openDoor()
  18.   p.move(5, false, true)
  19.   sleep(1.05)
  20. end
  21.  
  22. function tryOpenDoor()
  23.   pcall(openDoor)
  24. end
  25.  
  26. function tryCloseDoor()
  27.   pcall(closeDoor)
  28. end
  29.  
  30. function closeDoor()
  31.   q.callRemote("JAKJ_RIM_CarriageController_0", "move", 4, false, true)
  32.   sleep(1.05)
  33. end
  34.  
  35.  
  36.  
  37. function sendMessage(player, message)
  38.  
  39.   q.callRemote("chat_0", "tell", player, message)
  40.  
  41. end
  42.  
  43. function f(n)
  44.   return math.floor(n)
  45. end
  46.  
  47. function validCoords(l)
  48.   return (f(l.X) == -2 and f(l.Y) == 1 and f(l.Z) == 1)
  49. end
  50.  
  51. function isPlayer(e)
  52.   return e.Name == "Player"
  53. end
  54.  
  55. function isInventoryEmpty(inv)
  56.   notempty = false
  57.   for k_, v_ in pairs(inv) do
  58.     if(v_.Name ~= "empty" and (not isWhitelistedItem(v_.Name))) then
  59.       notempty = true
  60.     end
  61.   end
  62.  
  63.   return not notempty
  64. end
  65.  
  66. function checkItemsAndPlayers()
  67.   t_ = s.getTargets()
  68.   nbPlayers = 0
  69.   emptyInv = true
  70.  
  71.   for k_,v_ in pairs(t_) do
  72.     if(isPlayer(v_)) then
  73.       nbPlayers = nbPlayers+1
  74.       emptyInv = isInventoryEmpty(v_.Inventory)
  75.     end  
  76.   end  
  77.  
  78.   return (emptyInv and (nbPlayers == 1))
  79.  
  80. end
  81.  
  82. function distance(from, to)
  83.   xd = from.X - to.X
  84.   yd = from.Y - to.Y
  85.   zd = from.Z - to.Z
  86.   return math.sqrt(xd*xd + yd*yd + zd*zd)
  87. end
  88.  
  89. function getNBPlayersNear(pl, pos)
  90.   t_ = s.getTargets()
  91.   nbPlayers = 0
  92.   for k_,v_ in pairs(t_) do
  93.     if(isPlayer(v_)) then
  94.       if(k_ ~= pl) then
  95.         if(distance(pos, v_.Position) < 2) then
  96.           nbPlayers = nbPlayers + 1
  97.         end
  98.       end
  99.     end
  100.   end
  101.  
  102.   return nbPlayers
  103. end
  104.  
  105. function isWhitelistedItem(itemname)
  106.   return (whitelist_items[itemname] == 1)
  107. end
  108.  
  109. function isWhitelistedPlayer(pname)
  110.   return (whitelist_players[pname] == 1)
  111. end
  112.  
  113.  
  114. tryOpenDoor()
  115.  
  116. while true do
  117.  
  118.   t = s.getTargets()
  119.  
  120.   for k,v in pairs(t) do
  121.    
  122.     l = v.Position
  123.     if(v ~= nil and v.Name == "Player" and validCoords(l)) then
  124.      
  125.       if isWhitelistedPlayer(k) then
  126.         if(getNBPlayersNear(k, v.Position) > 0) then
  127.          
  128.           sendMessage(k, "Un joueur se trouve a moins de deux blocs de vous !")
  129.          
  130.         else
  131.           setTPActive(true)
  132.           sleep(0.05)
  133.           setTPActive(false)
  134.           break
  135.         end
  136.       end
  137.      
  138.       notempty = not isInventoryEmpty(v.Inventory)
  139.     --  print(k)
  140.      
  141.      
  142.       if(notempty) then
  143.        
  144.         sendMessage(k, "Inventaire non vide !")
  145.        
  146.       else
  147.      
  148.         closeDoor()
  149.        
  150.         if(checkItemsAndPlayers()) then
  151.           print("TP : "..k)
  152.           sendMessage(k, "Bienvenue, "..k..".")
  153.           setTPActive(true)
  154.           sleep(0.05)
  155.           setTPActive(false)
  156.           tryOpenDoor()
  157.         else
  158.           print("Filoutage : "..k)
  159.           sendMessage(k, "Pas bien de filouter :p")
  160.           tryOpenDoor()
  161.         end
  162.        
  163.       end
  164.      
  165.     end
  166.     sleep(0.25)
  167.   end
  168.  
  169.  
  170.   sleep(0.25)
  171. end
Advertisement
Add Comment
Please, Sign In to add comment