Skip to main content

World

World-related APIs.

Global Methods

World.GetObjectByNID(nid: number): NetObject | nil

Returns the network object with the given network id.

World.GetAllByType(type: NetObjectType): NetObject[]

Returns network objects with the given type.

World.SpawnVehicle(name: string, vec3: position, vec3: rotation): NetVehicle

Spawns a vehicle at the given position with the given rotation. For a complete list of vehicle names, see Vehicle List.

Example:

-- Spawn a car at the airport
World.SpawnVehicle("v024_car_ecosuper_racing_01", vec3(9503, 517, 8463), vec3(0, 0, 0))

World.SpawnMountedGun(id: string, position: vec3, rotation?: vec3, health?: number): NetMountedGun

Spawns a mounted gun at the given position with the given rotation. This is synced to all players.

Parameters:

  • id: string - The identifier for the mounted gun
  • position: vec3 - The position to spawn the mounted gun at
  • rotation?: vec3 - Optional rotation (defaults to no rotation)
  • health?: number - Optional health value (defaults to 100)

Example:

-- Spawn a mounted gun at the specified position
local mountedGun = World.SpawnMountedGun("turret_01", vec3(1000, 100, 2000), vec3(0, 90, 0), 150)

World.SpawnRigidObject(position: vec3, model: string, pfx: string, motionType: RigidObjectMotionType, rotation?: vec3, health?: number): NetRigidObject

Spawns a rigid object at the given position with the given rotation. This is synced to all players. See the objects list for a complete list of objects to spawn.

Parameters:

  • position: vec3 - The position to spawn the object at
  • model: string - The model name of the object
  • pfx: string - The particle effects file for the object
  • motionType: RigidObjectMotionType - Initial motion type for the rigid object
  • rotation?: vec3 - Optional rotation (defaults to no rotation)
  • health?: number - Optional health value (defaults to 100)

World.SpawnNPC(id: string, position: vec3, health?: int, rotation?: vec3): NetNPC

Spawns an NPC at the given position with the given rotation and health.

Parameters:

  • id: string - The identifier for the NPC
  • position: vec3 - The position to spawn the NPC at
  • health?: int - Optional health value (defaults to 100)
  • rotation?: vec3 - Optional rotation (defaults to no rotation)

Returns: NetNPC - The spawned NPC instance

Example:

-- Spawn an NPC at the specified position
local npc = World.SpawnNPC("civilian_01", vec3(1000, 100, 2000), 100, vec3(0, 90, 0))

-- Make the NPC patrol
npc:Move(vec3(1, 0, 0), MoveType.Walk, MoveStyle.Patrol)

World.Destroy(obj: NetObject)

Destroys a NetObject. This can be used to destroy vehicles and objects.

World.SpawnTether(origin: vec3, target: NetObject, targetOffset: vec3): NetTether

Creates a tether from a static origin position to a target object with an offset relative to the object.

Parameters:

  • origin: vec3 - World position where the tether starts
  • target: NetObject - The object the tether attaches to
  • targetOffset: vec3 - Offset from the object's origin for the tether attachment

Returns: NetTether - The created tether instance

Example:

-- Tether a vehicle to a fixed world point
local tether = World.SpawnTether(vec3(1000, 200, 1500), someVehicle, vec3(0, 1.2, 0))

World.SpawnTether(origin: NetObject, originOffset: vec3, target: NetObject, targetOffset: vec3): NetTether

Creates a tether between two objects, using offsets relative to each object for the attachment points.

Parameters:

  • origin: NetObject - The first object
  • originOffset: vec3 - Offset from the first object's origin for the tether attachment
  • target: NetObject - The second object
  • targetOffset: vec3 - Offset from the second object's origin for the tether attachment

Returns: NetTether - The created tether instance

Example:

-- Tether two objects together at their roof hardpoints
local tether = World.SpawnTether(someVehicle, vec3(0, 1.2, 0), someOtherVehicle, vec3(0, 1.7, 0))