Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --File: /cattech/serverops.lua
- chunkDataHash={}
- function coordinatesToChunkColumn(x, y, z)
- local chunkX = math.floor(x / 16)
- local chunkZ = math.floor(z / 16)
- return chunkX, chunkZ
- end
- function roundCoordinatesToChunkColumn(x,y,z)
- local rX = math.floor(x / 16) * 16
- local rZ = math.floor(z / 16) * 16
- return rX, rZ
- end
- function deltaTime(seconds)
- local currentTime = os.time()
- local newTime = currentTime + seconds/72
- return newTime
- end
- function deltaGameTime(seconds)
- local currentTime = os.time()
- local newTime = currentTime + seconds
- return newTime
- end
- function handleChunkLoad()
- for key, chnk in pairs(chunkDataHash) do
- local coord = chnk.chunkX .. " " .. chnk.chunkZ
- log("debug",key .. " | " .. chnk.added .. " " .. chnk.expires .. "<=?" .. deltaTime(0))
- if chnk.expires <= deltaTime(0) then
- executeCommand("/forceload remove " .. coord)
- chunkDataHash[key]=nil
- else
- if (chnk.added == 0) then
- chunkDataHash[key]["added"] = 1
- executeCommand("/forceload add " .. coord)
- end
- end
- end
- end
- function addChunkLoad(x, y, z, minutes)
- local chunkX, chunkZ = roundCoordinatesToChunkColumn(x, y, z)
- local coord = chunkX .. "x" .. chunkZ
- if not chunkDataHash[coord] then
- chunkDataHash[coord] = {}
- end
- chunkDataHash[coord].chunkX = chunkX
- chunkDataHash[coord].chunkZ = chunkZ
- chunkDataHash[coord].added = chunkDataHash[coord].added or 0
- chunkDataHash[coord].expires = deltaTime(minutes * 60)
- end
- function executeCommand(command)
- local success, err = pcall(function()
- commands.exec(command)
- end)
- if success then
- log("debug","Command: " .. command)
- else
- log("error","Error: " .. err)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement