Skip to content

Commit

Permalink
refactor: rappeling
Browse files Browse the repository at this point in the history
  • Loading branch information
mafewtm committed Dec 14, 2024
1 parent f6f5183 commit 9f9d2c2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 20 deletions.
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ insert_final_newline = false
indent_style = space
charset = utf-8
trim_trailing_whitespace = true
indent_size = 4
indent_size = 4

[*.{sql,html,css,json,js,ts,jsx,tsx}]
indent_size = 2
44 changes: 27 additions & 17 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ local LR_SPEED = 3.0 -- speed by which the camera pans left-right
local UD_SPEED = 3.0 -- speed by which the camera pans up-down
local toggleHeliCam = 51 -- control id of the button by which to toggle the heliCam mode. Default: INPUT_CONTEXT (E)
local toggleVision = 25 -- control id to toggle vision mode. Default: INPUT_AIM (Right mouse btn)
local toggleRappel = 154 -- control id to rappel out of the heli. Default: INPUT_DUCK (X)
local toggleLockOn = 22 -- control id to lock onto a vehicle with the camera. Default is INPUT_SPRINT (spacebar)
local heliCam = false
local fov = (FOV_MAX + FOV_MIN) * 0.5
Expand Down Expand Up @@ -203,11 +202,6 @@ local function handleInVehicle()
type = 'heliopen',
})
end

if IsControlJustPressed(0, toggleRappel) and (cache.seat == 1 or cache.seat == 2) then -- Initiate rappel
PlaySoundFrontend(-1, 'SELECT', 'HUD_FRONTEND_DEFAULT_SOUNDSET', false)
TaskRappelFromHeli(cache.ped, 1)
end
end

if heliCam then
Expand Down Expand Up @@ -273,9 +267,9 @@ local function handleInVehicle()
end

local spotlight = lib.addKeybind({
name = 'helicam',
description = 'Toggle Helicopter Spotlight',
defaultKey = '7',
name = 'spotlight',
description = locale('spotlight_keybind'),
defaultKey = 'H',
disabled = true,
onPressed = function()
PlaySoundFrontend(-1, 'SELECT', 'HUD_FRONTEND_DEFAULT_SOUNDSET', false)
Expand All @@ -286,6 +280,17 @@ local spotlight = lib.addKeybind({
end,
})

local rappel = lib.addKeybind({
name = 'rappel',
description = locale('rappel_keybind'),
defaultKey = 'X',
disabled = true,
onPressed = function()
PlaySoundFrontend(-1, 'SELECT', 'HUD_FRONTEND_DEFAULT_SOUNDSET', false)
TaskRappelFromHeli(cache.ped, 1)
end
})

---@diagnostic disable-next-line: param-type-mismatch
AddStateBagChangeHandler('spotlight', nil, function(bagName, _, value)
local entity = GetEntityFromStateBagName(bagName)
Expand All @@ -294,17 +299,22 @@ AddStateBagChangeHandler('spotlight', nil, function(bagName, _, value)
end)

lib.onCache('seat', function(seat)
if seat ~= -1 and seat ~= 0 then
spotlight:disable(true)
return
end

local model = GetEntityModel(cache.vehicle)

if not config.policeHelicopters[model] then return end
if not config.authorizedHelicopters[model] then return end

if seat == -1 and seat == 0 then
rappel:disable(true)

if DoesVehicleHaveSearchlight(cache.vehicle) then
spotlight:disable(false)
if DoesVehicleHaveSearchlight(cache.vehicle) then
spotlight:disable(false)
end
elseif seat == 1 and seat == 2 then
spotlight:disable(true)

if DoesVehicleAllowRappel(cache.vehicle) then
rappel:disable(false)
end
end

CreateThread(function()
Expand Down
4 changes: 2 additions & 2 deletions config/client.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
return {
policeHelicopters = {
`polmav`,
authorizedHelicopters = {
[`polmav`] = true,
},
}
1 change: 1 addition & 0 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ files {
'html/script.js',
'html/main.css',
'config/client.lua',
'locales/*.json'
}

lua54 'yes'
Expand Down
4 changes: 4 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"spotlight_keybind": "Toggle helicopter spotlight",
"rappel_keybind": "Start rappeling"
}

0 comments on commit 9f9d2c2

Please sign in to comment.