Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 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
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
111 changes: 98 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 @@ -33,6 +43,60 @@ end

local ReportFrame

local PromptFrame

local Prompted = -1

local function BuildPromptFrame()
if Prompted == 1 then return end
if ActiveReports() == 0 then return end
if IsValid(PromptFrame) then
PromptFrame:UpdateCount()
return
end

local w, h = 300, 180

PromptFrame = vgui.Create("DFrame")
PromptFrame:SetSize(w, h)
PromptFrame:Center()
PromptFrame:SetTitle("")
PromptFrame:SetVisible(true)
PromptFrame:SetMouseInputEnabled(true)

local inner = vgui.Create("DPanel", PromptFrame)
inner:StretchToParent(5, 25, 5, 45)

local text = vgui.Create("DLabel", inner)
text:SetWrap(true)
text:SetText(string.format(TTTLogTranslate(GetDMGLogLang, "prompt_text"), ActiveReports()))
text:SetDark(true)
text:StretchToParent(10, 5, 10, 5)

local bw, bh = 75, 25
local cancel = vgui.Create("DButton", PromptFrame)
cancel:SetPos(5, h - 40)
cancel:SetSize(125, bh)
cancel:SetText(TTTLogTranslate(GetDMGLogLang, "prompt_answer"))
cancel.DoClick = function()
RunConsoleCommand("dmglogs_answerreport")
PromptFrame:Close()
end

local disable = vgui.Create("DButton", PromptFrame)
disable:SetPos(w - 130, h - 40)
disable:SetSize(125, bh)
disable:SetText(TTTLogTranslate(GetDMGLogLang, "prompt_ignore"))
disable.DoClick = function()
Prompted = 1
PromptFrame:Close()
end

PromptFrame.UpdateCount = function(PromptFrame)
text:SetText(string.format(TTTLogTranslate(GetDMGLogLang, "prompt_text"), ActiveReports()))
end
end

local function BuildReportFrame(report)
if IsValid(ReportFrame) and report then
if HasReportBeenRendered(report) then
Expand All @@ -42,18 +106,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 +156,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 @@ -847,14 +909,37 @@ net.Receive("DL_SendReport", function()
local client = LocalPlayer()

if not client.IsActive or not client:IsActive() then
if Prompted ~= -1 then
BuildPromptFrame()
return
end
BuildReportFrame(report)
end
end
end)

net.Receive("DL_Death", function()
if not IsValid(ReportFrame) then
BuildReportFrame()
local forced = net.ReadBool()
if not forced then
if Prompted == -1 then Prompted = 0 end
BuildPromptFrame()
return
end
if IsValid(PromptFrame) then
PromptFrame:Close()
PromptFrame:Remove()
end
BuildReportFrame()
end)

net.Receive("DL_Respawn", function()
if IsValid(PromptFrame) then
PromptFrame:Close()
PromptFrame:Remove()
end
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 prompt 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
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
Loading