Hydrotronics

Custom Mob Loot for Minecraft

May 12th, 2019
828
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.51 KB | None | 0 0
  1.  
  2. function string.split(str, spl)
  3.     if spl == nil then
  4.         spl = "%s"
  5.     end
  6.     local tab = {}
  7.     for s in string.gmatch(str, "([^"..spl.."]+)") do
  8.         table.insert(tab, s)
  9.     end
  10.     return tab
  11. end
  12.  
  13. mobcount = 0
  14. mobs = {}
  15. local lts = fs.list("plugins/loottables")
  16. for _,entity in pairs(lts) do
  17.     local mob = {}
  18.     mob["Name"] = entity
  19.     mob["Data"] = {}
  20.     local file = fs.open("plugins/loottables/"..entity,"r")
  21.     local line = file.readLine()
  22.     while line do
  23.         local dets = string.split(line, " ")
  24.         local data = {}
  25.         data["Item"] = dets[1]
  26.         data["Count"] = tonumber(dets[2])
  27.         data["Meta"] = tonumber(dets[3])
  28.         data["Chance"] = tonumber(dets[4])
  29.         table.insert(mob["Data"], data)
  30.         line = file.readLine()
  31.     end
  32.     mobs[entity] = mob
  33.     mobcount = mobcount + 1
  34.     print("Loaded Entity #"..mobcount..": "..entity)
  35. end
  36. print("Loaded "..mobcount.." mobs")
  37.  
  38. parallel.waitForAny(function()
  39.     local c = 0
  40.     while true do
  41.         if c > 10000 then
  42.             c = 0
  43.             sleep(0)
  44.         else
  45.             c = c + 1
  46.         end
  47.        
  48.         for _,tag in pairs(mobs) do
  49.             if commands.exec("testfor @e[type="..tag["Name"]..",tag=!enhanced]") then
  50.                 commands.exec("effect @e[type="..tag["Name"]..",tag=!enhanced] invisibility 100 0 true")
  51.                 local sumScript = ""
  52.                 local sumScript2 = ""
  53.                 local unused = 5
  54.                 for _,i in pairs(tag["Data"]) do
  55.                     unused = unused - 1
  56.                     sumScript = sumScript.."{Count:"..i["Count"]..",id:\""..i["Item"].."\"},"
  57.                     sumScript2 = sumScript2..i["Chance"].."F,"
  58.                 end
  59.                 for i = 1,unused do
  60.                     sumScript = sumScript.."{},"
  61.                     sumScript2 = sumScript2.."1F,"
  62.                 end
  63.                 sumScript = sumScript:sub(1,-2)
  64.                 sumScript2 = sumScript2:sub(1,-4)
  65.                 commands.exec("execute @e[type="..tag["Name"]..",tag=!enhanced] ~ ~ ~ /summon "..tag["Name"].." ~ ~ ~ {ArmorItems:["..sumScript.."],ArmorDropChances:["..sumScript2.."],Tags:[\"enhanced\"]}")
  66.                 commands.exec("gamerule doMobLoot false")
  67.                 commands.exec("kill @e[type="..tag["Name"]..",tag=!enhanced]")
  68.                 commands.exec("gamerule doMobLoot true")
  69.             end
  70.         end
  71.     end
  72. end,function()
  73.     print("Press any key to cancel")
  74.     os.pullEvent("key")
  75. end)
Advertisement
Add Comment
Please, Sign In to add comment