Wergat

TableToNBT

Sep 18th, 2015
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.71 KB | None | 0 0
  1. function convertTableToNBT(t)
  2.  local function tableToNBT(t)
  3.   local function rll(s) return string.sub(tableToNBT(s),1,-2) end
  4.   local nbt = ""
  5.   for k,v in pairs(t) do
  6.    if(type(v)~="table")then
  7.     if(t[1]==nil)then
  8.      if(type(v)~="string")then nbt = nbt..k..":"..v..","
  9.      else nbt = nbt..k..":\""..v.."\"," end
  10.     else
  11.      if(type(v)~="string")then nbt = nbt..v..","
  12.      else nbt = nbt..v.."," end
  13.     end
  14.    elseif(type(v)=="table")then
  15.     if(v[1]~=nil)then nbt = nbt..k..":["..rll(v).."],"
  16.     else
  17.      if(type(k)~="number")then nbt = nbt..k..":{"..rll(v).."},"
  18.      else nbt = nbt.."{"..rll(v).."}," end
  19.     end end end
  20.   return nbt
  21.  end
  22.  return "{"..string.sub(tableToNBT(t),1,-2).."}"
  23. end
Advertisement
Add Comment
Please, Sign In to add comment