# Special Types

## Constructors

### NewObject

#### NewObject(typeName: `string`) -> `GameType`

Create a new object of the type given by `typeName`. This type should be an internal game type.

```lua
obj = NewObject("gameObject")
puppet = NewObject("PlayerPuppet")
vec2 = NewObject("Vector2")
vec3 = NewObject("Vector3")
matrix = NewObject("Matrix")
world_transform = NewObject("WorldTransform")
```

{% hint style="info" %}
The geometric types discussed below can also be created with NewObject.
{% endhint %}

### ToVector3

#### ToVector3(values: `table<x: float, y: float, z: float>`) -> `Vector3`

Create a new `Vector3` from a table of `x`, `y`, and `z` floats.

```lua
position = ToVector3{x=-1788, y=-450, z=7.75}
```

| Property   | Description                        |
| ---------- | ---------------------------------- |
| `x: float` | The x-axis component of the vector |
| `y: float` | The y-axis component of the vector |
| `z: float` | The z-axis component of the vector |

{% hint style="info" %}
In Cyberpunk, the Z axis is the up axis.
{% endhint %}

### ToVector4

#### ToVector4(values: `table<x: float, y: float, z: float, w: float>`) -> `Vector4`

Create a new `Vector4` from a table of `x`, `y`, `z`, and `w` floats.

```lua
position = ToVector4{x=-1788, y=-450, z=7.75, w=1}
```

| Property   | Description                        |
| ---------- | ---------------------------------- |
| `x: float` | The x-axis component of the vector |
| `y: float` | The y-axis component of the vector |
| `z: float` | The z-axis component of the vector |
| `w: float` | The w-axis component of the vector |

{% hint style="warning" %}
You may notice that functions like `PlayerPuppet:GetWorldPosition` will return a `Vector4`, even though, intuitively, 3D coordinates only include x, y, and z values. These `Vector4` values are known as [homogenous coordinates](https://en.wikipedia.org/wiki/Homogeneous_coordinates) in graphical programming, useful in matrix transformations.

All you really need to know is that the 4th value, `w`, should always be 1 when you are dealing with 3D coordinates.
{% endhint %}

### ToEulerAngles

#### ToEulerAngles(angles: `table<roll: float, pitch: float, yaw: float>`) -> `EulerAngles`

Create a new `EulerAngles` from a table of `roll`, `pitch`, and `yaw`. Angle values are in degrees.

```lua
rotation = ToEulerAngles{roll=0, pitch=0, yaw=45}

player = Game.GetPlayer()
Game.GetTeleportationFacility():Teleport(player, player:GetWorldPosition(), rotation)
```

| Property       | Description                                                                                                                                         |
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| `yaw: float`   | <p>The horizontal angle in degrees along the axis pointing up.</p><p>0 is north, 90 is west, 180 and -180 are south, and -90 is east.</p>           |
| `pitch: float` | <p>The vertical angle in degrees along the axis pointing to the right.</p><p>-90 is down, 0 is straight ahead, and 90 is up.</p>                    |
| `roll: float`  | <p>The roll angle in degrees along the axis pointing forward.</p><p>Positive values rotate anti-clockwise and negative values rotate clockwise.</p> |

### ToQuaternion

#### ToQuaternion(values: `table<i: float, j: float, k: float, r: float>`) -> `Quaternion`

Create a new `Quaternion` from a table of a vector part `i`, `j`, `k`, and a scalar (real) part `r`.

```lua
-- 45 degree rotation about the Z axis (yaw)
rotation = ToQuaternion{i=0, j=0, k=0.383, r=0.924}
```

| Property   | Description                              |
| ---------- | ---------------------------------------- |
| `i: float` | The x-axis component of the quaternion   |
| `j: float` | The y-axis component of the quaternion   |
| `k: float` | The z-axis component of the quaternion   |
| `r: float` | The scalar (real) part of the quaternion |

{% hint style="info" %}
Quaternions are also often expressed with `w, x, y, z` terms, which map to our terms as following:

`w == r`\
`x == i`\
`y == j`\
`z == k`
{% endhint %}

### ToCName

#### ToCName(hash: `table<hash_hi: uint32, hash_lo: uint32>`) -> `CName`

Create a new `CName` from a table of `hash_hi` and `hash_lo`.

```lua
cname = ToCName{hash_hi=0x01234567, hash_lo=0x89abcdef}
```

| Property          | Description                                     |
| ----------------- | ----------------------------------------------- |
| `hash_hi: uint32` | The higher 32 bits of the `CName`'s 64-bit hash |
| `hash_lo: uint32` | The lower 32 bits of the `CName`'s 64-bit hash  |
| `value: string`   | The text value of the `CName`                   |

### ToTweakDBID

#### ToTweakDBID(data: `table<hash: uint32, length: uint8>`) -> `TweakDBID`

Create a new `TweakDBID` from a table of `hash` and `length`.

```lua
id = ToTweakDB{hash=0x01234567, length=12}
```

| Property        | Description                     |
| --------------- | ------------------------------- |
| `hash: uint32`  | The CRC32 hash of the item name |
| `length: uint8` | The length of the item name     |

### ToItemID

#### ToItemID(data: `table<id: TweakDBID, rng_seed: uint32, unknown: uint16, maybe_type: uint8>`) -> `ItemID`

Create an `ItemID` from a table of `id`, `rng_seed`, an unknown field `unknown`, and an unknown field `maybe_type`.

```lua
dbid = ToTweakDB{hash=0x01234567, length=12}
itemid = ToItemID{id=dbid, rng_seed=0x01234567}
```

| Property            | Description                                                      |
| ------------------- | ---------------------------------------------------------------- |
| `id: TweakDBID`     | The TweakDBID referenced by this ItemID                          |
| `tdbid: TweakDBID`  | Alias for `id`                                                   |
| `rng_seed: uint32`  | The RNG (random number generation) seed used for loot generation |
| `unknown: uint16`   | Unknown field                                                    |
| `maybe_type: uint8` | Unknown field, possibly a type                                   |
