Hosting and domain costs until October 2024 have been generously sponsored by dumptruck_ds. Thank you!

Difference between revisions of "setmodel"

From Quake Wiki

 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
Syntax:<br/>
+
''void'' '''setmodel'''(''entity'' e, ''string'' modelPath)
<code>setmodel(entity e, string path)</code>
 
  
Makes the entity <code>e</code> use the model that is found in the <code>path</code>.  This model must be precached before it can be used.
+
== Usage ==
 +
Sets the entity's model. Valid models must be precached at map load in order to be usable. This sets both the '''model''' and '''modelindex''' fields. The model index is the index within the cache which is not exposed to QuakeC, but can be set directly by storing the value and changing it. The model name and model index do not need to match as '''modelindex''' takes priority.
 +
 
 +
For BSP models this also sets up the size information of the entity meaning <code>setsize()</code> should not be used on them. BSP entities will automatically store their model name in their '''model''' field on map load, so calling <code>setmodel(self, self.model);</code> will work for things like platforms, doors, and trains.
 +
 
 +
To clear a model, setting '''model''' to ""/'''string_null''' or setting '''modelindex''' to 0 will work.
 +
 
 +
=== Parameters ===
 +
*''e''
 +
:The entity whose model is being set.
 +
*''modelPath''
 +
:The path to the model file to setCan be a model (.mdl), sprite (.spr) or BSP (.bsp).
 +
 
 +
== Example ==
 +
void monster_my_monster()
 +
{
 +
    // Make sure the model is precached first in the initialization function
 +
    precache_model("progs/mymonster.mdl");
 +
 +
    // Set the entity's model to mymonster.mdl
 +
    setmodel(self, "progs/mymonster.mdl");
 +
}
  
 
[[Category:QuakeC Function]]
 
[[Category:QuakeC Function]]

Latest revision as of 10:35, 31 July 2023

void setmodel(entity e, string modelPath)

Usage[edit]

Sets the entity's model. Valid models must be precached at map load in order to be usable. This sets both the model and modelindex fields. The model index is the index within the cache which is not exposed to QuakeC, but can be set directly by storing the value and changing it. The model name and model index do not need to match as modelindex takes priority.

For BSP models this also sets up the size information of the entity meaning setsize() should not be used on them. BSP entities will automatically store their model name in their model field on map load, so calling setmodel(self, self.model); will work for things like platforms, doors, and trains.

To clear a model, setting model to ""/string_null or setting modelindex to 0 will work.

Parameters[edit]

  • e
The entity whose model is being set.
  • modelPath
The path to the model file to set. Can be a model (.mdl), sprite (.spr) or BSP (.bsp).

Example[edit]

void monster_my_monster()
{
    // Make sure the model is precached first in the initialization function
    precache_model("progs/mymonster.mdl");

    // Set the entity's model to mymonster.mdl
    setmodel(self, "progs/mymonster.mdl");
}