Skip to content

Commit

Permalink
Refactor a good chunk of vehicle code
Browse files Browse the repository at this point in the history
  • Loading branch information
ZehMatt committed Jun 7, 2024
1 parent ed3ad8c commit bd7e023
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 177 deletions.
9 changes: 4 additions & 5 deletions entities/entities/lambda_vehicle_tracker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@ function ENT:Initialize()
end

self:DrawShadow(false)
--self:AddEffects(EF_NODRAW)
end

function ENT:AttachToVehicle(vehicle)
self:SetModel(vehicle:GetModel())
self:SetPos(vehicle:GetPos())
self:SetAngles(vehicle:GetAngles())
self:SetParent(vehicle)
--self:AddEffects(EF_NODRAW)
self:DrawShadow(false)
self.Vehicle = vehicle
self.Player = vehicle.LambdaPlayer
self.Player = GAMEMODE:VehicleGetPlayerOwner(vehicle)
self:SetNWEntity("LambdaVehicleOwner", self.Player)
self:SetNWBool("LambdaVehicleTaken", IsValid(self.Player))
end
Expand All @@ -50,8 +48,9 @@ if SERVER then
return
end

if self.Player ~= vehicle.LambdaPlayer then
self.Player = vehicle.LambdaPlayer
local vehicleOwner = GAMEMODE:VehicleGetPlayerOwner(vehicle)
if self.Player ~= vehicleOwner then
self.Player = vehicleOwner
self:SetNWEntity("LambdaVehicleOwner", self.Player)
self:SetNWBool("LambdaVehicleTaken", IsValid(self.Player))
DbgPrint("Owner changed")
Expand Down
4 changes: 2 additions & 2 deletions gamemode/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function GM:CalcViewModelView(wep, vm, oldPos, oldAng, vm_origin, vm_angles)
local ply = wep:GetOwner()
if IsValid(ply) and IsValid(ply:GetVehicle()) then
local vehicle = ply:GetVehicle()
if vehicle:GetNWBool("IsPassengerSeat", false) == true then
if self:VehicleIsPassengerSeat(vehicle) == true then
local ang = oldAng
local eyeAng = ply:GetAimVector():Angle()
ang:Set(eyeAng + ply:GetViewPunchAngles())
Expand Down Expand Up @@ -305,7 +305,7 @@ function GM:CalcView(ply, pos, ang, fov, nearZ, farZ)
local vehicle = ply:GetVehicle()
local wep = ply:GetActiveWeapon()
if IsValid(vehicle) then
if vehicle:GetNWBool("IsPassengerSeat", false) == true then
if self:VehicleIsPassengerSeat(vehicle) == true then
local eyeAng = ply:GetAimVector():Angle()
ang:Set(eyeAng + ply:GetViewPunchAngles())
local _, localang = WorldToLocal(Vector(0, 0, 0), ang, Vector(0, 0, 0), vehicle:GetAngles())
Expand Down
1 change: 1 addition & 0 deletions gamemode/gametypes/base/cl_localisation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@ LOCALISATION["english"] = {
["GM_DM_TIMELIMIT_DESC"] = "Set how long the round lasts",
["GM_DM_TEAMONLY"] = "Team based deathmatch",
["GM_DM_TEAMONLY_DESC"] = "Switch between DM or TDM",
["LAMBDA_VEHICLE_TAKE_OVER"] = "Take over vehicle %+speed%+%+use%"
}
return LOCALISATION
2 changes: 0 additions & 2 deletions gamemode/sh_hudhint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ else -- CLIENT

local function LocalizeWithInput(text, default)
local msg = language.GetPhrase(text, default)
if msg == text then return msg end
-- Process key bindings.
local i = 1

while i ~= nil do
local pos = string.find(msg, "%", i, true)
if pos == nil then break end
Expand Down
26 changes: 26 additions & 0 deletions gamemode/sh_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -542,4 +542,30 @@ function util.GetAllPlayers()
end

return PLAYER_LIST_CACHE
end

local function IsPlayerNearby(pos, ply, radius)
if ply:Alive() == false then
return false
end
if ply:GetPos():Distance(pos) <= radius then
return true
end
return false
end

function util.IsPlayerNearby(entOrPos, radius)
local pos = entOrPos

if IsEntity(entOrPos) then
pos = entOrPos:GetPos()
end

for _, ply in pairs(util.GetAllPlayers()) do
if IsPlayerNearby(pos, ply, radius) then
return true
end
end

return false
end
Loading

0 comments on commit bd7e023

Please sign in to comment.