<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Diegofkda</id>
	<title>Multi Theft Auto: Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Diegofkda"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/Diegofkda"/>
	<updated>2026-04-26T18:32:51Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=EngineReplaceModel&amp;diff=27144</id>
		<title>EngineReplaceModel</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=EngineReplaceModel&amp;diff=27144"/>
		<updated>2011-09-13T15:11:22Z</updated>

		<summary type="html">&lt;p&gt;Diegofkda: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
{{Client function}}&lt;br /&gt;
This function replaces the given model in the given model ID with the DFF file passed. This function supports vehicles and objects at the moment.&lt;br /&gt;
&lt;br /&gt;
Note: Due to a bug, when replacing models with built in collisions (i.e. vehicles), the collision may not get replaced correctly. The current work around is to load the dff again and do another replace after a short delay.&lt;br /&gt;
&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
bool engineReplaceModel ( dff theModel, int modelID )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''theModel:''' The model to replace the given model ID with&lt;br /&gt;
*'''modelID:''' The model it to replace the model of&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns ''true'' if the model was successfully replaced, ''false'' if it failed for some reason, ie. the DFF or the model ID is not valid.&lt;br /&gt;
&lt;br /&gt;
==Example== &lt;br /&gt;
'''Example 1:'''&lt;br /&gt;
&amp;lt;section name=&amp;quot;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
Client-Side example for replacing vehicle collisions, model and texture with custom ones.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function ReplaceVehicle ( )&lt;br /&gt;
outputChatBox ( &amp;quot;&amp;gt; replacing the euros vehicle&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
--We will not load the TXD for now&lt;br /&gt;
  dff = engineLoadDFF ( &amp;quot;data/euros.dff&amp;quot;, 587 ) --Load the DFF for first time with an ID specified (required for collisions)&lt;br /&gt;
  engineReplaceModel ( dff, 587 ) --Replace it for first time&lt;br /&gt;
  x, y, z = getElementPosition ( getLocalPlayer() ) -- Get the player position&lt;br /&gt;
  vehicle = createVehicle ( 587, x, y+3, z ) -- Create the vehicle near player position (the car you want to replace must be near the player for the collisions)&lt;br /&gt;
  setTimer ( function () destroyElement ( vehicle ) end, 3000, 1 ) -- Destroy it after 3000 seconds&lt;br /&gt;
  setTimer ( function () -- Now we will load the TXD for first time, and the DFF for second time&lt;br /&gt;
    txd = engineLoadTXD ( &amp;quot;data/euros.txd&amp;quot; )--Load the TXD&lt;br /&gt;
    engineImportTXD ( txd, 587 )&lt;br /&gt;
&lt;br /&gt;
    dff = engineLoadDFF ( &amp;quot;data/euros.dff&amp;quot;, 587 ) --Load the DFF for second time&lt;br /&gt;
    engineReplaceModel ( dff, 587 )&lt;br /&gt;
  end, 50, 1 )&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
addEvent ( &amp;quot;replaceVeh&amp;quot;, true )&lt;br /&gt;
addEventHandler ( &amp;quot;replaceVeh&amp;quot;, getRootElement(), ReplaceVehicle )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&amp;lt;section name=&amp;quot;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
Server-side example function for triggering the replace.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function ReplaceCommand ( )&lt;br /&gt;
triggerClientEvent( &amp;quot;replaceVeh&amp;quot;, getRootElement(), replaceVeh )&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler( &amp;quot;replace&amp;quot;, ReplaceCommand )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example 2:'''&lt;br /&gt;
&amp;lt;section name=&amp;quot;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
Client-Side example for replacing object model, collision and texture with custom ones.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function ReplaceObject ( )&lt;br /&gt;
&lt;br /&gt;
txd = engineLoadTXD( &amp;quot;MyModel.txd&amp;quot; )&lt;br /&gt;
col = engineLoadCOL( &amp;quot;MyModel.col&amp;quot; )&lt;br /&gt;
dff = engineLoadDFF( &amp;quot;MyModel.dff&amp;quot;, 0 ) --modelid is everytime 0, when you replace no vehicle&lt;br /&gt;
&lt;br /&gt;
engineImportTXD( txd, 1234 )&lt;br /&gt;
engineReplaceCOL( col, 1234 )&lt;br /&gt;
engineReplaceModel( dff, 1234 )-- replace the model at least&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
addEvent ( &amp;quot;replaceObj&amp;quot;, true )&lt;br /&gt;
addEventHandler ( &amp;quot;replaceObj&amp;quot;, getRootElement(), ReplaceObject )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&amp;lt;section name=&amp;quot;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
Server-side example function for triggering the replace.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function ReplaceCommand ( )&lt;br /&gt;
triggerClientEvent( &amp;quot;replaceObj&amp;quot;, getRootElement(), replaceObj )&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler( &amp;quot;replace&amp;quot;, ReplaceCommand )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Engine_functions}}&lt;/div&gt;</summary>
		<author><name>Diegofkda</name></author>
	</entry>
</feed>