Skip to content

Commit dba0f06

Browse files
committed
feat(vehicle): add slider for fast vehciels
- Add a slider for Fast Vehicles. - Add a slider for Fast Planes. closes #143 closes #144
1 parent 47384d2 commit dba0f06

8 files changed

Lines changed: 90 additions & 46 deletions

File tree

SSV2/includes/data/config.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ local Config <const> = {
185185
subwoofer = false,
186186
horn_beams = false,
187187
fast_vehicles = false,
188+
fast_vehicles_speed = 10,
188189
auto_brake_lights = false,
189190
iv_exit = false,
190191
no_wheel_recenter = false,
@@ -205,6 +206,7 @@ local Config <const> = {
205206
auto_lock_doors = false,
206207
cobra_maneuver = false,
207208
fast_jets = false,
209+
fast_jets_speed = 150.0,
208210
no_jet_stall = false,
209211
no_turbulence = false,
210212
aircraft_mg = {

SSV2/includes/features/Speedometer.lua

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
local gui_registered = false
1111
local last_engine_state = true
12+
local last_captured_top_spd = 0.0
1213
local RUNTIME_COLORS <const> = {
1314
INDICATOR_RED = Color(1.0, 0.215, 0.215, 1.0):AsU32(),
1415
INDICATOR_GREEN = Color(0.1, 0.91, 0.0, 1.0):AsU32(),
@@ -88,21 +89,25 @@ local Speedometer = {
8889
}; Speedometer.__index = Speedometer
8990

9091
---@public
91-
function Speedometer:UpdateState()
92+
---@param PV PlayerVehicle
93+
function Speedometer:UpdateState(PV)
9294
local state = self._state
93-
local PV = LocalPlayer:GetVehicle()
9495
if not (PV and PV:IsValid()) then
9596
state.should_draw = false
9697
return
9798
end
9899

99-
local speed_modifier = Match(GVars.features.speedometer.speed_unit, UNIT_MULTIPLIERS)
100-
local fast_vehicles = GVars.features.vehicle.fast_vehicles
101-
local IsEngineOn = PV:IsEngineOn()
100+
local speed_modifier = Match(GVars.features.speedometer.speed_unit, UNIT_MULTIPLIERS)
101+
local IsEngineOn = PV:IsEngineOn()
102+
local IsNosActive = PV:IsNOSActive()
103+
if (not IsNosActive) then
104+
last_captured_top_spd = PV:GetMaxSpeed()
105+
end
106+
102107
state.PV = PV
103108
state.speed_modifier = speed_modifier
104109
state.CurrentSpeed = PV:GetSpeed() * speed_modifier
105-
state.MaxSpeed = math.floor((PV:GetDefaultMaxSpeed() * (fast_vehicles and 1.8 or 1)) * speed_modifier)
110+
state.MaxSpeed = math.floor(last_captured_top_spd * speed_modifier)
106111
state.CurrentAltitude = PV:GetHeightAboveGround()
107112
state.Manufacturer = PV:GetManufacturerName()
108113
state.IsEngineOn = IsEngineOn
@@ -111,7 +116,7 @@ function Speedometer:UpdateState()
111116
state.IsABSEngaged = PV:IsABSEngaged()
112117
state.IsESCEngaged = PV:IsESCEngaged()
113118
state.IsESCDisabled = get_is_tc_esc_dsabled(PV)
114-
state.IsNOSActive = PV:IsNOSActive()
119+
state.IsNOSActive = IsNosActive
115120
state.IsAircraft = PV:IsPlane() or PV:IsHeli()
116121
state.IsSports = PV:IsSportsOrSuper()
117122
state.IsShootingFlares = PV.m_is_shooting_flares

SSV2/includes/features/online/yim_resupplier/YimResupplierV3.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,21 @@ function YRV3:Reset(disable, reason)
130130
self.m_last_autosell_check_time = 0
131131
self.m_last_income_check_time = 0
132132
self.m_last_business_update_time = 0
133-
self.m_businesses = { safes = {} }
134133
self.m_boss_types_avail = { { name = "GB_BOSS" --[[VIP]], id = 0 } }
135134
self.m_sell_script_running = false
136135
self.m_initial_data_done = false
137136
self.m_data_initialized = false
138137
self.m_autosell_state = Enums.eAutoSellState.NONE
139138
self.m_state = disable and Enums.eYRState.ERROR or Enums.eYRState.IDLE
140139

140+
for _, business in self:BusinessIter() do
141+
local reset = business.Reset
142+
if (reset) then
143+
---@diagnostic disable-next-line
144+
reset(business)
145+
end
146+
end; self.m_businesses = { safes = {} }
147+
141148
if (disable) then
142149
self:SetLastError(reason or "Unhandled Exception.")
143150
end

SSV2/includes/features/vehicle/misc_vehicle.lua

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ function MiscVehicle:ShootExplosiveMG(enemiesOnly, targetEntity, startPos, endPo
109109
end
110110

111111
function MiscVehicle:UpdateMachineGuns()
112-
if (not GVars.features.vehicle.aircraft_mg.triggerbot
113-
and not GVars.features.vehicle.aircraft_mg.manual_aim) then
112+
local cfg = GVars.features.vehicle.aircraft_mg
113+
if not (cfg.triggerbot or cfg.manual_aim) then
114114
return
115115
end
116116

@@ -120,17 +120,17 @@ function MiscVehicle:UpdateMachineGuns()
120120

121121
local PV = self.m_entity
122122
local handle = PV:GetHandle()
123-
local manualAim = GVars.features.vehicle.aircraft_mg.manual_aim
124-
local triggerbotRange = GVars.features.vehicle.aircraft_mg.tiggerbot_range
123+
local manualAim = cfg.manual_aim
124+
local triggerbotRange = cfg.tiggerbot_range
125125
local playerPos = LocalPlayer:GetPos()
126126
local rotation = manualAim and CAM.GET_GAMEPLAY_CAM_ROT(2) or PV:GetRotation(2)
127127
local direction = rotation:to_direction()
128128
local multiplier = manualAim and 200 or triggerbotRange
129129
local destination = playerPos + direction * multiplier
130130
local hit, endCoords, entityHit = World:RayCast(playerPos, destination, -1, handle)
131131

132-
if (hit and GVars.features.vehicle.aircraft_mg.triggerbot and (ENTITY.IS_ENTITY_A_PED(entityHit) or ENTITY.IS_ENTITY_A_VEHICLE(entityHit))) then
133-
local enemiesOnly = GVars.features.vehicle.aircraft_mg.enemies_only
132+
if (hit and cfg.triggerbot and (ENTITY.IS_ENTITY_A_PED(entityHit) or ENTITY.IS_ENTITY_A_VEHICLE(entityHit))) then
133+
local enemiesOnly = cfg.enemies_only
134134
local ped = Game.GetClosestPed(endCoords, 50, true)
135135
local veh = Game.GetClosestVehicle(endCoords, 50, handle)
136136

@@ -150,8 +150,8 @@ function MiscVehicle:UpdateMachineGuns()
150150
self:ShootExplosiveMG(false, 0, playerPos, endPos)
151151
end
152152

153-
local color = GVars.features.vehicle.aircraft_mg.marker_color
154-
local markerSize = GVars.features.vehicle.aircraft_mg.marker_size
153+
local color = cfg.marker_color
154+
local markerSize = cfg.marker_size
155155
local markerDest = hit and endCoords or vec3:new(
156156
playerPos.x + direction.x * 50,
157157
playerPos.y + direction.y * 50,
@@ -206,17 +206,18 @@ function MiscVehicle:DisableAirTurbulence()
206206
end
207207

208208
function MiscVehicle:Update()
209-
local PV = self.m_entity
209+
local PV = self.m_entity
210210
local handle = PV:GetHandle()
211+
local cfg = GVars.features.vehicle
211212

212-
if (GVars.features.vehicle.fast_jets and PV:IsPlane() and (VEHICLE.GET_VEHICLE_FLIGHT_NOZZLE_POSITION(handle) ~= 1.0)) then
213+
if (cfg.fast_jets and PV:IsPlane() and (VEHICLE.GET_VEHICLE_FLIGHT_NOZZLE_POSITION(handle) ~= 1.0)) then
213214
local speed = PV:GetSpeed()
214215
local gearState = PV:GetLandingGearState()
215216
local rot = PV:GetRotation(2)
216217
local pitch = rot.x
217-
local baseThrust = 2e4
218-
local minThrust = 5e3
219-
local maxSpeed = 164.0
218+
local baseThrust = 25e3
219+
local minThrust = 1e4
220+
local maxSpeed = cfg.fast_jets_speed or 150.0
220221
local thrustMult = 1.0
221222

222223
if (pitch >= 60) then
@@ -225,10 +226,7 @@ function MiscVehicle:Update()
225226
thrustMult = 1.4
226227
end
227228

228-
if speed >= 72 and speed < maxSpeed
229-
and PAD.IS_CONTROL_PRESSED(0, 87)
230-
and gearState == Enums.eLandingGearState.RETRACTED
231-
then
229+
if (speed >= 70 and speed < maxSpeed and PAD.IS_CONTROL_PRESSED(0, 87) and gearState == Enums.eLandingGearState.RETRACTED) then
232230
local lerp = math.min(1.0, (speed) / (maxSpeed))
233231
local thrust = math.min(minThrust, baseThrust * thrustMult * (1.0 - lerp))
234232
ENTITY.APPLY_FORCE_TO_ENTITY_CENTER_OF_MASS(
@@ -245,13 +243,13 @@ function MiscVehicle:Update()
245243
end
246244
end
247245

248-
if (GVars.features.vehicle.no_jet_stall) then
246+
if (cfg.no_jet_stall) then
249247
if (PV:IsDriveable() and PV:GetEngineHealth() > 350 and PV:GetHeightAboveGround() > 5.0 and not PV:IsEngineOn()) then
250248
VEHICLE.SET_VEHICLE_ENGINE_ON(handle, true, true, false)
251249
end
252250
end
253251

254-
if (GVars.features.vehicle.no_turbulence) then
252+
if (cfg.no_turbulence) then
255253
self:DisableAirTurbulence()
256254
end
257255

SSV2/includes/frontend/vehicle/aircraft_ui.lua

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99

1010
local flrs = require("includes.features.vehicle.flares")
11+
Flares = LocalPlayer:GetVehicle():AddFeature(flrs)
1112
local autopilot_state_idx = 0
1213
local autopilot_index_changed = false
1314
local autopilot_labels
1415
local planes_tab = GUI:RegisterNewTab(Enums.eTabID.TAB_VEHICLE, "SUBTAB_AIRCRAFT", nil, nil, true)
15-
Flares = LocalPlayer:GetVehicle():AddFeature(flrs)
1616
local optionPopup = {
1717
flags = ImGuiWindowFlags.NoResize | ImGuiWindowFlags.AlwaysAutoResize,
1818
label = "##optionsPopup",
@@ -50,7 +50,18 @@ planes_tab:AddBoolCommand("VEH_FAST_JETS",
5050
gvar_key = "features.vehicle.fast_jets",
5151
translate_label = true,
5252
meta = { description = "VEH_FAST_JETS_TT", isTranslatorLabel = true },
53-
register_command = true
53+
register_command = true,
54+
options_data = {
55+
condition = function() return GVars.features.vehicle.fast_jets end,
56+
callback = function()
57+
optionPopup.callback = function()
58+
local cfg = GVars.features.vehicle
59+
cfg.fast_jets_speed = ImGui.SliderFloat("##speed", cfg.fast_jets_speed, 100.0, 300.0)
60+
end
61+
optionPopup.label = _T("VEH_FAST_JETS")
62+
optionPopup.should_draw = true
63+
end
64+
}
5465
}
5566
)
5667
planes_tab:AddBoolCommand("VEH_NO_JET_STALL",

SSV2/includes/frontend/vehicle/vehicle_ui.lua

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,20 @@ vehicleTab:AddBoolCommand("VEH_FAST_AF",
281281
{
282282
gvar_key = "features.vehicle.fast_vehicles",
283283
meta = { description = "VEH_FAST_AF_TT" },
284-
translate_label = true
284+
translate_label = true,
285+
options_data = {
286+
condition = function()
287+
return GVars.features.vehicle.fast_vehicles
288+
end,
289+
callback = function()
290+
optionPopup.callback = function()
291+
local cfg = GVars.features.vehicle
292+
cfg.fast_vehicles_speed = ImGui.SliderFloat("##speed", cfg.fast_vehicles_speed, 10.0, 100.0)
293+
end
294+
optionPopup.label = _T("VEH_FAST_AF")
295+
optionPopup.should_draw = true
296+
end
297+
}
285298
}
286299
)
287300
vehicleTab:AddBoolCommand("VEH_NOS",

SSV2/includes/modules/Entity.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,12 @@ end
346346

347347
---@return boolean
348348
function Entity:IsOutside()
349-
return self:GetInteriorID() == 0
349+
local interiorID = self:GetInteriorID()
350+
if (interiorID == 0) then
351+
return true
352+
end
353+
local groupID = INTERIOR.GET_INTERIOR_GROUP_ID(interiorID)
354+
return groupID > 0
350355
end
351356

352357
---@return joaat_t

SSV2/includes/modules/PlayerVehicle.lua

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ local ManualGearbox = require("includes.features.vehicle.manual_gearbox")
4848
---@field private m_threads array<Thread>
4949
---@field private m_default_max_speed float
5050
---@field private m_has_loud_radio boolean
51+
---@field private m_top_speed_modified boolean
5152
---@field private m_generic_toggleables table<string, GenericToggleable>
5253
---@field public m_default_xenon_lights { enabled: boolean, index: integer }
5354
---@field public m_default_tire_smoke { enabled: boolean, color: vec3 }
@@ -193,19 +194,19 @@ function PlayerVehicle:Set(handle)
193194
self.m_autopilot.eligible = self:IsAircraft()
194195

195196

196-
local feats_cfg = GVars.features.vehicle
197-
if (feats_cfg.no_turbulence and VEHICLE.IS_THIS_MODEL_A_PLANE(new_model)) then
197+
local cfg = GVars.features.vehicle
198+
if (cfg.no_turbulence and VEHICLE.IS_THIS_MODEL_A_PLANE(new_model)) then
198199
VEHICLE.SET_PLANE_TURBULENCE_MULTIPLIER(handle, 0.0)
199200
end
200201

201-
if (feats_cfg.default_station.enabled) then
202-
self:SetRadioStation(feats_cfg.default_station.station_name)
202+
if (cfg.default_station.enabled) then
203+
self:SetRadioStation(cfg.default_station.station_name)
203204
end
204205

205206
self.m_flag_controller:ApplyPresets()
206207
self.m_stancer:OnNewVehicle()
207208

208-
if (feats_cfg.manual_gearbox.enabled) then
209+
if (cfg.manual_gearbox.enabled) then
209210
self.m_manual_gearbox:OnNewVehicle()
210211
end
211212
-- self:ResumeThreads()
@@ -607,42 +608,44 @@ function PlayerVehicle:Main()
607608
return
608609
end
609610

611+
local cfg = GVars.features.vehicle
610612
local handle = self:GetHandle()
611613

612-
if (GVars.features.vehicle.fast_vehicles) then
613-
if (self:GetMaxSpeed() <= 80) then
614-
VEHICLE.MODIFY_VEHICLE_TOP_SPEED(handle, 100)
615-
end
616-
elseif (self:GetMaxSpeed() >= 80) then
614+
if (cfg.fast_vehicles) then
615+
VEHICLE.MODIFY_VEHICLE_TOP_SPEED(handle, cfg.fast_vehicles_speed or 10)
616+
self.m_top_speed_modified = true
617+
elseif (self.m_top_speed_modified) then
617618
VEHICLE.MODIFY_VEHICLE_TOP_SPEED(handle, -1)
619+
self.m_top_speed_modified = false
618620
end
619621

620-
if (GVars.features.vehicle.subwoofer and (not self:HasLoudRadio() or not self.m_generic_toggleables["subwoofer"])) then
622+
if (cfg.subwoofer and (not self:HasLoudRadio() or not self.m_generic_toggleables["subwoofer"])) then
621623
self:AddGenericToggleable("subwoofer", function()
622624
self:ToggleSubwoofer(true)
623625
end, self.ToggleSubwoofer, { self, false })
624626
end
625627

626-
if (GVars.features.vehicle.unbreakable_windows) then
628+
if (cfg.unbreakable_windows) then
627629
local native = VEHICLE.SET_DONT_PROCESS_VEHICLE_GLASS
628630
self:AddGenericToggleable("strongwindows", function()
629631
native(handle, true)
630632
end, native, { handle, false })
631633
end
632634

633-
if (GVars.features.vehicle.auto_brake_lights and LocalPlayer:IsDriving()) then
635+
if (cfg.auto_brake_lights and LocalPlayer:IsDriving()) then
634636
if (self:IsDriveable() and self:IsEngineOn() and not self:IsMoving() and not PAD.IS_CONTROL_PRESSED(0, 72)) then
635637
VEHICLE.SET_VEHICLE_BRAKE_LIGHTS(handle, true)
636638
end
637639
end
638640

639-
self.m_is_flatbed = self:IsFlatbedTruck()
641+
self.m_is_flatbed = self:IsFlatbedTruck()
640642
self.m_engine_swap_compatible = self:IsCar()
643+
641644
self.m_feat_mgr:Update()
642645
self:UpdateESC()
643646
self:AutoLock()
644647
self:HandleAutopilot()
645-
Speedometer:UpdateState()
648+
Speedometer:UpdateState(self)
646649
end
647650

648651
-- Just for convenience so we don't have to remember patch names.

0 commit comments

Comments
 (0)