Advertisement
Skymagnum

Untitled

May 10th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.09 KB | None | 0 0
  1. function removeFromTable(table, pos)
  2.    local new = {}
  3.    for i, v in pairs(table) do
  4.       if not (v.pos.x == pos.x and v.pos.y == pos.y and v.pos.z == pos.z) then
  5.           new[i] = v
  6.       end
  7.    end
  8.    
  9.    return new
  10. end
  11.  
  12.  
  13. function print_table(self) -- by MaXwEllDeN
  14.         local str = "{"
  15.  
  16.         for i, v in pairs(self) do
  17.                 local index = type(i) == "string" and "[\"".. i .. "\"]" or "[".. i .. "]"
  18.                 local value = type(v) == "table" and print_table(v) or type(v) == "string" and "\"".. v .. "\"" or tostring(v)
  19.  
  20.                 str = str .. index .. " = ".. value .. ", "
  21.         end
  22.  
  23.         return (#str > 1 and str:sub(1, #str - 2)) .. "}"
  24. end
  25.  
  26. function onUse(cid, item, fromPosition, itemEx, toPosition)
  27.  
  28. local arvores = {
  29. [SEMENTE] = {arvore = arvore, tempo = tempo},
  30. }
  31.  
  32.     local file = io.open("/file/file", "a+")
  33.     local semeable = {Tiles que são semeaveis}
  34.     local semead = Tile que vira quando esta semeado
  35.     local arv = arvores[itemEx.itemid]
  36.  
  37.     if isInArray(semeable, itemEx.itemid)
  38.        addEvent(doCreateItem, arv * tempo, item.itemid, toPosition)
  39.        doCreateItem(semead, toPosition)
  40.        doCreateItem(arv.arvore, toPosition)
  41.        local content = file:read("*all")
  42.        local item_info = {id = arv.arvore, pos = {x = toPosition.x, y = toPosition.y, z = toPosition.z}}
  43.        file:write(content .. ", ".. print_table(item_info))
  44.        local file2 = io.open("/file/file", "r")
  45.        local content2 = loadstring("return ".. file2:read("*all")()
  46.        file2:close()
  47.  
  48.        local file3 = io.open("/file/file", "w+")
  49.        addEvent(file3:write, arv.tempo * 1000, print_table(removeFromTable(content2, {x = toPosition.x, y = toPosition.y, z = toPosition.z})))
  50.        addEvent(file3:close(), arv.tempo * 1000)
  51.     end
  52.  
  53.     return true
  54. end
  55.  
  56. function onStartup()
  57.  
  58. local file = io.open("/file/file", "r")
  59.  
  60.     local content = file:read("*all")
  61.     local itens = loadstring("return {".. content .. "}")()
  62.  
  63.     for _, v in pairs(itens) do
  64.         doCreateItem(v.id, v.pos)
  65.     end
  66.  
  67.     return true
  68. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement