Overkillz

Check if objects is already loaded

Recommended Posts

Hello dear community, today I would like to ask you if there is a way to check when the objects are totally loaded.

For example, the first things that I do is to remove world objects. Later, I created an amount of objects and set a cameraMatrix and at the end of it fade the camera to see it but while the camera is loading or is loaded, some objects are being loaded. What do I mean with loaded ? Objects goes from invisible to visible.

I wont use setTimer to delay the fadeCamera. Im just asking if there is a way to do it :)

for i=550,20000 do
	removeWorldModel(i,10000,0,0,0)
end
setOcclusionsEnabled(false)
setWaterLevel(-5000)     

for k,objects in ipairs(garageObjects) do -- garageObjects table is already defined and with values
	local a,b,c,d,e,f,g,h,i = unpack(objects)
	local object = createObject ( a,b,c,d,e,f,g )
	setObjectScale(object,h or 1)
	setElementDoubleSided(object, i or false )
	setElementDimension(object,arenaCDimension)
end
fadeCamera(true)

I hope you can bring me a hand with it.

 

EXTRA QUESTION: setGarageOpen function has already built some objects by default ? I mean objects like some wheels, vehicle parts ... or whatever

 

Thanks for reading, regards.

 

Edited by Overkillz

Share this post


Link to post

you can try to introduce tables, this way:

 

for i=550,20000 do
	removeWorldModel(i,10000,0,0,0)
end
setOcclusionsEnabled(false)
setWaterLevel(-5000)     

for k,objects in ipairs(garageObjects) do -- garageObjects table is already defined and with values
  	local loadedObjects = {}
	local a,b,c,d,e,f,g,h,i = unpack(objects)
	local object = createObject ( a,b,c,d,e,f,g )
    table.insert(loadedObjects, object)
	setObjectScale(object,h or 1)
	setElementDoubleSided(object, i or false )
	setElementDimension(object,arenaCDimension)
end
if (#loadedObjects >= #garageObjects) then
	fadeCamera(true)
  	loadedObjects = {}
 end

 

In this case, fadeCamera will be executed only when all the objects were created.

 

PS: setGarageOpen only opens the garage door.

Edited by UDC

Share this post


Link to post

@Overkillz

Objects will only be loaded when they are streamed in. This also means that they can be unloaded and reloaded.

 

for i=550,20000 do
	removeWorldModel(i,10000,0,0,0)
end
setOcclusionsEnabled(false)
setWaterLevel(-5000)     


local container = createElement("container")

local count = 0
local function elementCounter ()
	count = count + 1
	iprint("Streamed in: ", source, ", ", count, "/", #garageObjects)
end
addEventHandler("onClientElementStreamIn", container, elementCounter)


for k,objects in ipairs(garageObjects) do -- garageObjects table is already defined and with values
	local a,b,c,d,e,f,g,h,i = unpack(objects)
	local object = createObject ( a,b,c,d,e,f,g )
	
	setObjectScale(object,h or 1)
	setElementDoubleSided(object, i or false )
	setElementDimension(object,arenaCDimension)
	
	setElementParent(object, container) -- !important
end
fadeCamera(true)

 

Keep in mind that this doesn't mean that the texture has been loaded. It doesn't have to be painted to exist.

 


 

I recommend to use lowLOD objects instead, those will show up faster.

https://wiki.multitheftauto.com/wiki/SetLowLODElement

 

See this useful function:

https://wiki.multitheftauto.com/wiki/AssignLod

 

function assignLOD(element)
    local lod = createObject(getElementModel(element),0, 0 ,0, 0, 0, 0, true)
    setElementDimension(lod,getElementDimension(element))
    setElementPosition(lod, getElementPosition(element))
    setElementRotation(lod, getElementRotation(element))
    setElementCollisionsEnabled(lod,false)
    setLowLODElement(element,lod)
    return lod
end

 

  • Like 1

Share this post


Link to post
28 minutes ago, UDC said:

you can try to introduce tables, this way:

 


for i=550,20000 do
	removeWorldModel(i,10000,0,0,0)
end
setOcclusionsEnabled(false)
setWaterLevel(-5000)     

for k,objects in ipairs(garageObjects) do -- garageObjects table is already defined and with values
  	local loadedObjects = {}
	local a,b,c,d,e,f,g,h,i = unpack(objects)
	local object = createObject ( a,b,c,d,e,f,g )
    table.insert(loadedObjects, object)
	setObjectScale(object,h or 1)
	setElementDoubleSided(object, i or false )
	setElementDimension(object,arenaCDimension)
end
if (#loadedObjects >= #garageObjects) then
	fadeCamera(true)
  	loadedObjects = {}
 end

 

In this case, fadeCamera will be executed only when all the objects were created.

 

PS: setGarageOpen only opens the garage door.

In fact there is not any different between your code and mine one.

Adding the objects into another table doesn't guarantee you that the objects is loaded.

Share this post


Link to post

@IIYAMA
I've just tried it and practically I can't apreciate the difference. There isn't a big different between the common method and the previous ones mentioned.

Anyways, looks like I will be forced to use setTimer due to load player datas, create shaders, textures ...etc

Thanks for it. Might I can implement it on my map Loader.

Regards.

Share this post


Link to post
9 minutes ago, Overkillz said:

@IIYAMA
I've just tried it and practically I can't apreciate the difference. There isn't a big different between the common method and the previous ones mentioned.

Anyways, looks like I will be forced to use setTimer due to load player datas, create shaders, textures ...etc

Thanks for it. Might I can implement it on my map Loader.

Regards.

 

There is a huge difference, MTA can create 10000+ of objects and the streamer can only load a part of it. Very hardware limited.

The first example I gave you does not fix your issue directly, but it does answer your topic question. (except for the texture layer on the objects)

 

  • Like 2

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

  • Recently Browsing   0 members

    No registered users viewing this page.