Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0534a4c
Added ROLE events
BDJslime-UnaverageJoe Apr 12, 2024
01920fb
Added role change support
BDJslime-UnaverageJoe Apr 12, 2024
fa0c2f4
misc
BDJslime-UnaverageJoe Apr 12, 2024
9bf26de
Cache log line color
BDJslime-UnaverageJoe Apr 12, 2024
bf35935
misc changes
BDJslime-UnaverageJoe Apr 12, 2024
26e61ec
Update roles for death recent logs
BDJslime-UnaverageJoe Apr 13, 2024
9168279
Added round check
BDJslime-UnaverageJoe Apr 13, 2024
acdce5a
Handle instant respawns
BDJslime-UnaverageJoe Apr 18, 2024
cbebd64
Delayed respawn check
BDJslime-UnaverageJoe Apr 18, 2024
dac675c
move message to client
BDJslime-UnaverageJoe Apr 18, 2024
c24d003
Merge pull request #1 from BDJslime-UnaverageJoe/RoleRespawn
BDJslime-UnaverageJoe Apr 18, 2024
1d818e2
Merge branch 'BadgerCode:master' into RoleEventCR
BDJslime-UnaverageJoe Jan 22, 2025
4e27efc
Revert "Role respawn"
BDJslime-UnaverageJoe Jan 22, 2025
563e2ed
Merge pull request #2 from BDJslime-UnaverageJoe/revert-1-RoleRespawn
BDJslime-UnaverageJoe Jan 22, 2025
de0e801
Config additions
BDJslime-UnaverageJoe Jan 23, 2025
d6a944e
Prompt to respond to reports + console command to respond
BDJslime-UnaverageJoe Jan 23, 2025
fa274a0
Merge pull request #3 from BDJslime-UnaverageJoe/answerPrompt
BDJslime-UnaverageJoe Jan 23, 2025
b3dd409
Change spawn check to generic hook
BDJslime-UnaverageJoe Jan 23, 2025
f7fc67d
Prevent autorespond when reported while dead
BDJslime-UnaverageJoe Jan 24, 2025
5f20956
cleanup
BDJslime-UnaverageJoe Jul 27, 2025
384a933
Save mid responces and prevent closing when respawning outside of act…
BDJslime-UnaverageJoe Jul 28, 2025
8d4a9c2
fix closing prompts
BDJslime-UnaverageJoe Jul 28, 2025
5b3a3db
Replace prompt with simple chat message
BDJslime-UnaverageJoe Apr 19, 2026
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
20 changes: 17 additions & 3 deletions lua/damagelogs/client/listview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,15 @@ function Damagelog:AddLogsLine(listview, tbl, roles, nofilters, old)
end
end

local color = infos:GetColor(tbl.infos, roles)

function item:PaintOver(w, h)
if not self:IsSelected() and infos:Highlight(item, tbl.infos, text) then
surface.SetDrawColor(color_what)
surface.DrawRect(0, 0, w, h)
else
for _, v in pairs(item.Columns) do
v:SetTextColor(infos:GetColor(tbl.infos, roles))
v:SetTextColor(color)
end
end
end
Expand All @@ -170,13 +172,18 @@ function Damagelog:SetListViewTable(listview, tbl, nofilters, old)

if #tbl.logs > 0 then
local added = false

local roles = tbl.roles
for _, v in ipairs(tbl.logs) do
local line_added = self:AddLogsLine(listview, v, tbl.roles, nofilters, old)
local line_added = self:AddLogsLine(listview, v, roles, nofilters, old)

if not added and line_added then
added = true
end

if (CR_VERSION or TTT2) and Damagelog:CheckRoleUpdates(v) then
local infos = v["infos"]
roles[infos[2]]["role"] = infos[4]
end
end

if not added then
Expand All @@ -187,6 +194,13 @@ function Damagelog:SetListViewTable(listview, tbl, nofilters, old)
end
end

function Damagelog:CheckRoleUpdates(tbl)
if self.events[tbl.id]["Type"] == "ROLE" and tbl.infos[1] == 1 then
return true
end
return false
end

function Damagelog:SetRolesListView(listview, tbl)
listview:Clear()

Expand Down
44 changes: 31 additions & 13 deletions lua/damagelogs/client/rdm_manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ Damagelog.ReportsQueue = Damagelog.ReportsQueue or {}

local renderedReports = {}

local function ActiveReports()
local found = 0
for _, v in pairs(Damagelog.ReportsQueue) do
if not v.finished then
found = found + 1
end
end
return found
end

local function MarkReportAsRendered(report)
renderedReports[string.format("%s:%s", tostring(report.index), tostring(report.previous or "nil"))] = true
end
Expand All @@ -42,18 +52,8 @@ local function BuildReportFrame(report)

ReportFrame:AddReport(report)
else
local found = false

for _, v in pairs(Damagelog.ReportsQueue) do
if not v.finished then
found = true
break
end
end

if not found then
return
end
if ActiveReports() == 0 then return end

RunConsoleCommand("-voicerecord")

Expand Down Expand Up @@ -102,7 +102,15 @@ local function BuildReportFrame(report)
local TextEntry = vgui.Create("DTextEntry")
TextEntry:SetMultiline(true)
TextEntry:SetHeight(150)
if report.savedresponse then TextEntry:SetText(report.savedresponse) end
PanelList:AddItem(TextEntry)

TextEntry.OnLoseFocus = function()
if not report.finished then
report.savedresponse = string.Trim(TextEntry:GetValue())
end
end

local Button = vgui.Create("DButton")
Button:SetText(TTTLogTranslate(GetDMGLogLang, "Send"))

Expand Down Expand Up @@ -853,8 +861,18 @@ net.Receive("DL_SendReport", function()
end)

net.Receive("DL_Death", function()
if not IsValid(ReportFrame) then
BuildReportFrame()
local forced = net.ReadBool()
if not forced and ActiveReports() > 0 then
chat.AddText(Color(255, 62, 62), net.ReadString(), color_white, " " .. string.format(TTTLogTranslate(GetDMGLogLang, "delayed_text"), ActiveReports(), Damagelog.Respond_Command) )
return
end
BuildReportFrame()
end)

net.Receive("DL_Respawn", function()
if IsValid(ReportFrame) then
ReportFrame:Close()
ReportFrame:Remove()
end
end)

Expand Down
3 changes: 3 additions & 0 deletions lua/damagelogs/config/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ Damagelog.RDM_Manager_Enabled = true
Damagelog.RDM_Manager_Command = "!report"
-- Command to open the respond menu while you're alive
Damagelog.Respond_Command = "!respond"
-- True to always respond to reports after death, false to only notify player for round
-- Recommend to disable if server is utilizing revivable gameplay elements
Damagelog.AutoRespond = true
--[[Set to true if you want to enable MySQL (it needs to be configured on config/mysqloo.lua)
Setting it to false will make the logs use SQLite (garrysmod/sv.db)
]]
Expand Down
3 changes: 2 additions & 1 deletion lua/damagelogs/config/config_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function Damagelog:getConfig()
config.Commands = {}
config.Commands.RDM_Manager_Command = Damagelog.RDM_Manager_Command
config.Commands.Respond_Command = Damagelog.Respond_Command

config.AutoRespond = Damagelog.AutoRespond
config.Use_MySQL = Damagelog.Use_MySQL
--Autoslay stuff
config.Autoslay = {}
Expand Down Expand Up @@ -126,6 +126,7 @@ function Damagelog:loadConfigFromTable(loaded_config)
Damagelog.RDM_Manager_Enabled = config.RDM_Manager_Enabled
Damagelog.RDM_Manager_Command = config.Commands.RDM_Manager_Command
Damagelog.Respond_Command = config.Commands.Respond_Command
Damagelog.AutoRespond = config.AutoRespond
Damagelog.Use_MySQL = Damagelog.Use_MySQL

Damagelog.ShowRemainingSlays = config.Autoslay.ShowRemainingSlays
Expand Down
19 changes: 16 additions & 3 deletions lua/damagelogs/server/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Damagelog.OldTables = Damagelog.OldTables or {}
Damagelog.ShootTables = Damagelog.ShootTables or {}
Damagelog.Roles = Damagelog.Roles or {}
Damagelog.SceneRounds = Damagelog.SceneRounds or {}
local RecentRoles = {}

net.Receive("DL_SendLang", function(_, ply)
ply.DMGLogLang = net.ReadString()
Expand All @@ -101,13 +102,16 @@ function Player:SetDamagelogID(id)
end

function Player:AddToDamagelogRoles(joinedAfterRoundStart)
local id = table.insert(Damagelog.Roles[#Damagelog.Roles], {
local info = {
role = (joinedAfterRoundStart and DAMAGELOG_ROLE_JOINAFTERROUNDSTART)
or (self:IsSpec() and DAMAGELOG_ROLE_SPECTATOR)
or self:GetRole(),
steamid64 = self:SteamID64(),
nick = self:Nick()
})
}

local id = table.insert(Damagelog.Roles[#Damagelog.Roles], info)
if joinedAfterRoundStart then table.insert(RecentRoles[#Damagelog.Roles], id, info) end

self:SetDamagelogID(id)
end
Expand Down Expand Up @@ -152,6 +156,7 @@ function Damagelog:TTTBeginRound()
end

self.CurrentRound = rounds + 1
RecentRoles = self.Roles[rounds + 1]
end

table.Empty(self.DamageTable)
Expand Down Expand Up @@ -360,8 +365,16 @@ hook.Add("PlayerDeath", "Damagelog_PlayerDeathLastLogs", function(ply)

ply.DeathDmgLog = {
logs = table.Reverse(found_dmg),
roles = Damagelog.Roles[#Damagelog.Roles]
roles = RecentRoles
}
end)

function Damagelog:UpdateRecentRole(ply, role)
if GetRoundState() ~= ROUND_ACTIVE then return end
local round = self.CurrentRound

timer.Simple(10, function()
if round ~= self.CurrentRound then return end
RecentRoles[ply:GetDamagelogID()]["role"] = role
end)
end
18 changes: 18 additions & 0 deletions lua/damagelogs/server/rdm_manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ util.AddNetworkString("DL_SendReport")
util.AddNetworkString("DL_SendAnswer")
util.AddNetworkString("DL_SendForgive")
util.AddNetworkString("DL_GetForgive")
util.AddNetworkString("DL_Respawn")
util.AddNetworkString("DL_Death")
util.AddNetworkString("DL_Answering")
util.AddNetworkString("DL_Answering_global")
Expand Down Expand Up @@ -153,6 +154,7 @@ hook_Add("PlayerSay", "Damagelog_RDMManager", function(ply, text, teamOnly)
return false
elseif Damagelog.Respond_Command and string_Left(string_lower(text), #Damagelog.Respond_Command) == Damagelog.Respond_Command then
net.Start("DL_Death")
net.WriteBool(true)
net.Send(ply)

return false
Expand Down Expand Up @@ -436,6 +438,7 @@ function HandlePlayerReport(ply, attacker, message, reportType)

if reportType == DAMAGELOG_REPORT_FORCE and attacker:IsActive() then
net.Start("DL_Death")
net.WriteBool(true)
net.Send(attacker)
end

Expand Down Expand Up @@ -680,14 +683,28 @@ end)

hook_Add("PlayerDeath", "RDM_Manager", function(ply)
net.Start("DL_Death")
net.WriteBool(Damagelog.AutoRespond)
net.Send(ply)
end)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could simplify this function to always wait 5 seconds before requesting that the dead player replies to their reports.


hook_Add("PlayerSpawn", "RDM_Manager", function(ply)
if GetRoundState() != ROUND_ACTIVE then return end
net.Start("DL_Respawn")
net.Send(ply)
end)

hook_Add("TTTEndRound", "RDM_Manager", function()
net.Start("DL_Death")
net.WriteBool(true)
net.Broadcast()
end)

concommand.Add("dmglogs_answerreport", function(ply, cmd, args)
net.Start("DL_Death")
net.WriteBool(true)
net.Send(ply)
end)

function HandleReportedPlayerAnswer(ply, previous, text, index)
local tbl = previous and Damagelog.Reports.Previous[index] or Damagelog.Reports.Current[index]

Expand Down Expand Up @@ -866,6 +883,7 @@ net.Receive("DL_ForceRespond", function(_len, ply)

if IsValid(attacker) then
net.Start("DL_Death")
net.WriteBool(true)
net.Send(attacker)
end
end
Expand Down
84 changes: 84 additions & 0 deletions lua/damagelogs/shared/events/roles.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
if SERVER then
--Global Variables Unavailable? find how to hook later
--if CR_VERSION then
Damagelog:EventHook("TTTPlayerRoleChanged")
Damagelog:EventHook("TTTPlayerRoleChangedByItem")
--elseif TTT2 then
--TODO
--else
--UNUSED
--end
Damagelog:EventHook("PlayerSpawn")
else
Damagelog:AddFilter("filter_show_roles", DAMAGELOG_FILTER_BOOL, true)
Damagelog:AddColor("color_roles", Color(128, 64, 0))
end
local event = {}
event.Type = "ROLE"

function event:TTTPlayerRoleChanged(ply, oldRole, newRole)
if oldRole == nil or oldRole == ROLE_NONE or oldRole == newRole or newRole == ROLE_NONE then return end
self.CallEvent({
[1] = 1,
[2] = ply:GetDamagelogID(),
[3] = oldRole,
[4] = newRole
})
Damagelog:UpdateRecentRole(ply, newRole)
end

function event:TTTPlayerRoleChangedByItem(ply, tgt, item)
if not IsValid(item) then return end
self.CallEvent({
[1] = 2,
[2] = ply:GetDamagelogID(),
[3] = tgt:GetDamagelogID(),
[4] = IsEntity(item) and item:GetClass() or item
})
end

function event:PlayerSpawn(ply)
self.CallEvent({
[1] = 3,
[2] = ply:GetDamagelogID(),
})
end


function event:ToString(v, roles)
local ply = Damagelog:InfoFromID(roles, v[2])

if v[1] == 1 then
return string.format(TTTLogTranslate(GetDMGLogLang, "role_change"), ply.nick, Damagelog:StrRole(v[3]), Damagelog:StrRole(v[4]))
elseif v[1] == 2 then
local tgt = Damagelog:InfoFromID(roles, v[3])
return string.format(TTTLogTranslate(GetDMGLogLang, "role_item"), ply.nick, Damagelog:StrRole(ply.role), Damagelog:GetWeaponName(v[4]), tgt.nick, Damagelog:StrRole(tgt.role))
elseif v[1] == 3 then
return string.format(TTTLogTranslate(GetDMGLogLang, "revive"), ply.nick, Damagelog:StrRole(ply.role))
end
end

function event:IsAllowed(tbl)
return Damagelog.filter_settings["filter_show_roles"]
end

function event:Highlight(line, tbl, text)
return table.HasValue(Damagelog.Highlighted, tbl[1])
end

function event:GetColor(tbl)
return Damagelog:GetColor("color_roles")
end

function event:RightClick(line, tbl, roles, text)
line:ShowTooLong(true)
local ply = Damagelog:InfoFromID(roles, tbl[2])
if tbl[1] == 2 then
local tgt = Damagelog:InfoFromID(roles, tbl[3])
line:ShowCopy(true, {ply.nick, util.SteamIDFrom64(ply.steamid64)}, {tgt.nick, util.SteamIDFrom64(tgt.steamid64)})
return
end
line:ShowCopy(true, {ply.nick, util.SteamIDFrom64(ply.steamid64)})
end

Damagelog:AddEvent(event)
9 changes: 8 additions & 1 deletion lua/damagelogs/shared/lang/english.lua
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ DamagelogLang.english = {
filter_show_equipment_usage = "Show equipment usage (if supported)",
filter_show_c4 = "Show C4",
filter_show_drownings = "Show drownings",
filter_show_roles = "Show role changes",
-- Colors
color_found_bodies = "Found bodies",
colors_aslays = "Auto Slays",
Expand Down Expand Up @@ -408,5 +409,11 @@ DamagelogLang.english = {
rdmmanager_action_ban = "Ban",
rdmmanager_action_ban_title = "Banning",
rdmmanager_action_ban_submit = "Ban",
dmglogs_btn_highlight = "Highlight"
dmglogs_btn_highlight = "Highlight",

role_change = "%s [%s] has changed into [%s]",
role_item = "%s [%s] used %s on %s [%s]",
revive = "%s [%s] has been revived",

delayed_text = [[You have %s unanswered reports, You may respond to them now using %s or be forced to at the end of the current round.]],
}