Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ocs/apis/sensor")
- whitelist_items = {["Power Armor Chestplate"] = 1, ["Power Armor Boots"] = 1}
- whitelist_players = {richie3366 = 1, ralmn = 1, Elarcis = 1}
- --table.insert(whitelist, "Power Armor Chestplate", 1)
- --table.insert(whitelist, "Power Armor Boots", 1)
- s = sensor.wrap("front")
- p = peripheral.wrap("back")
- q = peripheral.wrap("top")
- function setTPActive(bool)
- redstone.setOutput("right", bool)
- end
- function openDoor()
- p.move(5, false, true)
- sleep(1.05)
- end
- function tryOpenDoor()
- pcall(openDoor)
- end
- function tryCloseDoor()
- pcall(closeDoor)
- end
- function closeDoor()
- q.callRemote("JAKJ_RIM_CarriageController_0", "move", 4, false, true)
- sleep(1.05)
- end
- function sendMessage(player, message)
- q.callRemote("chat_0", "tell", player, message)
- end
- function f(n)
- return math.floor(n)
- end
- function validCoords(l)
- return (f(l.X) == -2 and f(l.Y) == 1 and f(l.Z) == 1)
- end
- function isPlayer(e)
- return e.Name == "Player"
- end
- function isInventoryEmpty(inv)
- notempty = false
- for k_, v_ in pairs(inv) do
- if(v_.Name ~= "empty" and (not isWhitelistedItem(v_.Name))) then
- notempty = true
- end
- end
- return not notempty
- end
- function checkItemsAndPlayers()
- t_ = s.getTargets()
- nbPlayers = 0
- emptyInv = true
- for k_,v_ in pairs(t_) do
- if(isPlayer(v_)) then
- nbPlayers = nbPlayers+1
- emptyInv = isInventoryEmpty(v_.Inventory)
- end
- end
- return (emptyInv and (nbPlayers == 1))
- end
- function distance(from, to)
- xd = from.X - to.X
- yd = from.Y - to.Y
- zd = from.Z - to.Z
- return math.sqrt(xd*xd + yd*yd + zd*zd)
- end
- function getNBPlayersNear(pl, pos)
- t_ = s.getTargets()
- nbPlayers = 0
- for k_,v_ in pairs(t_) do
- if(isPlayer(v_)) then
- if(k_ ~= pl) then
- if(distance(pos, v_.Position) < 2) then
- nbPlayers = nbPlayers + 1
- end
- end
- end
- end
- return nbPlayers
- end
- function isWhitelistedItem(itemname)
- return (whitelist_items[itemname] == 1)
- end
- function isWhitelistedPlayer(pname)
- return (whitelist_players[pname] == 1)
- end
- tryOpenDoor()
- while true do
- t = s.getTargets()
- for k,v in pairs(t) do
- l = v.Position
- if(v ~= nil and v.Name == "Player" and validCoords(l)) then
- if isWhitelistedPlayer(k) then
- if(getNBPlayersNear(k, v.Position) > 0) then
- sendMessage(k, "Un joueur se trouve a moins de deux blocs de vous !")
- else
- setTPActive(true)
- sleep(0.05)
- setTPActive(false)
- break
- end
- end
- notempty = not isInventoryEmpty(v.Inventory)
- -- print(k)
- if(notempty) then
- sendMessage(k, "Inventaire non vide !")
- else
- closeDoor()
- if(checkItemsAndPlayers()) then
- print("TP : "..k)
- sendMessage(k, "Bienvenue, "..k..".")
- setTPActive(true)
- sleep(0.05)
- setTPActive(false)
- tryOpenDoor()
- else
- print("Filoutage : "..k)
- sendMessage(k, "Pas bien de filouter :p")
- tryOpenDoor()
- end
- end
- end
- sleep(0.25)
- end
- sleep(0.25)
- end
Advertisement
Add Comment
Please, Sign In to add comment