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

TTT: Allow detectives to reequip their dropped hat #962

Merged
merged 5 commits into from May 24, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -5,6 +5,8 @@ ENT.Type = "anim"
ENT.Base = "base_anim"

ENT.Model = Model("models/ttt/deerstalker.mdl")
ENT.CanHavePrints = false
ENT.CanUseKey = true

AccessorFuncDT(ENT, "worn", "BeingWorn")

Expand Down Expand Up @@ -33,6 +35,9 @@ function ENT:Initialize()
end

if SERVER then
local ttt_hats_reclaim = CreateConVar("ttt_detective_hats_reclaim", "1")
local ttt_hats_innocent = CreateConVar("ttt_detective_hats_reclaim_any", "0")

function ENT:OnRemove()
self:SetBeingWorn(false)
end
Expand All @@ -44,6 +49,7 @@ if SERVER then
self:SetParent(nil)

self:SetBeingWorn(false)
self:SetUseType(SIMPLE_USE)

-- only now physics this entity
self:PhysicsInit(SOLID_VPHYSICS)
Expand Down Expand Up @@ -86,6 +92,39 @@ if SERVER then
end
end

local function CanEquipHat(ply)
return not IsValid(ply.hat) and
(ttt_hats_innocent:GetBool() or ply:GetRole() == ROLE_DETECTIVE)
end

function ENT:UseOverride(ply)
if not ttt_hats_reclaim:GetBool() then return end

if IsValid(ply) and not self:GetBeingWorn() then
if GetRoundState() != ROUND_ACTIVE then
SafeRemoveEntity(self)
return
elseif not CanEquipHat(ply) then
return
end

sound.Play("weapon.ImpactSoft", self:GetPos(), 75, 100, 1)

self:SetMoveType(MOVETYPE_NONE)
self:SetSolid(SOLID_NONE)
self:SetCollisionGroup(COLLISION_GROUP_DEBRIS)

self:SetParent(ply)
self.Wearer = ply

ply.hat = self.Entity

self:SetBeingWorn(true)

LANG.Msg(activator, "hat_retrieve")
end
end

local function TestHat(ply, cmd, args)
if cvars.Bool("sv_cheats", 0) then
local hat = ents.Create("ttt_hat_deerstalker")
Expand Down
3 changes: 3 additions & 0 deletions garrysmod/gamemodes/terrortown/gamemode/lang/english.lua
Expand Up @@ -1059,3 +1059,6 @@ L.drop_no_ammo = "Insufficient ammo in your weapon's clip to drop as an ammo box
--- v31
L.set_cross_brightness = "Crosshair brightness"
L.set_cross_size = "Crosshair size"

--- v?? (05-22-15:m-d-y)
L.hat_retrieve = "You picked up a Detective's hat."