Author Topic: TTT In-Game Damage Log Window  (Read 2521 times)

0 Members and 3 Guests are viewing this topic.

Offline Reisama

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
TTT In-Game Damage Log Window
« on: March 12, 2015, 01:10:34 PM »
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:
Code: [Select]
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.

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: TTT In-Game Damage Log Window
« Reply #1 on: March 12, 2015, 01:16:07 PM »
Well, from what it looks like, GAMEMODE.DamageLog does not exist, as evident by the fact you're unable to make references to it without errors.

Quote
[Error] lua/ulx/modules/sh/extra_commands.lua:40: attempt to get length of field 'DamageLog' (a nil value)
Quote
'DamageLog' (a nil value)
GAMEMODE.DamageLog = nil
It doesn't exist.
It's undefined.
bw81@ulysses-forums ~ % whoami
Homepage

Offline Reisama

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Re: TTT In-Game Damage Log Window
« Reply #2 on: March 12, 2015, 01:32:46 PM »
I noticed that - i guess i forgot to clarify in my problem that I dont know how to reference the existing table DamageLog (which exists in the TTT gamemode files) in my ulx scripts.

Edit:

To help better see what I am talking about... DamageLog is used in the comand ttt_print_damagelog, which uses a function defined in gamemodes/terrortown/gamemode/admin.lua, around line 110, and from what I can gather, DamageLog is defined as both a function (same file, around line 150), and a table (defined in gamemodes/terrortown/gamemode/init.lua on line 683).
« Last Edit: March 12, 2015, 01:53:54 PM by Reisama »

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: TTT In-Game Damage Log Window
« Reply #3 on: March 12, 2015, 01:53:19 PM »
I don't believe there's an easy way of accessing this table, as it's probably local to TTT only.
You could always use one of the pre-built scripts for this task—Tommy229's Damagelog Menu + RDM Manager is almost exactly what it sounds like you're looking for.
bw81@ulysses-forums ~ % whoami
Homepage

Offline Reisama

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Re: TTT In-Game Damage Log Window
« Reply #4 on: March 12, 2015, 01:56:15 PM »
I found that during my searches, and I tried looking at how he did it, but I cant for the life of me understand how he pulled it off. The main point of making it from scratch on my own is so I can make my own gui for functions, such as slaying players from the same window, or adjusting other things we may add to our server later on.
Edit: I looked at it a little bit more and something caught my eye - He made his own hooks. I'm going to see if I can just write a new script that builds off of that. Wish me luck.
« Last Edit: March 12, 2015, 02:01:07 PM by Reisama »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: TTT In-Game Damage Log Window
« Reply #5 on: March 12, 2015, 09:28:28 PM »
Luck
If you've not already, seek/search around our dev corner. Pretty sure there's been a few discussions that may lend help/ideas regarding damage logs.
Might even be a release in our releases section.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming