Auto ttt_print_damagelog at the end/start of each round...

I am fairly new to Lua and am having some trouble with getting the ttt damage log command to execute at either the start or the end of each round. I was hoping for it to be a client script without needing access to the server files or anything like that.
The first thing I tried was:


hook.Add("TTTEndRound", "DamageLog", PrintDamageLog)
local function PrintDamageLog(wintype)
   if wintype == WIN_INNOCENT then
      RunConsoleCommand("ttt_print_damagelog")

   elseif wintype == WIN_TRAITOR then
      RunConsoleCommand("ttt_print_damagelog")

   elseif wintype == WIN_TIMELIMIT then
      RunConsoleCommand("ttt_print_damagelog")
   end
end

However, that didn’t seem to work. I pasted that lua script into “garrysmod\garrysmod\lua\autorun” and also “garrysmod\garrysmod\lua\autorun\client” but to no avail.

The second thing I tried was:


hook.Add( "TTTPrepareRound", "Print_Log", function( ply )
       print( ply:Name() .. " THIS IS A TEST!" )
end )

which I copied from the Garry’s Mod wiki, but yet again it didn’t work.

I don’t know if what I’m asking is possible, but what I do want is when the round ends, the command “ttt_print_damagelog” is put into the console and reveals the information without the need for me typing it all out. I have seen one other example of what I want, but I don’t think it suits my needs as the script should be able to work for all ranks of people.
Many thanks, Tom.

Putting this in a file under lua/autorun/client should work just fine
[lua]hook.Add( “TTTEndRound”, “AutoPrintLog”, function()

RunConsoleCommand( “ttt_print_damagelog” )

end )[/lua]

Thanks for the reply, but that didn’t seem to work…
After the round ended, the console only gave me this:



TTT:   The Traitors have won!
Round state: 4
TTT:   Let's look at the round report for 10 seconds.
TTT:   Your Karma is 1035, so you deal full damage this round!
TTT:   A new round begins in 10 seconds. Prepare yourself.
Round state: 2

Any more help would be greatly appreciated!

The reason yours doesn’t work is because you’re defining the hook before the function exists, meaning it points to nil and won’t work.

Always add a hook after the function you’re targeting, or integrate it so it’s one.

What Internet1001 posted should work just fine because it should be a shared function… Are you adding it in the right spot? garrysmod/addons/addon_name/lua/autorun/client/blah.lua

If it isn’t working try in garrysmod/addons/addon_name/lua/autorun/server/blah.lua:
[lua]hook.Add( “TTTEndRound”, “AutoPrintLog”, function()
for k, v in pairs( player.GetAll( ) ) do
v:ConCommand( “ttt_print_damagelog” );
end
end );[/lua]

Although his example should work… You could try adding a timer.Simple( 0, function( ) … end ); to have it execute one frame over, just in case.

Just to be sure, do they need to go in “C:\Games\Steam\SteamApps\gamingtom\garrysmod\garrysmod\addons\AutoDamagelog\lua\autorun\client\AutoDamagelog.lua” or “C:\Games\Steam\SteamApps\common\GarrysMod\garrysmod\addonsAutoDamagelog\lua\autorun\client\AutoDamagelog.lua”?
Thanks!

The path is now in common: steamapps\common\GarrysMod\garrysmod
I remember when they changed this. I got so infuriated trying to figure out what was wrong with my code and all the while it wasn’t even running :suicide:

I thought it only changed if you installed/reinstalled Garry’s Mod after the steam pipe update? Also, I don’t understand what is wrong with using lua/autorun/client instead of addons/Whateveraddonthisis/lua/autorun/client

It doesn’t really matter, it’s just more convenient to just place a file in the already-created lua/autorun folder instead of having to make new folders for the addon.
And yes, that was ages ago, after the steam pipe update.

Why would you reinstall Gmod if you had working lua code?

Okay, I really don’t know what I’m doing wrong here… I create the Lua script with the code:


hook.Add( "TTTEndRound", "AutoPrintLog", function()
     for k, v in pairs( player.GetAll( ) ) do
         v:ConCommand( "ttt_print_damagelog" );
     end
end );

and I place it in “C:\Games\Steam\SteamApps\common\GarrysMod\garrysmod\addons\AutoDamagelog\lua\autorun\client”. I then load up Gmod and join a TTT server and it first gives me the message in console:
“Adding Filesystem Addon ‘c:\games\steam\steamapps\common\garrysmod\garrysmod\addons\autodamagelog’”
However, after the round finishes it doesn’t give me the damage log or anything.
I also tried placing the lua file in “C:\Games\Steam\SteamApps\common\GarrysMod\garrysmod\addons\AutoDamagelog\lua\autorun\server” but that didn’t help :confused:
Any ideas?

That one was supposed to be for server; question. Is allow cs lua on in the server, or is this your server?

If allow cs lua is enabled and it’s not your server; you have to manually run the code. Code doesn’t automatically execute.

If this is your server, put it in the server directory instead of your local install.

I guess that’s the problem then. The server I’m attempting to use it on isn’t mine and must have lua disabled :confused:
Thanks guys for the help.