Sign in to follow this  
Dias

MTA's engineReplace limit

Recommended Posts

I'm attempting to replace the entire Vice City map only using MTA. It does work flawlessly, the objects are replaced properly, also spawned in the right places but there seems to be some sort of MTA limitation. It seems not to be able to replace after 2000+ objects (I use a loop). After this sort of limit is reached, my client crashes and it gives me the error "MTA could not load ID(x) [ x = some id)

Does anybody know of this limitation? Is there a maximum ammount of objects we can replace by new ones in MTA?

Edit: I halted the loop to not go further of that said ID, and I successfuly manage to replace the first island of Vice City with no problems.

Share this post


Link to post

I do not know if there is a limit.

But if you want to replace 2000+ objects, it might be handy to process the data a little bit slower.

Create yourself a slow processing function.

You will get the best performance with: (clientside only)

  
local thisTable = {} 
local slowProcessingIndex = 1 
  
function slowProcessingFunction () 
  
local endLoopTime = getTickCount()+10 -- 10 ms = 100fps. 
  
repeat 
  
    local tableData = thisTable[slowProcessingIndex] 
  
    slowProcessingIndex = slowProcessingIndex+1 
until getTickCount() > endLoopTime or slowProcessingIndex > #thisTable 
  
if slowProcessingIndex > #thisTable then 
    removeEventHandler("onClientRender",root,slowProcessingFunction) 
end 
  
end 
  
addEventHandler("onClientRender",root,slowProcessingFunction) 

I see a lot of people messing with timers, but works 100 times better. Stable fps(depending on how large the mods are) and doesn't crash. I am using something similar with on my custom map loader and Dutch saying: "Het loopt als een trein" >(probably)> "It works/moves like a train".

Share this post


Link to post

I'm using routines for that already. The problem is that MTA seems not to be able to replace further more than those 2000 objects.

Share this post


Link to post

I know there is a object limit and I'm fairly sure there's also a limit on how many objects you may replace, believe I've read it somewhere on these forums. If you do some searching you might be able to find the thread.

If not one of the devs should be able to give a more accurate and helpful answer if they swing by. :)

Share this post


Link to post

How about replacing only the ones that are nearby? > Problem solved.

Share this post


Link to post

I wonder if that'll lag players with lower rigs, replacing the dff, col and txd of say.. 20 or 50 objects that just got streamed in is quite a slap on processing and render.

Share this post


Link to post

Using onClientElementStreamIn, will not give you the result you want.

And you have to uses the slow loading function for loading the objects.

What you want is assigning elements to a 2D grid of X(300) units.

local gridHolder = {} 
local gridSize = 300 
local objects = getElementsByType("object") 
for i=1,#objects do 
    local object = objects[i] 
    local x,y,z = getElementPosition(object) 
    local gridX = math.floor((x/gridSize)+0.5) 
    local gridY = math.floor((y/gridSize)+0.5) 
  
    local gridDataX = gridHolder[gridX] 
    if not gridDataX then 
         gridHolder[gridX] = {} 
         gridDataX = gridHolder[gridX] 
    end 
  
    local gridDataY = gridDataX[gridY] 
    if not gridDataY then 
        gridDataY[gridY] = {} 
        gridDataY = gridDataX[gridY] 
    end 
  
    gridDataY[#gridDataY+1] = getElementModel(object) 
end 

local gridsAroundPlayer = { 
    {0,0},--center 
    {0,-1},-- top 
    {1,-1},-- right/top 
    {1,0},-- right 
    {1,1},-- right/bottom 
    {0,1},-- bottom 
    {-1,1},-- left/bottom 
    {-1,0},-- left 
    {-1,-1}-- left/top 
} 
local loadedIds = {} 
local loadedGrids = {} 
local nextGridUpdate = 0 
addEventHandler("onClientRender",root, 
function () 
    local timeNow = getTickCount() 
    if timeNow > nextGridUpdate then 
        nextGridUpdate = timeNow+300 
  
        local playerX,playerY,playerZ = getElementPosition(localPlayer) 
  
        local gridX = math.floor((playerX/gridSize)+0.5) 
        local gridY = math.floor((playerY/gridSize)+0.5) 
        local newLoadedIds = {} 
        local loadingGridsNew = {} 
        for j=1,#gridsAroundPlayer do 
            local offSet = gridsAroundPlayer[j] 
            local gridX = gridX + offSet[1] 
            local gridY = gridY + offSet[2] 
            if not loadedGrids[gridX.."/".. gridY] then 
                local gridDataX = gridHolder[gridX] 
                if gridDataX then 
                    local gridDataY = gridDataX[gridY] 
                    if gridDataY then 
                        --  
                        -- gridDataY,                          
                        -- store every id inside: newLoadedIds[id]  
                        -- loadedIds[id] < make sure that id isn't placed in this variable. 
                        -- load mods on id... 
  
                        loadingGridsNew[gridX.."/".. gridY] = true 
                    end 
                end 
            end 
        end 
        for key, data in pairs(loadedGrids) do  
            if not loadingGridsNew[key] then 
                local gridDataX = gridHolder[gridX] 
                if gridDataX then 
                    local gridDataY = gridDataX[gridY] 
                    if gridDataY then 
                     
                    -- gridDataY,  
                    -- newLoadedIds < make sure the id isn't in this table. 
                    -- unload mods from id 
                    end 
                end 
            end 
        end 
        loadedGrids = loadingGridsNew 
        loadedIds = newLoadedIds 
    end 
end) 

This is not tested.

Share this post


Link to post

I still do not recommend you to do it that way. (with streamed in/out)

But make sure you freeze the player position when they spawn, till the process has been finished. :idea:

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.