-- shaed extensions to player table local plymeta = FindMetaTable( "Player" ) if not plymeta then return end function plymeta:IsTerror() return self:Team() == TEAM_TERROR end function plymeta:IsSpec() return self:Team() == TEAM_SPEC end AccessorFunc(plymeta, "role", "Role", FORCE_NUMBER) -- Role access function plymeta:GetTraitor() return self:GetRole() == ROLE_TRAITOR end function plymeta:GetDetective() return self:GetRole() == ROLE_DETECTIVE end plymeta.IsTraitor = plymeta.GetTraitor plymeta.IsDetective = plymeta.GetDetective function plymeta:IsSpecial() return self:GetRole() != ROLE_INNOCENT end -- Player is alive and in an active round function plymeta:IsActive() return self:IsTerror() and GetRoundState() == ROUND_ACTIVE end -- convenience functions for common patterns function plymeta:IsRole(role) return self:GetRole() == role end function plymeta:IsActiveRole(role) return self:IsRole(role) and self:IsActive() end function plymeta:IsActiveTraitor() return self:IsActiveRole(ROLE_TRAITOR) end function plymeta:IsActiveDetective() return self:IsActiveRole(ROLE_DETECTIVE) end function plymeta:IsActiveSpecial() return self:IsSpecial() and self:IsActive() end local role_strings = { [ROLE_TRAITOR] = "traitor", [ROLE_INNOCENT] = "innocent", [ROLE_DETECTIVE] = "detective" }; local GetRTranslation = CLIENT and LANG.GetRawTranslation or util.passthrough -- Returns printable role function plymeta:GetRoleString() return GetRTranslation(role_strings[self:GetRole()]) or "???" end -- Returns role language string id, caller must translate if desired function plymeta:GetRoleStringRaw() return role_strings[self:GetRole()] end function plymeta:GetBaseKarma() return self:GetNWFloat("karma", 1000) end function plymeta:HasEquipmentWeapon() for _, wep in pairs(self:GetWeapons()) do if ValidEntity(wep) and wep:IsEquipment() then return true end end return false end function plymeta:CanCarryWeapon(wep) if (not wep) or (not wep.Kind) then return false end return self:CanCarryType(wep.Kind) end function plymeta:CanCarryType(t) if not t then return false end for _, w in pairs(self:GetWeapons()) do if w.Kind and w.Kind == t then return false end end return true end function plymeta:IsDeadTerror() return (self:IsSpec() and not self:Alive()) end function plymeta:HasBought(id) return self.bought and table.HasValue(self.bought, id) end function plymeta:GetCredits() return self.equipment_credits or 0 end function plymeta:GetEquipmentItems() return self.equipment_items or EQUIP_NONE end -- Given an equipment id, returns if player owns this. Given nil, returns if -- player has any equipment item. function plymeta:HasEquipmentItem(id) if not id then return self:GetEquipmentItems() != EQUIP_NONE else -- eh, 1 << x returns a string? --return self:GetEquipmentItems() & (1 << id) > 0 return self:GetEquipmentItems() & id == id end end function plymeta:HasEquipment() return self:HasEquipmentItem() or self:HasEquipmentWeapon() end if CLIENT then -- Server has this, but isn't shared for some reason function plymeta:HasWeapon(cls) for _, wep in pairs(self:GetWeapons()) do if IsValid(wep) and wep:GetClass() == cls then return true end end return false end local gmod_GetWeapons = plymeta.GetWeapons function plymeta:GetWeapons() if self != LocalPlayer() then return {} else return gmod_GetWeapons(self) end end end -- Override GetEyeTrace for an optional trace mask param. Technically traces -- like GetEyeTraceNoCursor but who wants to type that all the time, and we -- never use cursor tracing anyway. function plymeta:GetEyeTrace(mask) if self.LastPlayerTraceMask == mask and self.LastPlayerTrace == CurTime() then return self.PlayerTrace end local tr = util.GetPlayerTrace(self) tr.mask = mask self.PlayerTrace = util.TraceLine(tr) self.LastPlayerTrace = CurTime() self.LastPlayerTraceMask = mask return self.PlayerTrace end