|
| 1 | +--- |
| 2 | +title: GameEntity |
| 3 | +--- |
| 4 | +{/* |
| 5 | +Internal class used by the GameEntity classes (Ped, Player, Prop, Vehicle). |
| 6 | +*/} |
| 7 | + |
| 8 | +{/* ## Properties |
| 9 | +
|
| 10 | +<TypeTable |
| 11 | + type={{ |
| 12 | + handle: { |
| 13 | + description: "The entity's script handle.", |
| 14 | + type: 'number', |
| 15 | + required: true |
| 16 | + }, |
| 17 | + netId: { |
| 18 | + description: "The entity's network id.", |
| 19 | + type: 'number', |
| 20 | + required: true |
| 21 | + }, |
| 22 | + type: { |
| 23 | + description: "The entity's type (i.e. Ped, Player, Prop, Vehicle).", |
| 24 | + type: 'string', |
| 25 | + required: true |
| 26 | + }, |
| 27 | + statebag: { |
| 28 | + description: "The entity's internal statebag name.", |
| 29 | + type: 'string', |
| 30 | + required: true |
| 31 | + }, |
| 32 | + }} |
| 33 | +/> */} |
| 34 | + |
| 35 | +### set |
| 36 | + |
| 37 | +Writes a value to the entity's statebag. |
| 38 | + |
| 39 | +<Tabs groupId="language" items={['Lua', 'TypeScript']}> |
| 40 | +<Tab> |
| 41 | +```lua |
| 42 | +entity:set(key, value) |
| 43 | +``` |
| 44 | +</Tab> |
| 45 | +<Tab> |
| 46 | +```ts |
| 47 | +entity.set(key, value) |
| 48 | +``` |
| 49 | +</Tab> |
| 50 | +</Tabs> |
| 51 | + |
| 52 | +- key: `string` |
| 53 | +- value: `any` |
| 54 | + |
| 55 | +**Returns:** `boolean` - If the state changed. |
| 56 | + |
| 57 | +### setr |
| 58 | + |
| 59 | +Writes a replicated value to the entity's statebag. Client-set values are validated by the server. |
| 60 | + |
| 61 | +<Tabs groupId="language" items={['Lua', 'TypeScript']}> |
| 62 | +<Tab> |
| 63 | +```lua |
| 64 | +entity:setr(key, value) |
| 65 | +``` |
| 66 | +</Tab> |
| 67 | +<Tab> |
| 68 | +```ts |
| 69 | +entity.setr(key, value) |
| 70 | +``` |
| 71 | +</Tab> |
| 72 | +</Tabs> |
| 73 | + |
| 74 | +- key: `string` |
| 75 | +- value: `any` |
| 76 | + |
| 77 | +**Returns:** `boolean` - If the state changed. |
| 78 | + |
| 79 | +### sets |
| 80 | + |
| 81 | +Writes a synced value to the entity's statebag. Client-set values are validated by the server. |
| 82 | +Synced values are only replicated between the player and server, and cannot be set on non-player entities. |
| 83 | + |
| 84 | +<Tabs groupId="language" items={['Lua', 'TypeScript']}> |
| 85 | +<Tab> |
| 86 | +```lua |
| 87 | +entity:sets(key, value) |
| 88 | +``` |
| 89 | +</Tab> |
| 90 | +<Tab> |
| 91 | +```ts |
| 92 | +entity.sets(key, value) |
| 93 | +``` |
| 94 | +</Tab> |
| 95 | +</Tabs> |
| 96 | + |
| 97 | +- key: `string` |
| 98 | +- value: `any` |
| 99 | + |
| 100 | +**Returns:** `boolean` - If the state changed. |
| 101 | + |
| 102 | +### get |
| 103 | + |
| 104 | +Returns a value from the entity's statebag. |
| 105 | + |
| 106 | +<Tabs groupId="language" items={['Lua', 'TypeScript']}> |
| 107 | +<Tab> |
| 108 | +```lua |
| 109 | +entity:get(key) |
| 110 | +``` |
| 111 | +</Tab> |
| 112 | +<Tab> |
| 113 | +```ts |
| 114 | +entity.get(key) |
| 115 | +``` |
| 116 | +</Tab> |
| 117 | +</Tabs> |
| 118 | + |
| 119 | +- key: `string` |
| 120 | + |
| 121 | +**Returns:** `unknown` |
| 122 | + |
| 123 | +### has |
| 124 | + |
| 125 | +Returns whether a key exists in the entity's statebag. |
| 126 | + |
| 127 | +<Tabs groupId="language" items={['Lua', 'TypeScript']}> |
| 128 | +<Tab> |
| 129 | +```lua |
| 130 | +entity:has(key) |
| 131 | +``` |
| 132 | +</Tab> |
| 133 | +<Tab> |
| 134 | +```ts |
| 135 | +entity.has(key) |
| 136 | +``` |
| 137 | +</Tab> |
| 138 | +</Tabs> |
| 139 | + |
| 140 | +- key: `string` |
| 141 | + |
| 142 | +**Returns:** `boolean` |
| 143 | + |
| 144 | +### keys |
| 145 | + |
| 146 | +Returns an array of all keys set on the entity's statebag. |
| 147 | + |
| 148 | +<Tabs groupId="language" items={['Lua', 'TypeScript']}> |
| 149 | +<Tab> |
| 150 | +```lua |
| 151 | +entity:keys() |
| 152 | +``` |
| 153 | +</Tab> |
| 154 | +<Tab> |
| 155 | +```ts |
| 156 | +entity.keys() |
| 157 | +``` |
| 158 | +</Tab> |
| 159 | +</Tabs> |
| 160 | + |
| 161 | +**Returns:** `string[]` |
| 162 | + |
| 163 | + |
| 164 | +### setHandle |
| 165 | + |
| 166 | +Updates the handle, netId, and statebag properties on an entity. Useful if re-using an entity instance, respawning an entity, changing the model, etc. |
| 167 | + |
| 168 | +<Tabs groupId="language" items={['Lua', 'TypeScript']}> |
| 169 | +<Tab> |
| 170 | +```lua |
| 171 | +entity:setHandle(handle) |
| 172 | +``` |
| 173 | +</Tab> |
| 174 | +<Tab> |
| 175 | +```ts |
| 176 | +entity.setHandle(handle) |
| 177 | +``` |
| 178 | +</Tab> |
| 179 | +</Tabs> |
| 180 | + |
| 181 | +- handle: `number` |
| 182 | + |
| 183 | +### getCoords |
| 184 | + |
| 185 | +Gets the entity's current coordinates. |
| 186 | + |
| 187 | +<Tabs groupId="language" items={['Lua', 'TypeScript']}> |
| 188 | +<Tab> |
| 189 | +```lua |
| 190 | +entity:getCoords() |
| 191 | +``` |
| 192 | +</Tab> |
| 193 | +<Tab> |
| 194 | +```ts |
| 195 | +entity.getCoords() |
| 196 | +``` |
| 197 | +</Tab> |
| 198 | +</Tabs> |
| 199 | + |
| 200 | +**Returns:** `Vector3` |
| 201 | + |
| 202 | +### setCoords |
| 203 | + |
| 204 | +Sets the entity's coordinates to the specified position. |
| 205 | + |
| 206 | +<Tabs groupId="language" items={['Lua', 'TypeScript']}> |
| 207 | +<Tab> |
| 208 | +```lua |
| 209 | +entity:setCoords(x, y, z, deadFlag, ragdollFlag, clearArea) |
| 210 | +``` |
| 211 | +</Tab> |
| 212 | +<Tab> |
| 213 | +```ts |
| 214 | +entity.setCoords() |
| 215 | +``` |
| 216 | +</Tab> |
| 217 | +</Tabs> |
| 218 | + |
| 219 | +- x: `number` |
| 220 | +- y: `number` |
| 221 | +- z: `number` |
| 222 | +- deadFlag?: `boolean` (Defaults to false) |
| 223 | +- ragdollFlag?: `boolean` (Defaults to false) |
| 224 | +- clearArea?: `boolean` (Defaults to false) |
| 225 | + |
| 226 | +### getModel |
| 227 | + |
| 228 | +Gets the entity's current model hash. |
| 229 | + |
| 230 | +<Tabs groupId="language" items={['Lua', 'TypeScript']}> |
| 231 | +<Tab> |
| 232 | +```lua |
| 233 | +entity:getModel() |
| 234 | +``` |
| 235 | +</Tab> |
| 236 | +<Tab> |
| 237 | +```ts |
| 238 | +entity.getModel() |
| 239 | +``` |
| 240 | +</Tab> |
| 241 | +</Tabs> |
| 242 | + |
| 243 | +**Returns:** `number` |
| 244 | + |
| 245 | +### getHeading |
| 246 | + |
| 247 | +Gets the entity's current heading (or yaw) in degrees. |
| 248 | + |
| 249 | +<Tabs groupId="language" items={['Lua', 'TypeScript']}> |
| 250 | +<Tab> |
| 251 | +```lua |
| 252 | +entity:getHeading() |
| 253 | +``` |
| 254 | +</Tab> |
| 255 | +<Tab> |
| 256 | +```ts |
| 257 | +entity.getHeading() |
| 258 | +``` |
| 259 | +</Tab> |
| 260 | +</Tabs> |
| 261 | + |
| 262 | +**Returns:** `number` |
| 263 | + |
| 264 | +### setHeading |
| 265 | + |
| 266 | +Sets the entity's heading (or yaw) to the given value in degrees. |
| 267 | + |
| 268 | +<Tabs groupId="language" items={['Lua', 'TypeScript']}> |
| 269 | +<Tab> |
| 270 | +```lua |
| 271 | +entity:setHeading(heading) |
| 272 | +``` |
| 273 | +</Tab> |
| 274 | +<Tab> |
| 275 | +```ts |
| 276 | +entity.setHeading(heading) |
| 277 | +``` |
| 278 | +</Tab> |
| 279 | +</Tabs> |
| 280 | + |
| 281 | +- heading: `number` |
| 282 | + |
| 283 | +### getRoutingBucket |
| 284 | + |
| 285 | +Gets the entity's current routing bucket. |
| 286 | + |
| 287 | +<Tabs groupId="language" items={['Lua', 'TypeScript']}> |
| 288 | +<Tab> |
| 289 | +```lua |
| 290 | +entity:getRoutingBucket() |
| 291 | +``` |
| 292 | +</Tab> |
| 293 | +<Tab> |
| 294 | +```ts |
| 295 | +entity.getRoutingBucket() |
| 296 | +``` |
| 297 | +</Tab> |
| 298 | +</Tabs> |
| 299 | + |
| 300 | +**Returns:** `number` |
| 301 | + |
| 302 | +### setRoutingBucket |
| 303 | + |
| 304 | +Sets the entity's routing bucket to the given id. **Server only.** |
| 305 | + |
| 306 | +<Tabs groupId="language" items={['Lua', 'TypeScript']}> |
| 307 | +<Tab> |
| 308 | +```lua |
| 309 | +entity:setRoutingBucket(bucketId) |
| 310 | +``` |
| 311 | +</Tab> |
| 312 | +<Tab> |
| 313 | +```ts |
| 314 | +entity.setRoutingBucket(bucketId) |
| 315 | +``` |
| 316 | +</Tab> |
| 317 | +</Tabs> |
| 318 | + |
| 319 | +- bucketId: `number` |
0 commit comments