2023-07-02 00:59:02 +02:00
|
|
|
# Table: script
|
|
|
|
|
|
|
|
Table containing helper functions related to gta scripts.
|
|
|
|
|
2023-07-03 13:01:12 +02:00
|
|
|
## Functions (2)
|
2023-07-02 00:59:02 +02:00
|
|
|
|
|
|
|
### `register_looped(name, func)`
|
|
|
|
|
|
|
|
Registers a function that will be looped as a gta script.
|
2023-07-05 00:30:57 +02:00
|
|
|
**Example Usage:**
|
2023-07-03 13:01:12 +02:00
|
|
|
```lua
|
|
|
|
script.register_looped("nameOfMyLoopedScript", function (script)
|
|
|
|
-- sleep until next game frame
|
|
|
|
script:yield()
|
|
|
|
|
|
|
|
local ModelHash = joaat("adder")
|
|
|
|
if not STREAMING.IS_MODEL_IN_CDIMAGE(ModelHash) then return end
|
|
|
|
STREAMING.REQUEST_MODEL(ModelHash) -- Request the model
|
|
|
|
while not STREAMING.HAS_MODEL_LOADED(ModelHash) do -- Waits for the model to load
|
|
|
|
script:yield()
|
|
|
|
end
|
|
|
|
local myPed = PLAYER.PLAYER_PED_ID()
|
|
|
|
local myCoords = ENTITY.GET_ENTITY_COORDS(myPed, true)
|
|
|
|
-- Spawns a networked vehicle on your current coords
|
|
|
|
local spawnedVehicle = VEHICLE.CREATE_VEHICLE(ModelHash, myCoords.x, myCoords.y, myCoords.z, ENTITY.GET_ENTITY_HEADING(myPed), true, false)
|
|
|
|
-- removes model from game memory as we no longer need it
|
|
|
|
STREAMING.SET_MODEL_AS_NO_LONGER_NEEDED(ModelHash)
|
|
|
|
-- sleep for 2s
|
|
|
|
script:sleep(2000)
|
|
|
|
ENTITY.DELETE_ENTITY(spawnedVehicle)
|
|
|
|
end)
|
|
|
|
```
|
2023-07-02 00:59:02 +02:00
|
|
|
|
|
|
|
- **Parameters:**
|
|
|
|
- `name` (string): name of your new looped script
|
|
|
|
- `func` (function): function that will be executed in a forever loop.
|
|
|
|
|
2023-07-05 00:30:57 +02:00
|
|
|
**Example Usage:**
|
2023-07-02 00:59:02 +02:00
|
|
|
```lua
|
|
|
|
script.register_looped(name, func)
|
|
|
|
```
|
|
|
|
|
|
|
|
### `run_in_fiber(func)`
|
|
|
|
|
2023-07-03 13:01:12 +02:00
|
|
|
Executes a function once inside the fiber pool, you can call natives inside it and yield or sleep.
|
2023-07-05 00:30:57 +02:00
|
|
|
**Example Usage:**
|
2023-07-02 00:59:02 +02:00
|
|
|
```lua
|
2023-07-03 13:01:12 +02:00
|
|
|
script.run_in_fiber(function (script)
|
|
|
|
-- sleep until next game frame
|
|
|
|
script:yield()
|
|
|
|
|
|
|
|
local ModelHash = joaat("adder")
|
|
|
|
if not STREAMING.IS_MODEL_IN_CDIMAGE(ModelHash) then return end
|
|
|
|
STREAMING.REQUEST_MODEL(ModelHash) -- Request the model
|
|
|
|
while not STREAMING.HAS_MODEL_LOADED(ModelHash) do -- Waits for the model to load
|
|
|
|
script:yield()
|
|
|
|
end
|
|
|
|
local myPed = PLAYER.PLAYER_PED_ID()
|
|
|
|
local myCoords = ENTITY.GET_ENTITY_COORDS(myPed, true)
|
|
|
|
-- Spawns a networked vehicle on your current coords
|
|
|
|
local spawnedVehicle = VEHICLE.CREATE_VEHICLE(ModelHash, myCoords.x, myCoords.y, myCoords.z, ENTITY.GET_ENTITY_HEADING(myPed), true, false)
|
|
|
|
-- removes model from game memory as we no longer need it
|
|
|
|
STREAMING.SET_MODEL_AS_NO_LONGER_NEEDED(ModelHash)
|
|
|
|
-- sleep for 2s
|
|
|
|
script:sleep(2000)
|
|
|
|
ENTITY.DELETE_ENTITY(spawnedVehicle)
|
|
|
|
end)
|
2023-07-02 00:59:02 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
- **Parameters:**
|
2023-07-03 13:01:12 +02:00
|
|
|
- `func` (function): function that will be executed once in the fiber pool.
|
2023-07-02 00:59:02 +02:00
|
|
|
|
2023-07-05 00:30:57 +02:00
|
|
|
**Example Usage:**
|
2023-07-02 00:59:02 +02:00
|
|
|
```lua
|
2023-07-03 13:01:12 +02:00
|
|
|
script.run_in_fiber(func)
|
2023-07-02 00:59:02 +02:00
|
|
|
```
|
|
|
|
|