Add helper functions for player availability and heading, and create ghost ped
This commit is contained in:
@@ -35,9 +35,27 @@ function OnTick()
|
||||
WAIT(500) -- Example: wait 500 ms between ticks, adjust as needed, also for performance
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- A compilation of frequently used lua helper functions.
|
||||
-- If downloaded externally, ensure to credit the original author.
|
||||
|
||||
-- Add custom helper functions below.
|
||||
|
||||
function random_choice(p1)
|
||||
function IS_PLAYER_AVAILABLE()
|
||||
local player_ped = PLAYER.PLAYER_PED_ID()
|
||||
if not DOES_ENTITY_EXIST(player_ped) or IS_ENTITY_DEAD(player_ped) then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function GET_PLAYER_PED_HEADING()
|
||||
local player_ped = PLAYER.PLAYER_PED_ID()
|
||||
return GET_ENTITY_HEADING(player_ped)
|
||||
end
|
||||
|
||||
function RANDOM_CHOICE(p1)
|
||||
if type(p1) ~= "table" or #p1 == 0 then
|
||||
return nil
|
||||
end
|
||||
@@ -45,5 +63,14 @@ function random_choice(p1)
|
||||
return choice
|
||||
end
|
||||
|
||||
|
||||
-- Example helper function: creates a ghost ped at an offset from the player
|
||||
function CREATE_GHOST(ped_model, offset_x, offset_y, offset_z)
|
||||
local player_ped = PLAYER.PLAYER_PED_ID()
|
||||
local player_heading = GET_PLAYER_PED_HEADING()
|
||||
local ped_model_hash = GET_HASH_KEY(ped_model)
|
||||
local player_coords = GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(player_ped, offset_x, offset_y, offset_z)
|
||||
local ghost = CreatePoolPed(1, ped_model_hash, player_coords.x, player_coords.y, player_coords.z, player_heading)
|
||||
SET_ENTITY_ALPHA(ghost, 0, false)
|
||||
return ghost
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user