Out-Feu

sleep.lua

Oct 2nd, 2024
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.93 KB | Gaming | 0 0
  1. --[[
  2.  
  3. SleepBot program
  4. By Out-Feu
  5.  
  6. version 2.2.0
  7.  
  8. Free to distribute/alter
  9. so long as proper credit to original
  10. author is maintained.
  11.  
  12. This program must be used on a chatty turtle.
  13.  
  14. The turtle must be placed in front of a ritual brazier.
  15. The ritual brazier must be right clicked when the turtle emit a redstone signal.
  16. Tablets of sunrise and tablets of moonfall must be placed inside the turtle inventory.
  17.  
  18. A Teru Teru Bozu can be placed on top of the turtle to change the weather.
  19. In that case, sunflowers and blue orchids must be placed inside the turtle inventory.
  20.  
  21. --]]
  22.  
  23. string.split = function(self)
  24.  local tab = {}
  25.  for str in self:gmatch("([^%s]+)") do
  26.   table.insert(tab, str)
  27.  end
  28.  return tab
  29. end
  30.  
  31. function canChangeTime()
  32.  local success, data = turtle.inspect()
  33.  return success and data.name == "ars_nouveau:ritual_brazier"
  34. end
  35.  
  36. function isRainning()
  37.  if env == nil then
  38.   return nil
  39.  end
  40.  return env.isRaining() or env.isThunder()
  41. end
  42.  
  43. function canChangeWeather()
  44.  local success, data = turtle.inspectUp()
  45.  return success and data.name == "botania:teru_teru_bozu"
  46. end
  47.  
  48. function setDay()
  49.  if useItem("ars_nouveau:ritual_sunrise") then
  50.   sendText("Le jour arrive dans quelques secondes")
  51.   sleep(15)
  52.  else
  53.   sendText("Je suis à court de 'Tablet of Sunrise' pour mettre le jour")
  54.  end
  55. end
  56.  
  57. function setNight()
  58.  if useItem("ars_nouveau:ritual_moonfall") then
  59.   sendText("La nuit arrive dans quelques secondes")
  60.   sleep(15)
  61.  else
  62.   sendText("Je suis à court de 'Tablet of Moonfall' pour mettre la nuit")
  63.  end
  64. end
  65.  
  66. function setClearWeather()
  67.  if isRainning() == false then
  68.   sendText("Il ne pleut pas")
  69.  elseif useItem("ars_nouveau:ritual_cloudshaping") then
  70.   sendText("La pluie va s'en aller")
  71.   sleep(15)
  72.  else
  73.   sendText("Je suis à court de 'Tablet of Cloudshaping' pour retirer la pluie")
  74.  end
  75. end
  76.  
  77. function setClear()
  78.  if isRainning() == false then
  79.   sendText("Il ne pleut pas")
  80.  elseif useItemUp("minecraft:sunflower") then
  81.   sendText("La pluie va s'en aller")
  82.  else
  83.   sendText("Je suis à court de 'Sunflower' pour retirer la pluie")
  84.  end
  85. end
  86.  
  87. function setRain()
  88.  if isRainning() == true then
  89.   sendText("Il pleut déjà")
  90.  else
  91.   repeat
  92.    if not useItemUp("minecraft:blue_orchid") then
  93.     sendText("Je suis à court de 'Blue Orchid' pour mettre la pluie")
  94.     return
  95.    end
  96.   until env == nil or isRainning() == true
  97.   if env == nil then
  98.    sendText("La pluie arrive peut-être (10% de chance)")
  99.   else
  100.    sendText("La pluie arrive")
  101.   end
  102.  end
  103. end
  104.  
  105. function useItem(item)
  106.  local slot = getItemSlot(item)
  107.  if slot == nil then
  108.   return false
  109.  end
  110.  turtle.select(slot)
  111.  turtle.place()
  112.  setRedstoneSignal(true)
  113.  sleep(1)
  114.  setRedstoneSignal(false)
  115.  return true
  116. end
  117.  
  118. function useItemUp(item)
  119.  local slot = getItemSlot(item)
  120.  if slot == null then
  121.   return false
  122.  end
  123.  turtle.select(slot)
  124.  turtle.placeUp()
  125.  return true
  126. end
  127.  
  128. function getItemSlot(item)
  129.  for slot = 1, 16 do
  130.   data =  turtle.getItemDetail(slot)
  131.   if data and data.name == item then
  132.    return slot
  133.   end
  134.  end
  135.  return nil
  136. end
  137.  
  138. function setRedstoneSignal(signal)
  139.  sides = redstone.getSides()
  140.  for k, side in pairs(sides) do
  141.   redstone.setOutput(side, signal)
  142.  end
  143. end
  144.  
  145. function isWhitelisted(player)
  146.  for _, wlplayer in pairs(whitelist) do
  147.   if wlplayer == player then
  148.    return true
  149.   end
  150.  end
  151.  return false
  152. end
  153.  
  154. function showWhitelist()
  155.  if whitelist == nil or next(whitelist) == nil then
  156.   sendText("La whitelist est vide.")
  157.   return
  158.  end
  159.  list = "Whitelist:"
  160.  for _, wlplayer in  pairs(whitelist) do
  161.   list = list .. "\n - " .. wlplayer
  162.  end
  163.  sendText(list)
  164. end
  165.  
  166. function showHelp(showItem)
  167.  local help = "Utilisation: " .. cmdPrefix .. " [option]\n"
  168.  help = help .. "Options:\n"
  169.  if canChangeTime() then
  170.   if not showItem then
  171.    help = help .. "'day' - Met le jour\n"
  172.    help = help .. "'night' - Met la nuit\n"
  173.    help = help .. "'clear' - Retire la pluie\n"
  174.   else
  175.    help = help .. "'day' - Utilise 1 'Tablet of Sunrise'\n"
  176.    help = help .. "'night' - Utilise 1 'Tablet of Moonfall'\n"
  177.    help = help .. "'clear' - Utilise 1 'Tablet of Cloudshaping'\n"
  178.   end
  179.  end
  180.  if canChangeWeather() then
  181.   if not showItem then
  182.    help = help .. "'weather clear' - Retire la pluie\n"
  183.    if env == nil then
  184.     help = help .. "'weather rain' - 10% de chance de mettre la pluie\n"
  185.    else
  186.     help = help .. "'weather rain' - Met la pluie\n"
  187.    end
  188.   else
  189.    help = help .. "'weather clear' - Utilise 1 'Sunflower'\n"
  190.    if env == nil then
  191.     help = help .. "'weather rain' - Utilise 1 'Blue Orchid'\n"
  192.    else
  193.     help = help .. "'weather rain' - Utilise en moyenne 10 'Blue Orchid'\n"
  194.    end
  195.   end
  196.  end
  197.  if not showItem then
  198.   if enableWhitelist then
  199.    help = help .. "'whitelist' - Affiche les joueurs pouvant utilser la commande '" .. cmdPrefix .. "'\n"
  200.   end
  201.   help = help .. "'help' - Affiche cette aide\n"
  202.   help = help .. "'help item' - Affiche les ressources utilisées par les commandes"
  203.  else
  204.   help = help:sub(1, -2)
  205.  end
  206.  sendText(help)
  207. end
  208.  
  209. function sendText(text)
  210.  chat.sendMessage(text, name)
  211. end
  212.  
  213. -------------------------------------------------------------------------------
  214.  
  215. per = peripheral.getNames()
  216. for k, v in pairs(per) do
  217.  if peripheral.getType(v) == "chatBox" then
  218.   chat = peripheral.wrap(v)
  219.  elseif peripheral.getType(v) == "environmentDetector" then
  220.   env = peripheral.wrap(v)
  221.  end
  222. end
  223. per = nil
  224.  
  225. if chat == nil then
  226.  term.setTextColor(colors.red)
  227.  print("Chat box not found")
  228.  term.setTextColor(colors.white)
  229.  return
  230. end
  231.  
  232. name = "SleepBot" -- Name displayed in chat
  233. cmdPrefix = "!sleep" -- Prefix for the commands
  234. whitelist = {} -- Players who can use the command
  235. enableWhitelist = false -- Restic the command to whitelisted players
  236.  
  237. --------------------------------------------------------------------------------
  238. print("Hello, I am " .. name .. "!")
  239. print("'" .. cmdPrefix .. " help' for more informations.")
  240.  
  241. repeat --main loop
  242.  local event, player, message = os.pullEvent("chat")
  243.  args = message:split()
  244.  if table.getn(args) > 1 and args[1] == cmdPrefix then
  245.   if enableWhitelist and not isWhitelisted(player) then
  246.    sendText("Le joueur '" .. player .. "' n'a pas le droit d'utiliser la commande '" .. cmdPrefix .. "'.")
  247.   elseif args[2] == "help" then
  248.    showHelp(table.getn(args) > 2 and args[3] == "item")
  249.   elseif args[2] == "whitelist" then
  250.    showWhitelist()
  251.   elseif canChangeTime() and args[2] == "day" then
  252.    setDay()
  253.   elseif canChangeTime() and args[2] == "night" then
  254.    setNight()
  255.   elseif canChangeTime() and args[2] == "clear" then
  256.    setClearWeather()
  257.   elseif canChangeWeather() and table.getn(args) > 2 and args[2] == "weather" and args[3] == "clear" then
  258.    setClear()
  259.   elseif canChangeWeather() and table.getn(args) > 2 and args[2] == "weather" and args[3] == "rain" then
  260.    setRain()
  261.   else
  262.    sendText("Option invalide, '".. cmdPrefix .." help' pour plus d'informations.")
  263.   end
  264.  end
  265. until false
Advertisement
Add Comment
Please, Sign In to add comment