Max Networked Objects : 60

Hello,

I have been new to redm and resource development for a few weeks and I would like to create a trading gameplay with physics items, principle :

  • Create box and attach items (where items are commodities into box)

I would like to point out that this gameplay is already done locally and is functional.
But now when I want to manage the replication layer at network level I face some problems.

I need each box to be seen and grabbed by all players on the server.

To test the development i use:

  • Client/Player 1 with “%LOCALAPPDATA%\RedM\RedM.exe”
  • Client/Player 2 with “%LOCALAPPDATA%\RedM\RedM.exe -cl2”

Now , in my resource i create a chat command like this (client.lua):

TriggerEvent("chat:addSuggestion", "/create_boxes", "Creating some boxes", {})
RegisterCommand('create_boxes', function(source, args, rawCommand)

    local smodel = "box_model"

    local numObjects = 100
    local objModel = GetHashKey(smodel)
    local coords = { x = x_value, y = y_value, z = z_value }

    local isNetwork = true
    local bScriptHostObj = false
    local dynamic = false
    local p7 = false
    local p8 = false 
    
    for i = 1, numObjects do

        if i > 1 then            
            coords.z = coords.z + box_height
        end

        local box = CreateObject( objModel, coords.x, coords.y, coords.z, isNetwork , bScriptHostObj, dynamic, p7, p8)
        if box ~= 0 then
        
            Citizen.Trace("\tBox created : "..tostring(box).." "..tostring(i).."/"..tostring(numObjects).."\n")

            while not DoesEntityExist(box) do
                    Citizen.Wait(100)
            end

            Citizen.Trace("\t\t-EntityExist\n")

            -- persistance
            SetEntityAsMissionEntity(box, true, false)

           -- just to make sure the boxes are networked
            if not NetworkGetEntityIsNetworked(box) then
                repeat
                    NetworkRegisterEntityAsNetworked(box)
                    Citizen.Wait(100)
                until NetworkGetEntityIsNetworked(box)            
            end
            
            Citizen.Trace("\t\t-IsNetworked\n")

        else
            Citizen.Trace("\tERROR create : "..tostring(box).." "..tostring(i).."/"..tostring(numObjects).."\n")
        end

        Citizen.Wait(100)

    end

end)

After executing the command /create_boxes on client 1 this is what happens :

  • On Client 1 : 61 boxes are created , 60 boxes are networked
  • On Client 2 : 60 boxes are created , 60 boxes are networked

From GetMaxNumNetworkObjects - RedM Natives @ Unofficial Docs i can read :

Always returns 60

Then, my question

  • Can I achieve my game goal or is it impossible due to limitations as I need more than 60 items?

Thank you to those who take the time to read me.

1 Like

You can achieve your goal by writing your own synchronization logic to create and manage non-networked objects on each desired client. However, this can be a challenging task, especially for those new to RedM.

Instead, I recommend adhering to the 60-object limit and utilizing it within a separate Routing Bucket for specific players at specific times. This way, you can fully utilize the 60-object limit without conflicting with other scripts (or other trades, in the context of your gameplay scenario) that may also create objects and use this limit.

1 Like

Thank you very much for your answer, i will read about this.

1 Like

Within a new routing bucket, the player is placed into a separate world where they may not have reached the pool limit, allowing them to create new objects. For example, you can refer to this script: Bucket Interiors - 28 Players in Zone. It addresses a similar issue, but instead of an object limit, it deals with a limit of 32 visible players at the same time. The script uses routing buckets to partially solve the problem.

If created objects are networked, they will be created on first closest client server see.

It’s all client-side at the end:

the networking is essentially glorified peer-to-peer, with the server acting as relay

1 Like

Again, thank you very much for your time and your explanations.

This situation seems strange to me because if you create a non-networked object, it remains non-networked regardless of whether you attach it to something or not. Additionally, if the object is networked, it will exist on all clients within its radius (I don’t know the exact radius, but let’s assume it is 424.0 units, as in FiveM).

Could you send me the code so I can check this on my end?

https://github.com/Faroeste-Roleplay/frp-lua-rdr3-discontinued/blob/64664f05f1ad0eb9a2844ff05d8130506d755704/resources/%5BFAROESTE%5D/%5BSYSTEM%5D/frp_inventory/client_drop.lua#L169

https://github.com/Rexshack-RedM/rsg-inventory/blob/main/client/main.lua#L169

Thank’s i will take a look

Thanks,

I’ve tested it on my side - same issue. What is interesting - the cause of issue is native

GetClosestObjectOfType

After calling this native an object becomes ‘network-bugged’. Also object becomes known by server -side, despite it’s not visible for other players:

1 Like

Additional info about this issue already reported on cfx github:
https://github.com/citizenfx/fivem/issues/2833