Jump to content

[HELP] replace vehicle models per dimension


Recommended Posts

What I want to achieve: to have vehicle models replaced with custom ones when the player enters dimension 50, then get replaced by a different set of custom models when the player goes back to dimension 0

With the example script, the models get replaced just fine but the problem is that every time the player changes from dimension 0 to dimension 50 and vice versa there's several seconds of loading time and memory usage keeps piling up much more than it should. Is there a better approach to vehicle model replacement per dimension? Thanks in advance

Example script:

local last_dim = false;


local function VC_models()
       
   
    TXD = engineLoadTXD ("stinger.txd") 
    DFF = engineLoadDFF ("stinger.dff" ) 
    engineImportTXD ( TXD,   477   )  
    engineReplaceModel ( DFF,   477   ) 
    
end


local function New_models()
 
     
    TXD = engineLoadTXD ("zr350.txd") 
    DFF = engineLoadDFF ("zr350.dff" ) 
    engineImportTXD ( TXD,   477   )  
    engineReplaceModel ( DFF,   477   )
     
    
end


addEventHandler("onClientRender", root,
    function()
        local cur_dim = getElementDimension(localPlayer);
        
        if not (last_dim == cur_dim) then
            if (cur_dim == 50) then
                VC_models();
            elseif (last_dim == 50) then
                New_models();
            end
            
            last_dim = cur_dim;
        end
    end
);

 

 

Link to post

Use this to check if player changed dimension then put the replaceModel function instead of rendering the replaceModel function.

https://wiki.multitheftauto.com/wiki/OnClientElementDimensionChange

note: 

never tried it, just an idea, but it might work, i feel like rendering the replace model functions would really cause lag since it just spams.

EDIT: 

tried something like this, it works, goodluck.

function SA_Model() 
	local txd = engineLoadTXD("test.txd", 202 )
	engineImportTXD(txd , 202)
	local dff = engineLoadDFF("test.dff", 202)
	engineReplaceModel(dff , 202)
end

function VC_Model()
	local txd = engineLoadTXD("test2.txd", 202 )
	engineImportTXD(txd , 202)
	local dff = engineLoadDFF("test2.dff", 202)
	engineReplaceModel(dff , 202)
end 

addEventHandler ( "onClientElementDimensionChange", localPlayer,
	function ( oldDimension, newDimension )
		if oldDimension == 0 then 
			VC_Model()
			outputChatBox("check 1")
		elseif newDimension == 0 then 
			SA_Model()
			outputChatBox("check 0")
		end 
	end
)

 

Edited by Bean666
Link to post
Posted (edited)
6 hours ago, Bean666 said:

Use this to check if player changed dimension then put the replaceModel function instead of rendering the replaceModel function.

https://wiki.multitheftauto.com/wiki/OnClientElementDimensionChange

note: 

never tried it, just an idea, but it might work, i feel like rendering the replace model functions would really cause lag since it just spams.

EDIT: 

tried something like this, it works, goodluck.

 

Thanks for the script, I didn't know about OnClientElementDimensionChange, it works too but unfortunately the big memory usage still remains, it's not very noticeable with one or two replaced vehicle models but with entire vehicle sets it still adds up every time every time the player goes from one dimension to the other. 

Edited by mono1
Link to post

Anyone knows if it's possible to stream out of memory the extra dimension vehicle models when on dimension 0 and vice versa? scene2res does something like that with map models and memory usage doesn't piles up when switching dimensions.

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.

×
×
  • Create New...