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

Add ENTITY:DeterminePhysgunHalo() for all entities #2151

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
75 changes: 63 additions & 12 deletions garrysmod/gamemodes/sandbox/gamemode/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,44 +115,95 @@ function GM:PostRenderVGUI()

end

local PhysgunHalos = {}
local physgunHalos = {}

--[[---------------------------------------------------------
Name: gamemode:DrawPhysgunBeam()
Desc: Return false to override completely
-----------------------------------------------------------]]
function GM:DrawPhysgunBeam( ply, weapon, bOn, target, boneid, pos )

if ( physgun_halo:GetInt() == 0 ) then return true end
if ( !physgun_halo:GetBool() ) then

physgunHalos = nil

return true

if ( IsValid( target ) ) then
PhysgunHalos[ ply ] = target
end

if ( !IsValid( target ) ) then return true end

physgunHalos = physgunHalos || {}

local entsToHalo = {}

local haloColor = ply:GetWeaponColor() + VectorRand() * 0.3
local haloSize = math.random( 1, 2 )

haloColor = Color( haloColor.r * 255, haloColor.g * 255, haloColor.b * 255, 255 )

local DeterminePhysgunHalo = target.DeterminePhysgunHalo

if ( DeterminePhysgunHalo ) then

local val, color, size = DeterminePhysgunHalo( target, ply, haloColor, haloSize, weapon, boneid, pos )

if ( val != nil ) then

haloColor = color or haloColor
haloSize = size or haloSize

if ( isentity( val ) ) then

entsToHalo[ 1 ] = val

elseif ( istable( val ) ) then

entsToHalo = val

end

end

else

entsToHalo[ 1 ] = target

end

-- We put these in the table for convenience
entsToHalo.color = haloColor
entsToHalo.size = haloSize

physgunHalos[ ply ] = entsToHalo

return true

end

hook.Add( "PreDrawHalos", "AddPhysgunHalos", function()

if ( !PhysgunHalos || table.IsEmpty( PhysgunHalos ) ) then return end
if ( !physgunHalos ) then return end

for ply, entsToHalo in pairs( physgunHalos ) do

for k, v in pairs( PhysgunHalos ) do
if ( !IsValid( ply ) or !entsToHalo[ 1 ] ) then continue end

if ( !IsValid( k ) ) then continue end
local size = entsToHalo.size
local color = entsToHalo.color

local size = math.random( 1, 2 )
local colr = k:GetWeaponColor() + VectorRand() * 0.3
-- Remove these from the table, we got what we needed - halo.Add only accepts entities
entsToHalo.size = nil
entsToHalo.color = nil

halo.Add( PhysgunHalos, Color( colr.x * 255, colr.y * 255, colr.z * 255 ), size, size, 1, true, false )
halo.Add( entsToHalo, color, size, size, 1, true, false )

end

PhysgunHalos = {}
physgunHalos = {}

end )


--[[---------------------------------------------------------
Name: gamemode:NetworkEntityCreated()
Desc: Entity is created over the network
Expand Down