• Print

Author Topic: Target ConCommand on Steam ID  (Read 5077 times)

0 Members and 1 Guest are viewing this topic.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Target ConCommand on Steam ID
« on: August 01, 2013, 11:57:13 am »
Hello again. I'm probably getting quite annoying, but I really want some support on this "issue". And since I've always been met with friendly answers by the people here on Ulysses Forums, I will continue to ask for support here.

I have this function to print a so-called "damagelog" on the gamemode Trouble in Terrorist Town, this function prints it to a client's console if their requirements are met. As of right now, I've managed to make it work for people that have IsAdmin or IsSuperAdmin true (I might not have needed that "IsSuperAdmin" part, but I wasn't sure). Although, I also want to make other users able to get the damagelog printed to their console, even though they're not admins. Preferably by their Steam ID. I have attempted with this:

Code: Lua
  1. local Users = {
  2.         ["STEAM_0:1:12345678"], --Test Steam ID
  3. }
  4.  
  5. function StaffDamagelog (ply)
  6. local user = Users[ply:SteamID()]
  7.         for k, v in ipairs (player.GetAll()) do
  8.                 if v:IsAdmin() then
  9.                         v:ConCommand ("ttt_print_damagelog")
  10.                 elseif v:IsSuperAdmin() then
  11.                         v:ConCommand ("ttt_print_damagelog")
  12.                 elseif user then
  13.                         v:ConCommand ("ttt_print_damagelog")
  14.                 end
  15.         end
  16. end
  17.  

It just kept printing out the error, expecting '=' near the ','. I understood what this meant, although, what would I add after the '='.

My current function that works totally fine for admins and superadmins is just this:

Code: Lua
  1. function StaffDamagelog (ply)
  2.         for k, v in ipairs (player.GetAll()) do
  3.                 if v:IsAdmin() then
  4.                         v:ConCommand ("ttt_print_damagelog")
  5.                 elseif v:IsSuperAdmin() then
  6.                         v:ConCommand ("ttt_print_damagelog")
  7.                 end
  8.         end
  9. end
  10.  

Any help with this is appreciated. I don't mind getting told that checking for IsSuperAdmin is stupid when I already have it for IsAdmin. :P

Thanks in advance!
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Target ConCommand on Steam ID
« Reply #1 on: August 01, 2013, 05:52:59 pm »
The way you have it set up, I think you want to change it to be the following:

Code: Lua
  1. local Users = {
  2. ["STEAM_0:1:12345678"] = true,
  3. }
Experiencing God's grace one day at a time.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Target ConCommand on Steam ID
« Reply #2 on: August 01, 2013, 06:09:30 pm »
I didn't say it had to be like that, but that might still work with it. Thanks for the suggestion, I'll test it and post again later after testing.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Target ConCommand on Steam ID
« Reply #3 on: August 02, 2013, 09:18:52 am »
I attempted this, Megiddo, and it outputted the error "attempt to index local 'ply' (a number value), more specifically on the line 12 (here it would be 6). I tried a lot of workarounds that I thought would work with no luck, the same error. I forgot exactly what I tried (I usually work on stuff like this around 3 AM, this was not an exception). Any ideas on what I can try?

Code: Lua
  1. local Users = {
  2.         ["STEAM_0:1:40394628"] = true, --Lab rat
  3. }
  4.  
  5. function StaffDamagelog(ply)
  6. local user = Users[ply:SteamID()]
  7.         for k,v in pairs (player.GetAll()) do
  8.                 if v:IsAdmin() then
  9.                         v:ConCommand("ttt_print_damagelog")
  10.                 elseif v:IsSuperAdmin() then
  11.                         v:ConCommand("ttt_print_damagelog")
  12.                 elseif user then
  13.                         v:ConCommand("ttt_print_damagelog")
  14.                 end
  15.         end
  16. end
  17. hook.Add("TTTEndRound", "StaffDamagelog", StaffDamagelog)
  18.  

Thanks again for the idea, Megiddo, unfortunately it didn't work.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Target ConCommand on Steam ID
« Reply #4 on: August 02, 2013, 10:40:00 am »
It's saying that the "ply" object is a number, not a player object as you're expecting it to be. You should review the documentation for that hook.
Experiencing God's grace one day at a time.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Target ConCommand on Steam ID
« Reply #5 on: August 02, 2013, 11:49:04 am »
Thanks Megiddo, that makes sense. I should've looked that up first.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Target ConCommand on Steam ID
« Reply #6 on: August 02, 2013, 12:05:18 pm »
I fixed it, and it works perfectly. It's really messy though, but I didn't know any other way of doing it (if you actually can make this more compact, then please tell me).

Thanks for all the help, Megiddo. It's appreciated!

Code: Lua
  1. local Users = {
  2.         ["STEAM_0:1:18726919"] = true, --Example.
  3. }
  4.  
  5. function StaffDamagelog(res)
  6.         if WIN_TRAITOR then
  7.                 for k,v in ipairs (player.GetAll()) do
  8.                 local user = Users[v:SteamID()]
  9.                         if user then
  10.                                 v:ConCommand("ttt_print_damagelog")
  11.                         elseif v:IsAdmin() then
  12.                                 v:ConCommand("ttt_print_damagelog")
  13.                         elseif v:IsSuperAdmin() then
  14.                                 v:ConCommand("ttt_print_damagelog")
  15.                         end
  16.                 end
  17.         elseif WIN_INNOCENT then
  18.                 for k,v in ipairs (player.GetAll()) do
  19.                 local user = Users[v:SteamID()]
  20.                         if user then
  21.                                 v:ConCommand("ttt_print_damagelog")
  22.                         elseif v:IsAdmin() then
  23.                                 v:ConCommand("ttt_print_damagelog")
  24.                         elseif v:IsSuperAdmin() then
  25.                                 v:ConCommand("ttt_print_damagelog")
  26.                         end
  27.                 end
  28.         elseif WIN_TIMELIMIT then
  29.                 for k,v in ipairs (player.GetAll()) do
  30.                 local user = Users[v:SteamID()]
  31.                         if user then
  32.                                 v:ConCommand("ttt_print_damagelog")
  33.                         elseif v:IsAdmin() then
  34.                                 v:ConCommand("ttt_print_damagelog")
  35.                         elseif v:IsSuperAdmin() then
  36.                                 v:ConCommand("ttt_print_damagelog")
  37.                         end
  38.                 end
  39.         end
  40. end
  41. hook.Add("TTTEndRound", "StaffDamagelog", StaffDamagelog)
  42.  
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Target ConCommand on Steam ID
« Reply #7 on: August 02, 2013, 12:29:17 pm »
why not just try...



Code: [Select]
if WIN_TRAITOR or WIN_INNOCENT or WIN_TIMELIMIT then
for k,v in ipairs (player.GetAll()) do
local user = Users[v:SteamID()]
if user then
v:ConCommand("ttt_print_damagelog")
elseif v:IsAdmin() then
v:ConCommand("ttt_print_damagelog")
elseif v:IsSuperAdmin() then
v:ConCommand("ttt_print_damagelog")
end
end
end

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Target ConCommand on Steam ID
« Reply #8 on: August 02, 2013, 12:39:40 pm »
I am quite embarrassed right now. That is a much better way of doing it. I haven't used "or" before, but I should've started using it.

Thanks, MrP.
« Last Edit: August 02, 2013, 12:42:16 pm by Decicus »
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

  • Print