Jump to content

Objects problem..


Feche1320

Recommended Posts

I am using my custom map object loader, load .map objects, send them to client and create them there, but I have this issue:

ByljUTp.jpg

No objects on the middle as you can see..

mcpcbQd.jpg

If I move around you can see that now objects load

dVig1DN.jpg

After moving again to the start position, objecs are now loaded.. is there any fix for this? creating objects server-side does the same thing.. thanks

Link to comment
  
-- This gets all objects, markers, spawnpoints 
-- getAll(resource, "object") 
-- getAll(resource, "spawnpoint") 
-- etc.. 
  
function getAll(res, name) 
    local idx = 0 
    local xml = xmlLoadFile(":" ..getResourceName(res).. "/meta.xml") 
    local child = xmlFindChild(xml, "map", idx) 
    if child and xml then 
        local mapsrc = xmlNodeGetAttribute(child, "src") 
        xmlUnloadFile(xml) 
        local map = xmlLoadFile(":" ..getResourceName(res).. "/" ..mapsrc) 
        if map then 
            local result = {} 
            local node = xmlFindChild(map, name, 0) 
            while node do 
                local row = {} 
                local attr = xmlNodeGetAttributes(node) 
                for k, v in pairs(attr) do 
                    row[k] = v 
                end 
                table.insert(result, row) 
                idx = idx + 1 
                node = xmlFindChild(map, name, idx) 
            end 
            -- Search for  
            if name == "object" then  
                local index = 0 
                local node = xmlFindChild(map, "track", index) 
                while node do 
                    outputDebugString("server_maps: found , loading..") 
                    local idx = 0 
                    local child = xmlFindChild(node, "object", idx) 
                    while child do  
                        local row = {} 
                        local attr = xmlNodeGetAttributes(child) 
                        for k, v in pairs(attr) do 
                            row[k] = v 
                        end 
                        table.insert(result, row) 
                        idx = idx + 1 
                        child = xmlFindChild(node, "object", idx) 
                    end 
                    index = index + 1 
                    node = xmlFindChild(map, "track", index) 
                end 
            end 
            xmlUnloadFile(map) 
            return result 
        end 
    end 
end 
  
-- Load new objects 
_objs = getAll(res, "object") 
triggerClientEvent("createMapObjects", root, _objs) 
  
-- Client side 
addEventHandler("createMapObjects", root, 
    function(_objs) 
        local id = nil 
        for i = 1, #_objs do 
            if _objs[i].collisions == "false" then 
                id = createObject(tonumber(_objs[i].model), tonumber(_objs[i].posX), tonumber(_objs[i].posY), tonumber(_objs[i].posZ), tonumber(_objs[i].rotX) or 0, tonumber(_objs[i].rotY) or 0, tonumber(_objs[i].rotZ) or 0, true) 
            else 
                id = createObject(tonumber(_objs[i].model), tonumber(_objs[i].posX), tonumber(_objs[i].posY), tonumber(_objs[i].posZ), tonumber(_objs[i].rotX) or 0, tonumber(_objs[i].rotY) or 0, tonumber(_objs[i].rotZ) or 0) 
            end 
            setElementDimension(id, tonumber(_objs[i].dimension) or 0) 
            setElementInterior(id, tonumber(_objs[i].interior) or 0) 
            setObjectScale(id, tonumber(_objs[i].scale) or 1.0) 
        end 
    end 
) 
  
-- And this gets triggered before loading a new map 
addEventHandler("deleteMapObjects", root, 
    function() 
        -- Destroy previous objects if exists 
        local o = 0 
        local objs = getElementsByType("object") 
        if #objs > 0 then 
            for i, tmp in ipairs(objs) do 
                destroyElement(tmp) 
                o = o + 1 
            end 
        end 
        outputDebugString("server_maps: " ..o.. " objects were destroyed.") 
    end 
) 
  

Link to comment
  • Moderators

@toxicsmoke11

Yes that is a bug, but that won't matter so much because the rounded numbers are accurate enough.

Also by not doing that(not convert to string), it saves you some bandwidth.

@Feche1320

I think it is more a kind of streamed in bug.

I have a sort of similar bug:

When I attach an object(with disable col) to my car. It will only be visible when I start driving.

(before moving it is only at the position I created it)

What if you force them to be not stream able and enabled that later?

https://wiki.multitheftauto.com/wiki/Se ... Streamable

It would be a logic explanation.

Link to comment

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...