Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function removeFromTable(table, pos)
- local new = {}
- for i, v in pairs(table) do
- if not (v.pos.x == pos.x and v.pos.y == pos.y and v.pos.z == pos.z) then
- new[i] = v
- end
- end
- return new
- end
- function print_table(self) -- by MaXwEllDeN
- local str = "{"
- for i, v in pairs(self) do
- local index = type(i) == "string" and "[\"".. i .. "\"]" or "[".. i .. "]"
- local value = type(v) == "table" and print_table(v) or type(v) == "string" and "\"".. v .. "\"" or tostring(v)
- str = str .. index .. " = ".. value .. ", "
- end
- return (#str > 1 and str:sub(1, #str - 2)) .. "}"
- end
- function onUse(cid, item, fromPosition, itemEx, toPosition)
- local arvores = {
- [SEMENTE] = {arvore = arvore, tempo = tempo},
- }
- local file = io.open("/file/file", "a+")
- local semeable = {Tiles que são semeaveis}
- local semead = Tile que vira quando esta semeado
- local arv = arvores[itemEx.itemid]
- if isInArray(semeable, itemEx.itemid)
- addEvent(doCreateItem, arv * tempo, item.itemid, toPosition)
- doCreateItem(semead, toPosition)
- doCreateItem(arv.arvore, toPosition)
- local content = file:read("*all")
- local item_info = {id = arv.arvore, pos = {x = toPosition.x, y = toPosition.y, z = toPosition.z}}
- file:write(content .. ", ".. print_table(item_info))
- local file2 = io.open("/file/file", "r")
- local content2 = loadstring("return ".. file2:read("*all")()
- file2:close()
- local file3 = io.open("/file/file", "w+")
- addEvent(file3:write, arv.tempo * 1000, print_table(removeFromTable(content2, {x = toPosition.x, y = toPosition.y, z = toPosition.z})))
- addEvent(file3:close(), arv.tempo * 1000)
- end
- return true
- end
- function onStartup()
- local file = io.open("/file/file", "r")
- local content = file:read("*all")
- local itens = loadstring("return {".. content .. "}")()
- for _, v in pairs(itens) do
- doCreateItem(v.id, v.pos)
- end
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement