Difference between revisions of "SpawnEntityFromArchetype"
From Nomad DB
m |
Wasdennnoch (talk | contribs) |
||
Line 15: | Line 15: | ||
== Example == | == Example == | ||
− | The example below spawns a bike and prints the name of the [[Entity|entity]]. | + | The example below spawns a bike at the player's position and prints the name of the [[Entity|entity]]. |
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local archetype = "{5a8ef904-070b-4706-8c23-788f6b82a30e}" | local archetype = "{5a8ef904-070b-4706-8c23-788f6b82a30e}" | ||
local destinationEntity = GetLocalPlayerEntityId() | local destinationEntity = GetLocalPlayerEntityId() | ||
− | local | + | local destX, destY, destZ = GetEntityPosition(destinationEntity, 0), GetEntityPosition(destinationEntity, 1), GetEntityPosition(destinationEntity, 2) |
+ | local rotX, rotY, rotZ = GetEntityAngle(destinationEntity, 0), GetEntityAngle(destinationEntity, 1), GetEntityAngle(destinationEntity, 2) | ||
+ | local spawnedEntity = SpawnEntityFromArchetype(archetype, destX, destY, destZ, rotX, rotY, rotZ) | ||
local spawnedEntityName = GetEntityName(spawnedEntity) | local spawnedEntityName = GetEntityName(spawnedEntity) | ||
print(spawnedEntityName) -- returns "Vehicle_Bike.Bike.Bike_01" | print(spawnedEntityName) -- returns "Vehicle_Bike.Bike.Bike_01" |
Revision as of 18:18, 16 April 2020
Spawns an entity of the specified archetype at the specified position.
Syntax
SpawnEntityFromArchetype(archetype, xPos, yPos, zPos, xRot, yRot, zRot)
- archetype (string): Archetype of the target entity
- xPos (number): X component of the target spawn position coordinates
- yPos (number): Y component of the target spawn position coordinates
- zPos (number): Z component of the target spawn position coordinates
- xRot (number): X component of the target spawn orientation in Degrees
- yRot (number): Y component of the target spawn orientation in Degrees
- zRot (number): Z component of the target spawn orientation in Degrees
- Returns (string): ID of the spawned entity.
Example
The example below spawns a bike at the player's position and prints the name of the entity.
local archetype = "{5a8ef904-070b-4706-8c23-788f6b82a30e}"
local destinationEntity = GetLocalPlayerEntityId()
local destX, destY, destZ = GetEntityPosition(destinationEntity, 0), GetEntityPosition(destinationEntity, 1), GetEntityPosition(destinationEntity, 2)
local rotX, rotY, rotZ = GetEntityAngle(destinationEntity, 0), GetEntityAngle(destinationEntity, 1), GetEntityAngle(destinationEntity, 2)
local spawnedEntity = SpawnEntityFromArchetype(archetype, destX, destY, destZ, rotX, rotY, rotZ)
local spawnedEntityName = GetEntityName(spawnedEntity)
print(spawnedEntityName) -- returns "Vehicle_Bike.Bike.Bike_01"