• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Concept] Dynamic Maps

as I really like the idea which you brought up here, I have a little present for you guys :)
I've lately been working on a safe way to execute big loops without lagging or crashing the server.
here is the result:

put those functions in compat.lua or functions.lua (depending what tfs you have)
Code:
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

here a practical use of the functions in a talkaction:
Code:
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
 
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 :)
 
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 :p
 
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 :p

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?
 
Well we did, test, on 100 x 100 = 10,000 SQMs and no lag at all, then we did 1000 x 1000 = 1,000,000 SQMs and that give a slight lag :p.
But as you can see on the video, where the instant part goes thats around 100/150x20/30 and did no lag at all, how to confirm check on ping its usually 150-300 cuz we are hosting on our houses and we live on the other side of the world off each others.
We haven't test max, but i guess that will go to when there is not enough ram to recreate, but then again Evil Hero released a safe way to do big ass loops without crashes :p
 
Last edited:
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?
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.

1000 x 1000 = 100,000 SQMs and that give a slight lag :p.
You complain about my mapping and I complain about your math skills XD
 
I have to give my congratulations to your guys, wonderfull team. And about the script, just perfect! Please more videos about it!
 
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.
 
And with instances I mean if a new map is generated, the players should be in different "phases" instead of creating a duplicate map for every team/player.
 
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.

Omg, wonderfull system man! You made it? Post some videos, pictures etc of the system!!!! Thx :D
 
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.

Sad thing i never knew cuz all PL serv ;c
 
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 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.

You can now create tiles using Game.createTiles() in TFS 1.0; makes things so much better now.
 
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 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 group :p
 
Here's the second test.
Done with instant creation (10k tiles a second)
The dimension of the map was 6 floors x 100x100 (60k tiles overall)
It took an overall of 8mb steady ram usage to keep it in.
Why does it show -3mb ram and such? because I clear ram once I start the loop to avoid causing lags.

If someone has a good piece with a lot of different borders and details to test it on, feel free to forward it to me, the more the merrier.
 
Oh my, what a script, really! Wonderfull! When you create a random map generator will be amazing!
 
- It's a way faster to generate area instead of copying existing sector.
- Sometimes quest structure may be placed on unreachable location or players may get stuck.
- Some details may block the path.

Currently my system works only on 1.0, but it's very easy to write for any TFS (3x "for" + addEvent(function, delay, dungeon_id, x, y, z))
All you need is a lot of math.random usages and creativity.

@Crypton3
4k lines to generate 5 dungeons with same cave design? It can be done in less than 2k lines easily.
 
Back
Top