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: Replace most UniqueID usage with SteamID #1182

Merged
merged 2 commits into from May 26, 2016
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 @@ -136,8 +136,8 @@ end
function SWEP:GatherRagdollSample(ent)
local sample = ent.killer_sample or {t=0, killer=nil}
local ply = sample.killer
if (not IsValid(ply)) and sample.killer_uid then
ply = player.GetByUniqueID(sample.killer_uid)
if (not IsValid(ply)) and sample.killer_sid then
ply = player.GetBySteamID(sample.killer_sid)
end


Expand Down
2 changes: 1 addition & 1 deletion garrysmod/gamemodes/terrortown/gamemode/admin.lua
Expand Up @@ -60,7 +60,7 @@ function PrintReport(ply)

for k, e in pairs(SCORE.Events) do
if e.id == EVENT_KILL then
if e.att.uid == -1 then
if e.att.sid == -1 then
pr("<something> killed " .. e.vic.ni .. (e.vic.tr and " [TRAITOR]" or " [inno.]"))
else
pr(e.att.ni .. (e.att.tr and " [TRAITOR]" or " [inno.]") .. " killed " .. e.vic.ni .. (e.vic.tr and " [TRAITOR]" or " [inno.]"))
Expand Down
60 changes: 30 additions & 30 deletions garrysmod/gamemodes/terrortown/gamemode/cl_awards.lua
Expand Up @@ -35,7 +35,7 @@ local function FirstSuicide(events, scores, players, traitors)
local fs = nil
local fnum = 0
for k, e in pairs(events) do
if e.id == EVENT_KILL and e.att.uid == e.vic.uid then
if e.id == EVENT_KILL and e.att.sid == e.vic.sid then
fnum = fnum + 1
if fs == nil then
fs = e
Expand Down Expand Up @@ -68,17 +68,17 @@ local function ExplosiveGrant(events, scores, players, traitors)
local bombers = {}
for k, e in pairs(events) do
if e.id == EVENT_KILL and is_dmg(e.dmg.t, DMG_BLAST) then
bombers[e.att.uid] = (bombers[e.att.uid] or 0) + 1
bombers[e.att.sid] = (bombers[e.att.sid] or 0) + 1
end
end

local award = {title= T("aw_exp1_title")}

if table.Count(bombers) > 0 then
for uid, num in pairs(bombers) do
for sid, num in pairs(bombers) do
-- award goes to whoever reaches this first I guess
if num > 2 then
award.nick = players[uid]
award.nick = players[sid]
if not award.nick then return nil end -- if player disconnected or something

award.text = PT("aw_exp1_text", {num = num})
Expand All @@ -96,7 +96,7 @@ end

local function ExplodedSelf(events, scores, players, traitors)
for k, e in pairs(events) do
if e.id == EVENT_KILL and is_dmg(e.dmg.t, DMG_BLAST) and e.att.uid == e.vic.uid then
if e.id == EVENT_KILL and is_dmg(e.dmg.t, DMG_BLAST) and e.att.sid == e.vic.sid then
return {title=T("aw_exp2_title"), text=T("aw_exp2_text"), nick=e.vic.ni, priority=math.random(1, 4)}
end
end
Expand All @@ -106,7 +106,7 @@ end

local function FirstBlood(events, scores, players, traitors)
for k, e in pairs(events) do
if e.id == EVENT_KILL and e.att.uid != e.vic.uid and e.att.uid != -1 then
if e.id == EVENT_KILL and e.att.sid != e.vic.sid and e.att.sid != -1 then
local award = {nick=e.att.ni}
if not award.nick or award.nick == "" then return nil end

Expand Down Expand Up @@ -182,11 +182,11 @@ local function NumKills_Traitor(events, scores, players, traitors)
if choices > 0 then
-- award a random killer
local pick = math.random(1, choices)
local uid = trs[pick]
local nick = players[uid]
local sid = trs[pick]
local nick = players[sid]
if not nick then return nil end

local kills = scores[uid].innos
local kills = scores[sid].innos
if kills == 1 then
return {title=T("aw_nkt1_title"), nick=nick, text=T("aw_nkt1_text"), priority=0}
elseif kills == 2 then
Expand Down Expand Up @@ -217,11 +217,11 @@ local function NumKills_Inno(events, scores, players, traitors)
if table.Count(ins) > 0 then
-- award a random killer
local pick = math.random(1, choices)
local uid = ins[pick]
local nick = players[uid]
local sid = ins[pick]
local nick = players[sid]
if not nick then return nil end

local kills = scores[uid].traitors
local kills = scores[sid].traitors
if kills == 1 then
return {title=T("aw_nki1_title"), nick=nick, text=T("aw_nki1_text"), priority = 0}
elseif kills == 2 then
Expand Down Expand Up @@ -264,7 +264,7 @@ local function Headshots(events, scores, players, traitors)
local hs = {}
for k, e in pairs(events) do
if e.id == EVENT_KILL and e.dmg.h and is_dmg(e.dmg.t, DMG_BULLET) then
hs[e.att.uid] = (hs[e.att.uid] or 0) + 1
hs[e.att.sid] = (hs[e.att.sid] or 0) + 1
end
end

Expand Down Expand Up @@ -300,7 +300,7 @@ local function UsedAmmoMost(events, ammotype)
local user = {}
for k, e in pairs(events) do
if e.id == EVENT_KILL and e.dmg.g == ammotype then
user[e.att.uid] = (user[e.att.uid] or 0) + 1
user[e.att.sid] = (user[e.att.sid] or 0) + 1
end
end

Expand All @@ -310,14 +310,14 @@ local function UsedAmmoMost(events, ammotype)

if not m_id then return nil end

return {uid=m_id, kills=m_num}
return {sid=m_id, kills=m_num}
end

local function CrowbarUser(events, scores, players, traitors)
local most = UsedAmmoMost(events, AMMO_CROWBAR)
if not most then return nil end

local nick = players[most.uid]
local nick = players[most.sid]
if not nick then return nil end

local award = {nick=nick, priority=most.kills + math.random(0, 4)}
Expand All @@ -340,7 +340,7 @@ local function PistolUser(events, scores, players, traitors)
local most = UsedAmmoMost(events, AMMO_PISTOL)
if not most then return nil end

local nick = players[most.uid]
local nick = players[most.sid]
if not nick then return nil end

local award = {nick=nick, priority=most.kills}
Expand All @@ -363,7 +363,7 @@ local function ShotgunUser(events, scores, players, traitors)
local most = UsedAmmoMost(events, AMMO_SHOTGUN)
if not most then return nil end

local nick = players[most.uid]
local nick = players[most.sid]
if not nick then return nil end

local award = {nick=nick, priority=most.kills}
Expand All @@ -386,7 +386,7 @@ local function RifleUser(events, scores, players, traitors)
local most = UsedAmmoMost(events, AMMO_RIFLE)
if not most then return nil end

local nick = players[most.uid]
local nick = players[most.sid]
if not nick then return nil end

local award = {nick=nick, priority=most.kills}
Expand All @@ -409,7 +409,7 @@ local function DeagleUser(events, scores, players, traitors)
local most = UsedAmmoMost(events, AMMO_DEAGLE)
if not most then return nil end

local nick = players[most.uid]
local nick = players[most.sid]
if not nick then return nil end

local award = {nick=nick, priority=most.kills}
Expand All @@ -433,7 +433,7 @@ local function MAC10User(events, scores, players, traitors)
local most = UsedAmmoMost(events, AMMO_MAC10)
if not most then return nil end

local nick = players[most.uid]
local nick = players[most.sid]
if not nick then return nil end

local award = {nick=nick, priority=most.kills}
Expand All @@ -456,7 +456,7 @@ local function SilencedPistolUser(events, scores, players, traitors)
local most = UsedAmmoMost(events, AMMO_SIPISTOL)
if not most then return nil end

local nick = players[most.uid]
local nick = players[most.sid]
if not nick then return nil end

local award = {nick=nick, priority=most.kills}
Expand All @@ -478,14 +478,14 @@ local function KnifeUser(events, scores, players, traitors)
local most = UsedAmmoMost(events, AMMO_KNIFE)
if not most then return nil end

local nick = players[most.uid]
local nick = players[most.sid]
if not nick then return nil end

local award = {nick=nick, priority=most.kills}
local kills = most.kills

if kills == 1 then
if table.HasValue(traitors, most.uid) then
if table.HasValue(traitors, most.sid) then
award.title = T("aw_knf1_title")
award.text = PT("aw_knf1_text", {num = kills})
award.priority = 0
Expand All @@ -511,7 +511,7 @@ local function FlareUser(events, scores, players, traitors)
local most = UsedAmmoMost(events, AMMO_FLARE)
if not most then return nil end

local nick = players[most.uid]
local nick = players[most.sid]
if not nick then return nil end

local award = {nick=nick, priority=most.kills}
Expand All @@ -533,7 +533,7 @@ local function M249User(events, scores, players, traitors)
local most = UsedAmmoMost(events, AMMO_M249)
if not most then return nil end

local nick = players[most.uid]
local nick = players[most.sid]
if not nick then return nil end

local award = {nick=nick, priority=most.kills}
Expand All @@ -555,7 +555,7 @@ local function M16User(events, scores, players, traitors)
local most = UsedAmmoMost(events, AMMO_M16)
if not most then return nil end

local nick = players[most.uid]
local nick = players[most.sid]
if not nick then return nil end

local award = {nick=nick, priority=most.kills}
Expand Down Expand Up @@ -638,7 +638,7 @@ local function Burner(events, scores, players, traitors)
local brn = {}
for k, e in pairs(events) do
if e.id == EVENT_KILL and is_dmg(e.dmg.t, DMG_BURN) then
brn[e.att.uid] = (brn[e.att.uid] or 0) + 1
brn[e.att.sid] = (brn[e.att.sid] or 0) + 1
end
end

Expand Down Expand Up @@ -674,7 +674,7 @@ local function Coroner(events, scores, players, traitors)
local finders = {}
for k, e in pairs(events) do
if e.id == EVENT_BODYFOUND then
finders[e.uid] = (finders[e.uid] or 0) + 1
finders[e.sid] = (finders[e.sid] or 0) + 1
end
end

Expand Down Expand Up @@ -709,7 +709,7 @@ local function CreditFound(events, scores, players, traitors)
local finders = {}
for k, e in pairs(events) do
if e.id == EVENT_CREDITFOUND then
finders[e.uid] = (finders[e.uid] or 0) + e.cr
finders[e.sid] = (finders[e.sid] or 0) + e.cr
end
end

Expand Down
4 changes: 2 additions & 2 deletions garrysmod/gamemodes/terrortown/gamemode/cl_scoring.lua
Expand Up @@ -497,8 +497,8 @@ function CLSCORE:Init(events)
local nicks = {}
for k, e in pairs(events) do
if e.id == EVENT_SPAWN then
scores[e.uid] = ScoreInit()
nicks[e.uid] = e.ni
scores[e.sid] = ScoreInit()
nicks[e.sid] = e.ni
end
end

Expand Down
4 changes: 2 additions & 2 deletions garrysmod/gamemodes/terrortown/gamemode/cl_scoring_events.lua
Expand Up @@ -161,7 +161,7 @@ local function KillText(e)

local txt = nil

if e.att.uid == e.vic.uid then
if e.att.sid == e.vic.sid then
if is_dmg(dmg.t, DMG_BLAST) then

txt = trap and "ev_blowup_trap" or "ev_blowup"
Expand Down Expand Up @@ -235,7 +235,7 @@ end
Event(EVENT_KILL,
{ text = KillText,
icon = function(e)
if e.att.uid == e.vic.uid or e.att.uid == -1 then
if e.att.sid == e.vic.sid or e.att.sid == -1 then
return smile_icon, "Suicide"
end

Expand Down
10 changes: 5 additions & 5 deletions garrysmod/gamemodes/terrortown/gamemode/cl_transfer.lua
Expand Up @@ -18,12 +18,12 @@ function CreateTransferMenu(parent)
dsubmit:SetDisabled(true)
dsubmit:SetText(GetTranslation("xfer_send"))

local selected_uid = nil
local selected_sid = nil

local dpick = vgui.Create("DComboBox", dform)
dpick.OnSelect = function(s, idx, val, data)
if data then
selected_uid = data
selected_sid = data
dsubmit:SetDisabled(false)
end
end
Expand All @@ -34,16 +34,16 @@ function CreateTransferMenu(parent)
local r = LocalPlayer():GetRole()
for _, p in pairs(player.GetAll()) do
if IsValid(p) and p:IsActiveRole(r) and p != LocalPlayer() then
dpick:AddChoice(p:Nick(), p:UniqueID())
dpick:AddChoice(p:Nick(), p:SteamID())
end
end

-- select first player by default
if dpick:GetOptionText(1) then dpick:ChooseOptionID(1) end

dsubmit.DoClick = function(s)
if selected_uid then
RunConsoleCommand("ttt_transfer_credits", tostring(selected_uid) or "-1", "1")
if selected_sid then
RunConsoleCommand("ttt_transfer_credits", selected_sid, "1")
end
end

Expand Down
18 changes: 10 additions & 8 deletions garrysmod/gamemodes/terrortown/gamemode/corpse.lua
Expand Up @@ -69,7 +69,7 @@ local function IdentifyBody(ply, rag)
-- Register find
if not CORPSE.GetFound(rag, false) then
-- will return either false or a valid ply
local deadply = player.GetByUniqueID(rag.uqid)
local deadply = player.GetBySteamID(rag.sid)
if deadply then
deadply:SetNWBool("body_found", true)

Expand All @@ -88,9 +88,9 @@ local function IdentifyBody(ply, rag)
end

-- Handle kill list
for k, vicid in pairs(rag.kills) do
for k, vicsid in pairs(rag.kills) do
-- filter out disconnected
local vic = player.GetByUniqueID(vicid)
local vic = player.GetBySteamID(vicsid)

-- is this an unconfirmed dead?
if IsValid(vic) and (not vic:GetNWBool("body_found", false)) then
Expand Down Expand Up @@ -190,7 +190,7 @@ function CORPSE.ShowSearch(ply, rag, covert, long_range)
local hshot = rag.was_headshot or false
local dtime = rag.time or 0

local owner = player.GetByUniqueID(rag.uqid)
local owner = player.GetBySteamID(rag.sid)
owner = IsValid(owner) and owner:EntIndex() or -1

-- basic sanity check
Expand Down Expand Up @@ -227,9 +227,9 @@ function CORPSE.ShowSearch(ply, rag, covert, long_range)

-- build list of people this traitor killed
local kill_entids = {}
for k, vicid in pairs(rag.kills) do
for k, vicsid in pairs(rag.kills) do
-- also send disconnected players as a marker
local vic = player.GetByUniqueID(vicid)
local vic = player.GetBySteamID(vicsid)
table.insert(kill_entids, IsValid(vic) and vic:EntIndex() or -1)
end

Expand Down Expand Up @@ -300,7 +300,7 @@ local function GetKillerSample(victim, attacker, dmg)

local sample = {}
sample.killer = attacker
sample.killer_uid = attacker:UniqueID()
sample.killer_sid = attacker:SteamID()
sample.victim = victim
sample.t = CurTime() + (-1 * (0.019 * dist)^2 + GetConVarNumber("ttt_killer_dna_basetime"))

Expand Down Expand Up @@ -380,7 +380,9 @@ function CORPSE.Create(ply, attacker, dmginfo)

-- flag this ragdoll as being a player's
rag.player_ragdoll = true
rag.uqid = ply:UniqueID()
rag.sid = ply:SteamID()

rag.uqid = ply:UniqueID() -- backwards compatibility; use rag.sid instead

-- network data
CORPSE.SetPlayerNick(rag, ply)
Expand Down