I am trying to create an in-game method of displaying the damage logs in TTT to my admins in a window in-game.
What I ultimately want to be able to do is have my admins be able to use a command, such as !dmglog, that will open this window up, and print out the damage log as it would be in the console if they used ttt_print_damagelog.
I have the command listed in the xgui, and the !dmglog command words, but the actual function is throwing errors, and after hours of searching, i'm about to throw the server at the wall.
The specific error is
[Error] lua/ulx/modules/sh/extra_commands.lua:40: attempt to get length of field 'DamageLog' (a nil value)
The file:
local CATEGORY_NAME = "Scapegoat Commands"
function ulx.tttdamagelog( calling_ply )
--if( calling_ply:IsUserGroup("Enforcer Level 1") ) then
ULib.clientRPC( calling_ply, "ulx.showDmgLog", calling_ply:SteamID(), calling_ply )
end
function ulx.showDmgLog( steamid, ply )
if not GetConVarString("gamemode") == "terrortown" then ULib.tsayError( calling_ply, "Incorrect Game Mode", true ) else
local window = vgui.Create( "DFrame" )
if ScrW() > 640 then -- Make it larger if we can.
window:SetSize( ScrW()*0.9, ScrH()*0.9 )
else
window:SetSize( 640, 480 )
end
window:Center()
window:SetTitle( "TTT Damage Log" )
window:SetVisible( true )
window:MakePopup()
local html = vgui.Create( "HTML", window )
local button = vgui.Create( "DButton", window )
button:SetText( "Close" )
button.DoClick = function() window:Close() end
button:SetSize( 100, 40 )
button:SetPos( (window:GetWide() - button:GetWide()) / 2, window:GetTall() - button:GetTall() - 10 )
html:SetSize( window:GetWide() - 20, window:GetTall() - button:GetTall() - 50 )
html:SetPos( 10, 30 )
local logresult = "Damage Log\n"
if #GAMEMODE.DamageLog == 0 then ----<-- Line 40
text = "Damage log is empty."
else
for _, txt in ipairs(GAMEMODE.DamageLog) do ----<-- also errors if I removed the length check
logresult=logresult .. txt .."\n"
end
html:SetHTML( logresult )
end
end
end
local scapegoat_damagelog = ulx.command(CATEGORY_NAME,"ulx tttdamagelog",ulx.tttdamagelog,"!dmglog",true,false)
scapegoat_damagelog:defaultAccess( ULib.ACCESS_ADMIN )
Any help on this would be great.
Just to clarify, there are more reasons for me to create this than I am explaining right now. I know I could just grant access to ttt_print_damagelog, but I eventually want to create functions on a gui that would use similar code to this.