WTF.Error
Member
- Joined
- Aug 8, 2007
- Messages
- 489
- Reaction score
- 10
function safeExecuteFunction(func, showPrint, cycleStep, cycleTime, callback)
cycle = 0
local startRam = collectgarbage("count")
local safeExecute = coroutine.create(func)
coroutine.resume(safeExecute, cycleStep)
local function keepAlive()
if coroutine.status(safeExecute) == "suspended" then
if showPrint then
print("cycle: ".. cycle)
print("----------")
print("start: ".. math.floor(startRam / 1000) .." mb ram")
print("----------")
print("current: ".. math.floor(currRam / 1000) .." mb ram")
print("----------")
print("difference: " .. math.floor((currRam - startRam) / 1000) .." mb ram")
print("----------")
end
addEvent(keepAlive, cycleTime)
coroutine.resume(safeExecute, cycleStep)
elseif coroutine.status(safeExecute) == "dead" then
cycle = nil
startRam = nil
currRam = nil
if type(callback) == "function" then
callback()
end
collectgarbage("collect")
if showPrint[2] then
print("end: ".. math.floor((collectgarbage("count") / 1000)) .." mb ram")
print("----------")
end
end
end
keepAlive()
end
function handleCycle(var, cycleStep)
currRam = collectgarbage("count")
if (var - cycle) == cycleStep then
cycle = var
coroutine.yield(cycleStep, cycle)
end
end
function onSay(cid, words, param)
local x = { t = {}, p = {}, z = {} }
local safeExecuteCallback = function()
x = nil -- I do this to clear the ram cache, cause atm the x table uses around 780mb ram, if we set it to nil and let the lua garbage collector clear the ram it'll go back to how it was before
end
local test = function(cycleStep)
for i = 1,650000000 do -- this would normaly crash your server or not let him respond :p
table.insert(x.t, 56496293840892394824230472347234823847234) -- we want to create a lot of ram usage, to emulate a high pressure on the server.
table.insert(x.p, 56496293840892394824230472347234823847234)
table.insert(x.z, 56496293840892394824230472347234823847234)
handleCycle(i, cycleStep)
-- i is the variable you use for the cycle handling (you have to use the same, as you use in the loop)
-- cycleStep will be auto handled as we set that already.
end
end
safeExecuteFunction(test, {true, true}, 100000, 100, safeExecuteCallback)
-- test is the function of the loop.
-- {true, true} means that it prints the progress and the end ram usage.
-- 100000 means that we put the loop on hold every 100000 cycles.
-- 100 means if the loop is on hold it'll take 100ms until he's restarted.
-- safeExecuteCallback is the function which is executed after the loop is done.
return true
end
atm it's just to copy a map part 1:1 and re create it somewhere else.Omg @Javiersin this function is amazing, is a talkaction @Evil Hero ? And why is generating the same map? Configured? The script generate random map?
I know the difficulty to create a script like this, and we will understand if you don't share with us! Rly
atm it's just to copy a map part 1:1 and re create it somewhere else.
Generating a completly random place takes a lot more effort and is not done with such an ease
Well taking under consideration that the server should be playable and there is no noticeable lag, I'd say around 1k SQM's a second is the max which is safe to go at the moment, I have to test more to give an exact ammount.Incredible script man, really, if you want help we are here to!
This fucntion you post here can execute like 100 SQM per second? What is the max?
You complain about my mapping and I complain about your math skills XD1000 x 1000 = 100,000 SQMs and that give a slight lag .
Something like my instance system?Random generated dungeons + instances = win.
Will be quite hard doh, but I've seen both instances and random generation around this forum already, someone just needs to combine them both.
Good luck guys.
Something like my instance system?
After 3 players enter the waiting room, the instance map starts generating. Every map is fully random It took me about ~4000 lines of code to write that system.
Something like my instance system?
After 3 players enter the waiting room, the instance map starts generating. Every map is fully random It took me about ~4000 lines of code to write that system.
I made something similar to this like 1+ year ago when everyone called it 'Instances'.
I made it using a TFS-Bug with doAreaCombatHealth function to create tiles in empty sqms. Checking every stackpos of a tile from the main map and inserting values inside tables.
I don't know how yours works as it's not in English, but with instances I mean something like in any MMORPG (WoW, Tera, you name it) where a lot of people can be in the same instance, just in different "dimensions". Hard to explain, but the server doesnt make a new map temporary for every groupSomething like my instance system?
After 3 players enter the waiting room, the instance map starts generating. Every map is fully random It took me about ~4000 lines of code to write that system.