Enhance player availability check and add function to get player ped offset

This commit is contained in:
2026-01-18 18:22:21 +00:00
parent ecd940ff7c
commit b9582c77a6
2 changed files with 11 additions and 7 deletions

View File

@@ -43,15 +43,20 @@ end
-- Add custom helper functions below.
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
local player_ped = PLAYER_PED_ID()
if not DOES_ENTITY_EXIST(player_ped) or IS_ENTITY_DEAD(player_ped) or IS_PLAYER_SWITCH_IN_PROGRESS() then
return false
end
return true
end
function GET_PLAYER_PED_OFFSET(offset_x, offset_y, offset_z)
local player_ped = PLAYER_PED_ID()
return GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(player_ped, offset_x, offset_y, offset_z)
end
function GET_PLAYER_PED_HEADING()
local player_ped = PLAYER.PLAYER_PED_ID()
local player_ped = PLAYER_PED_ID()
return GET_ENTITY_HEADING(player_ped)
end
@@ -63,12 +68,11 @@ 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 player_coords = GET_PLAYER_PED_OFFSET(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