diff --git a/README.md b/README.md index 9346183..a0a4649 100644 --- a/README.md +++ b/README.md @@ -19,4 +19,4 @@ Copy the `effect_template.lua` file into your effects directory, change as neede - Restore all modified game state(s) in `OnStop()`. ## Updates -- This script template will get minimal updates for additional function or changes. \ No newline at end of file +- This script template will get minimal updates for additional functions or changes. \ No newline at end of file diff --git a/effect_template.lua b/effect_template.lua index f825f35..404b32e 100644 --- a/effect_template.lua +++ b/effect_template.lua @@ -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