Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Megascan #59

Merged
merged 5 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lua/entities/base_glide/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ do
local seats = self.seats
if not seats then return end

if hook.Run( "Glide_CanDrawHUDSeats", self ) == false then return end

local t = RealTime()
local localPly = LocalPlayer()

Expand Down
18 changes: 17 additions & 1 deletion lua/entities/base_glide/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function ENT:Use( activator )
if not IsValid( activator ) then return end
if not activator:IsPlayer() then return end

local freeSeat = self:GetFreeSeat()
local freeSeat = self:GetClosestAvailableSeat( activator:GetShootPos() )
if freeSeat then
activator:SetAllowWeaponsInVehicle( false )
activator:EnterVehicle( freeSeat )
Expand Down Expand Up @@ -348,6 +348,22 @@ function ENT:GetFreeSeat()
end
end

--- Gets the closest available seat to a position.
function ENT:GetClosestAvailableSeat( pos )
local closestSeat = nil
local closestDistance = math.huge
for _, seat in ipairs( self.seats ) do
if IsValid( seat:GetDriver() ) then continue end
local distance = seat:GetPos():DistToSqr( pos )
if distance < closestDistance then
closestSeat = seat
closestDistance = distance
end
end

return closestSeat
end

--- Create a new seat.
---
--- `offset` is the seat's position relative to the chassis.
Expand Down
1 change: 1 addition & 0 deletions lua/entities/base_glide_car/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ local w, h, x, y

--- Override this base class function.
function ENT:DrawVehicleHUD( screenW, screenH )
if hook.Run( "Glide_CanDrawHUD", self ) == false then return end
BaseClass.DrawVehicleHUD( self, screenW, screenH )

if not Config.showHUD then return end
Expand Down
15 changes: 14 additions & 1 deletion lua/glide/server/ragdoll.lua
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ local function PoseRagdollBones( ragdoll, bones, velocity )
end

function Glide.RagdollPlayer( ply, velocity, unragdollTime )
local success, velocity_override, unragdollTimeOverride = hook.Run( "Glide_CanRagdollPlayer", ply, velocity, unragdollTime )
if success == false then return end

velocity = velocity_override or velocity
unragdollTime = unragdollTimeOverride or unragdollTime

if ply.GlideRagdoll then return end

local bones = GetAllBones( ply )
Expand All @@ -170,6 +176,7 @@ function Glide.RagdollPlayer( ply, velocity, unragdollTime )
return
end

hook.Run( "Glide_PrePlayerRagdoll", ply )
-- Create ragdoll
local ragdoll = ents.Create( "prop_ragdoll" )
if not IsValid( ragdoll ) then return end
Expand Down Expand Up @@ -228,6 +235,8 @@ function Glide.RagdollPlayer( ply, velocity, unragdollTime )
Glide.UnRagdollPlayer( ply )
end )
end

hook.Run( "Glide_PostPlayerRagdoll", ply )
end

local traceData = {
Expand Down Expand Up @@ -261,6 +270,8 @@ end
function Glide.UnRagdollPlayer( ply, restoreCallback )
if not IsValid( ply ) then return end

hook.Run( "Glide_PrePlayerUnRagdoll", ply )

timer.Remove( "Glide_Ragdoll_" .. ply:EntIndex() )

-- Make sure this player is still ragdolled
Expand Down Expand Up @@ -315,6 +326,8 @@ function Glide.UnRagdollPlayer( ply, restoreCallback )

-- Reset Custom Loadout workaround
ply.GlideBlockLoadout = nil

hook.Run( "Glide_PostPlayerUnRagdoll", ply )
end

hook.Add( "CanTool", "Glide.BlockPlayerRagdolls", function( _, tr )
Expand Down Expand Up @@ -342,7 +355,7 @@ hook.Add( "PlayerDisconnected", "Glide.CleanupPlayerRagdolls", function( ply )
end )

hook.Add( "PreCleanupMap", "Glide.CleanupPlayerRagdolls", function()
for _, ply in ipairs( player.GetAll() ) do
for _, ply in player.Iterator() do
Glide.UnRagdollPlayer( ply )
end
end )
Expand Down
18 changes: 13 additions & 5 deletions lua/glide/server/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@
local IsValid = IsValid

function Glide.CanSpawnVehicle( ply )
if hook.Run( "Glide_CanSpawnVehicle", ply ) == false then return false end

if not IsValid( ply ) then return false end
if not ply:CheckLimit( "glide_vehicles" ) then return false end

Expand Down Expand Up @@ -182,17 +184,21 @@
end
end

return false
return hook.Run( "Glide_CanLockVehicle", ply, vehicle) or false

Check warning on line 187 in lua/glide/server/util.lua

View workflow job for this annotation

GitHub Actions / Lint / lint

"Space before parenthesis"

Style: Please add a space before the parenthesis
end

--- Check if a player can enter a locked vehicle.
function Glide.CanEnterLockedVehicle( ply, vehicle )
return Glide.CanLockVehicle( ply, vehicle )
return hook.Run( "Glide_CanEnterLockedVehicle", ply, vehicle ) or Glide.CanLockVehicle( ply, vehicle )
end

--- Make a player switch to another seat
--- while inside a Glide vehicle.
function Glide.SwitchSeat( ply, seatIndex )
if hook.Run( "Glide_CanSwitchSeat", ply, seatIndex ) == false then return end

hook.Run( "Glide_PreSwitchSeat", ply, seatIndex )

local vehicle = ply:GlideGetVehicle()
if not IsValid( vehicle ) then return end

Expand All @@ -210,17 +216,19 @@
ply:ExitVehicle()
ply:SetAllowWeaponsInVehicle( false )
ply:EnterVehicle( seat )
end

local GetHumans = player.GetHumans
hook.Run( "Glide_PostSwitchSeat", ply, seatIndex )
end

--- Finds and returns all human players near a certain position.
function Glide.GetNearbyPlayers( pos, radius )
radius = radius * radius

local found, count = {}, 0

for _, ply in ipairs( GetHumans() ) do
for _, ply in player.Iterator() do
if ply:IsBot() then continue end

local dist = pos:DistToSqr( ply:GetPos() )

if dist < radius then
Expand Down
Loading