Difference between revisions of "SpawnEntityFromArchetype"
From Nomad DB
m |
SpeckBomber (talk | contribs) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{Page_WD2}} | ||
Spawns an [[Entity|entity]] of the specified [[Archetype|archetype]] at the specified position. | Spawns an [[Entity|entity]] of the specified [[Archetype|archetype]] at the specified position. | ||
Line 15: | Line 16: | ||
== 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" | ||
Line 29: | Line 32: | ||
* [[Archetype]] | * [[Archetype]] | ||
− | [[Category:WD2 Lua]] [[Category: WD2 Entity | + | [[Category:WD2 Lua]] [[Category: WD2 Entity]] |
Latest revision as of 20:41, 27 October 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"