• Print

Author Topic: ULX TTT DNA Logs  (Read 4509 times)

0 Members and 1 Guest are viewing this topic.

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
ULX TTT DNA Logs
« on: August 10, 2014, 02:40:09 am »
Could someone test this out on a srcds? I don't have access to one, but would like to see if it is working as it is.

Code: Lua
  1. local dnaloggingtable = {} -- Lists each event as a string.
  2. local allowlog = true
  3.  
  4. function ulx.dnalogs( ply )
  5.         if not ply:IsSuperAdmin and not allowlog then ply:ChatPrint( "You are not able to view logs during the round!" ) return end
  6.  
  7.         ply:SendLua( "
  8.         for k,v in pairs( " .. dnaloggingtable .. " ) do
  9.                 print( v .. '\n' )
  10.         end" )
  11.  
  12.         ply:ChatPrint( "DNA Logs printed to console." )
  13. end
  14. local dnalogs = ulx.command( "Utility", "ulx dnalogs", ulx.dnalogs, "!dnalogs", true )
  15. dnalogs:defaultAccess( ULib.ACCESS_ALL )
  16. dnalogs:help( "Prints DNA logs to console." )
  17.  
  18. concommand.Add( "ttt_print_dnalog", ulx.dnalogs( ply ) ) -- Also available for old-school ttt administrators. <3
  19.  
  20. hook.Add( "TTTFoundDNA", "TTTDNALogging_Log", function() -- Logging happens here.
  21.         if ent:IsPlayer() then
  22.                 dnaloggingtable[#dnaloggingtable + 1] = ply:Nick() .. " found the dna of " .. dna_owner:Nick() .. " on the body of " .. ent:Nick()
  23.         elseif ent:IsWeapon() then
  24.                 dnaloggingtable[#dnaloggingtable + 1] = ply:Nick() .. " found the dna of " .. dna_owner:Nick() .. " on their " .. ent:GetPrintName()
  25.         else
  26.                 dnaloggingtable[#dnaloggingtable + 1] = ply:Nick() .. " found the dna of " .. dna_owner:Nick() .. " on a special object"
  27.         end
  28. end )
  29.  
  30. -- These two are only there to disable logs during the round for non-superadmins.
  31.  
  32. hook.Add( "TTTBeginRound", "TTTDNALogging_Disable", function()
  33.         table.Empty( dnaloggingtable ) -- Remove last round's DNA logging.
  34.         allowlog = false
  35. end )
  36.  
  37. hook.Add( "TTTEndRound", "TTTDNALogging_Enable", function()
  38.         allowlog = true -- Enable viewing DNA logs for non-superadmins.
  39. end )
Out of the Garry's Mod business.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: ULX TTT DNA Logs
« Reply #1 on: August 10, 2014, 11:03:29 am »
Currently I see one error, the quotes in the SendLua (line 7) need to be escaped or you need to make a string like... [[ply:ChatPrint("hello")]] yes the square brackets are part of it.
I cry every time I see that I am not a respected member of this community.

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: ULX TTT DNA Logs
« Reply #2 on: August 10, 2014, 11:51:37 am »
Currently I see one error, the quotes in the SendLua (line 7) need to be escaped or you need to make a string like... [[ply:ChatPrint("hello")]] yes the square brackets are part of it.

Would the string be like [[for k,v ...

Or would it go elsewhere? I've never had to use those.

Edit: How is this?
Code: Lua
  1. ply:SendLua( [[for k,v in pairs( dnaloggingtable ) do print( v .. "\n" ) end]] )
« Last Edit: August 11, 2014, 12:06:18 am by Neku »
Out of the Garry's Mod business.

  • Print