CreateObject
Create an object in the specified location. Will attempt to use a corresponding pool if one exists.
int nObjectType,
resource rTemplate,
location lLoc,
string sOverrideScript = "",
int bSpawnActive = TRUE,
int bNoPermDeath = FALSE
);
- Parameters:
- nObjectType
- The object type (placeable, creature, etc)
- rTemplate
- The template to use
- lLoc
- Location of the object
- sOverrideScript
- Script assigned to the object. If empty, the engine will use the template script
- bSpawnActive
- Whether or not this object is enabled at spawn time
- bNoPermDeath
- Set to TRUE to avoid destroying the object permanently (only valid for pool creatures)
- Returns:
- The new object, OBJECT_INVALID on failure
- Source:
- script.ldf
Remarks
Note that dynamic creation of objects in the engine is subject to a host of limitations, reason being attempts to cut down 'unaccounted' memory usage.
Avoid using CreateObject whenever possible.
These objects can be created with CreateObject:
- Creature
- Placeable
These objects can not be created with CreateObject:
- Merchant
The function appears to assume that the lLoc parameter represents a valid safe location. If it is valid but not safe, it will be adjusted to the nearest safe location and the object will be created there instead. This is not completely confirmed, but it is clear that placeables cannot be created above the ground level in the air (z-coordinate gets adjusted). However, using SetPosition after creating the object allows you to immediately move the object to an unsafe location if that is desired (see the custom function provided in the example below).
Examples
void main() { // get a location from a waypoint with a unique tag object oWaypoint = GetObjectByTag("wp_werewolf_spawn"); location lWaypoint = GetLocation(oWaypoint); // create a werewolf object at the location object oWerewolf = CreateObject(OBJECT_TYPE_CREATURE, R"werewolf_core.utc", lWaypoint); }
// CreateObjectIn3DSpace - Creates a new object allowing for // locations that are valid but unsafe. // // Same as CreateObject except the lLoc parameter is not adjusted to // the nearest safe location allowing for creation of objects anywhere // in the area including up in the air and below ground. // object CreateObjectIn3DSpace( int nObjectType, resource rTemplate, location lLoc, string sOverrideScript = "", int bSpawnActive = TRUE, int bNoPermDeath = FALSE ); object CreateObjectIn3DSpace( int nObjectType, resource rTemplate, location lLoc, string sOverrideScript = "", int bSpawnActive = TRUE, int bNoPermDeath = FALSE ) { // Create the object using CreateObject. object oNewObject = CreateObject( nObjectType, rTemplate, lLoc, sOverrideScript, bSpawnActive, bNoPermDeath ); if( !IsObjectValid( oNewObject ) ) return OBJECT_INVALID; // Move the object to absolute location in 3D space even if it is // unsafe, then return the new object. SetPosition( oNewObject, GetPositionFromLocation( lLoc ), FALSE ); return oNewObject; }