Skip to content

Commit

Permalink
Item: Reworked ShouldDrawCosmetics hook
Browse files Browse the repository at this point in the history
  • Loading branch information
FluffyXVI committed May 17, 2019
1 parent 9add4bc commit 48579d9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
13 changes: 0 additions & 13 deletions fluffy_mg_base/gamemode/gametype_hunter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,4 @@ hook.Add('DoPlayerDeath', 'AwardLastSurvivor', function(ply)
GAMEMODE:PulseAnnouncement(4, name .. ' is the lone survivor!', 0.8)
last_player:AddStatPoints('LastSurvivor', 1)
end
end)

-- Disable cosmetics
hook.Add('ShouldDrawCosmetics', 'HideHunterCosmetics', function(ply, ITEM)
if GAMEMODE.TeamSurvival then
-- Cosmetics shouldn't show for the Hunter Team (in most cases)
-- Override in some cases
if ply:Team() == GAMEMODE.HunterTeam then
return false
else
return true
end
end
end)
6 changes: 0 additions & 6 deletions fluffy_mg_base/gamemode/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ function GM:CreateTeams()
team.SetSpawnPoint(TEAM_SPECTATOR, {"info_player_terrorist", "info_player_combine", "info_player_counterterrorist", "info_player_rebel"})
end

-- Function to toggle displaying cosmetics
-- Obviously, cosmetic items shouldn't be displayed on barrels etc.
function GM:ShouldDrawCosmetics(ply, ITEM)
return hook.Run('DrawCosmeticsCheck', ply, ITEM) or true
end

-- Valid playermodels
GM.ValidModels = {
male01 = "models/player/Group01/male_01.mdl",
Expand Down
7 changes: 7 additions & 0 deletions fluffy_mg_base/gamemode/shop/sh_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ function SHOP:LoadResources()
include('fluffy_mg_base/gamemode/shop/item/paint_master.lua')
end

-- Add the cosmetics check hook function
-- This function is hooked into various gamemodes to stop cosmetics from being drawn when they shouldn't be
-- Key examples of this is to override tracers, hide hats on certain playermodels, etc.
function GM:ShouldDrawCosmetics(ply, ITEM)
return hook.Run('DrawCosmeticsCheck', ply, ITEM) or true
end

SHOP:LoadResources()

if SERVER then
Expand Down
5 changes: 4 additions & 1 deletion fluffy_mg_base/gamemode/shop/sv_equip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ function SHOP:UnequipTrail(ply)
end

-- Wear a trail
function SHOP:WearTrail(ply)
function SHOP:WearTrail(ply, force)
if ply.EquippedTrail then
local ITEM = ply.EquippedTrail
if not GAMEMODE:ShouldDrawCosmetics(ply, ITEM) and not force then return end
ply.TrailEntity = util.SpriteTrail(ply, 0, ITEM.Color or color_white, false, 20, 2, 2.5, 0.1, ITEM.Material)
end
end
Expand Down Expand Up @@ -73,6 +74,8 @@ hook.Add('EntityFireBullets', 'ShopTracerEffects', function(ent, data)
if !ent:IsPlayer() then return end
local effect = ent:GetNWString('ShopTracerEffect')
if not effect then return end

if not GAMEMODE:ShouldDrawCosmetics(ent, {Type='Tracer'}) then return end

data.Tracer = 1
data.TracerName = effect
Expand Down

0 comments on commit 48579d9

Please sign in to comment.