Skip to content

Commit

Permalink
Turret toggle/FLIR inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
thecraftianman committed Jun 18, 2024
1 parent 4f0549b commit 084ff98
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lua/entities/acf_vehicle/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local LocalPlayer = LocalPlayer
local MouseScrollDelta = 0
-- local SmoothDistance = 0
local LastFOV = 0
local CurDistance = 150
-- local CurDistance = 150

local WorldCamMins = Vector(-4, -4, -4)
local WorldCamMaxs = Vector(4, 4, 4)
Expand Down Expand Up @@ -42,9 +42,9 @@ hook.Add("InputMouseApply", "ACF_VehicleZoomScroll", function(Cmd)
if Vehicle.CamZoom == 0 then return end

local MouseWheel = -Cmd:GetMouseWheel()
local test = math.max((math.abs(CurDistance) + math.abs(MouseWheel)) / 10, 10)
-- local test = math.max((math.abs(CurDistance) + math.abs(MouseWheel)) / 10, 10)
--print(test)
MouseScrollDelta = math.Clamp(MouseScrollDelta - MouseWheel * test, -95, 100) -- -2000, 180)
MouseScrollDelta = math.Clamp(MouseScrollDelta - MouseWheel * 2, 0, 100) -- -2000, 180)
--print(MouseScrollDelta)
end)

Expand Down
62 changes: 53 additions & 9 deletions lua/entities/acf_vehicle/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ local PlayerOutputBinds = {
[IN_ATTACK2] = "Mouse2",
[IN_RELOAD] = "R",

[IN_WEAPON2] = "PrevWeapon",
[IN_WEAPON1] = "NextWeapon",
-- [IN_WEAPON2] = "PrevWeapon",
-- [IN_WEAPON1] = "NextWeapon",
-- ["impulse 100"] = "Light",
}

Expand All @@ -42,7 +42,10 @@ do -- Spawning and Updating
-- CFW.addParentDetour("acf_vehicle", "Pod")

local Inputs = {
"Toggle Turret (Toggles the use of any linked turret drives.)",
"FLIR (Enables FLIR filter for the driver.)",
}

local Outputs = {
"W", "A", "S", "D", "Mouse1", "Mouse2",
"R", "Space", "Shift", "Zoom", "Alt", "Duck", -- "Noclip",
Expand Down Expand Up @@ -170,6 +173,7 @@ do -- Spawning and Updating
Entity.Throttle = 0
Entity.CanEnter = true
Entity.GearboxSetup = "Unknown"
Entity.TurretLocked = false

Pod:SetAngles(Ang)
Pod:SetModel("models/vehicles/pilot_seat.mdl")
Expand Down Expand Up @@ -535,31 +539,38 @@ end

do
local Clock = Utilities.Clock
local DriverKeyDown = FindMetaTable("Player").KeyDown

local function RecacheBindOutput(Entity, SelfTbl, Output, Value)
if SelfTbl.Outputs[Output].Value == Value then return end
WireLib.TriggerOutput(Entity, Output, Value)
end

function ENT:Think()
local Pod = self.Pod
local SelfTbl = self:GetTable()
local Pod = SelfTbl.Pod
local Driver = Pod:GetDriver()
if not IsValid(Driver) then return end

local CamAng = Driver:LocalEyeAngles()
WireLib.TriggerOutput(self, "CamAng", CamAng)
RecacheBindOutput(self, SelfTbl, "CamAng", CamAng)

local Turrets = self.Turrets
local Turrets = SelfTbl.Turrets

-- Perform turret outputs
if next(Turrets) then
if next(Turrets) and not SelfTbl.TurretLocked then
local InputAngle = Pod:LocalToWorldAngles(CamAng)

for Turret, _ in pairs(Turrets) do
Turret:InputDirection(InputAngle)
end
end

local Engines = self.Engines
local Engines = SelfTbl.Engines

-- Perform engine outputs
if next(Engines) then
local IsInMovement = Driver:KeyDown(IN_FORWARD) or Driver:KeyDown(IN_MOVELEFT) or Driver:KeyDown(IN_MOVERIGHT) or Driver:KeyDown(IN_BACK)
local IsInMovement = DriverKeyDown(Driver, IN_FORWARD) or DriverKeyDown(Driver, IN_MOVELEFT) or DriverKeyDown(Driver, IN_MOVERIGHT) or DriverKeyDown(Driver, IN_BACK)
local Throttle = IsInMovement and 100 or 0

for Engine in pairs(Engines) do
Expand All @@ -572,7 +583,8 @@ do

-- Perform player key outputs
for Bind, Output in pairs(PlayerOutputBinds) do
WireLib.TriggerOutput(self, Output, Driver:KeyDown(Bind) and 1 or 0)
--WireLib.TriggerOutput(self, Output, Driver:KeyDown(Bind) and 1 or 0)
RecacheBindOutput(self, SelfTbl, Output, DriverKeyDown(Driver, Bind) and 1 or 0)
end

self:NextThink(Clock.CurTime)
Expand All @@ -581,6 +593,38 @@ do
end
end

do
ACF.AddInputAction("acf_vehicle", "Toggle Turret", function(Entity, Value)
Value = tobool(Value)
if not Value then return end

Entity.TurretLocked = not Entity.TurretLocked

if Entity.TurretLocked == true then
for Turret, _ in pairs(Entity.Turrets) do
Turret:InputDirection(Turret.CurrentAngle)
--Turret:TriggerInput("Active", Entity.TurretLocked and 0 or 1)
end
end
end)

ACF.AddInputAction("acf_vehicle", "FLIR", function(Entity, Value)
local Pod = Entity.Pod
if not IsValid(Pod) then return end

local Driver = Pod:GetDriver()
if not IsValid(Driver) then return end

Value = tobool(Value)

if Value then
FLIR.start(Driver)
else
FLIR.stop(Driver)
end
end)
end

do -- Dupe Support
function ENT:PreEntityCopy()
local Turrets = self.Turrets
Expand Down

0 comments on commit 084ff98

Please sign in to comment.