• Print

Author Topic: a "who" modification  (Read 6019 times)

0 Members and 1 Guest are viewing this topic.

Offline Sloth Armstronk

  • Newbie
  • *
  • Posts: 5
  • Karma: 0
  • Space. Space is.. Scary as
a "who" modification
« on: November 04, 2015, 09:00:01 am »
So I'm trying to make a modification on the who command, but the problem is that I don't know how to make it so it only prints staff ex. "1 Sloth         owner"

Here is the code:
Code: [Select]
function ulx.staff( calling_ply )

local players = player.GetAll()
for _, player in ipairs( players ) do
local id = tostring( player:UserID() )
local nick = player:Nick()
local text = string.format( "%i%s %s%s ", id, string.rep( " ", 2 - id:len() ), nick, string.rep( " ", 31 - nick:len() ) )

text = text .. player:GetUserGroup()

ULib.tsayError( calling_ply, text )
end
end
local staff = ulx.command( CATEGORY_NAME, "ulx staff", ulx.staff, "!staff" )
staff:defaultAccess( ULib.ACCESS_ALL )
staff:help( "See information about currently online staff members." )

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: a "who" modification
« Reply #1 on: November 04, 2015, 11:07:23 am »
You can edit this however you please, but since I am not the best with what you are doing with all the nicks, ids, and stuff. But use this:

Code: Lua
  1. local CATEGORY_NAME = "Insert your category name here"
  2.  
  3. function ulx.staff( calling_ply, ply )
  4.         local ply == ply:GetAll()
  5.         if ply:IsUserGroup( "" ) then -- Insert group name in tab -- Remember this line to the next similar comment
  6.                  ply:GetUserGroup() = group
  7.                 calling_ply:ChatPrint( ply, "#A is #s on the server!", group )
  8.         end -- Remember up to here, and then copy and paste all of this code between per group. So the if ply:IsUserGroup( "" ) then to the end on this line
  9. local staff = ulx.command( CATEGORY_NAME, "ulx staff", ulx.staff, "!staff" )
  10. staff:defaultAccess( ULib.ACCESS_ALL )
  11. staff:help( "Prints the list of staff online and what staff rank they are. !staff" )
  12.  

This code is if you want their user group as well.
Code: Lua
  1. local CATEGORY_NAME = "Insert your category name here"
  2.  
  3. function ulx.staff( calling_ply, ply )
  4.         local ply == ply:GetAll()
  5.         if ply:IsUserGroup( "" ) then -- Insert group name in tab -- Remember this line to the next similar comment
  6.                  ply:GetUserGroup() = group
  7.                  ply:SteamID() = id
  8.                 calling_ply:ChatPrint( ply, "#A is " .. group .. " on the server! Their Steam ID is " .. id )
  9.         end -- Remember up to here, and then copy and paste all of this code between per group. So the if ply:IsUserGroup( "" ) then to the end on this line
  10. local staff = ulx.command( CATEGORY_NAME, "ulx staff", ulx.staff, "!staff" )
  11. staff:defaultAccess( ULib.ACCESS_ALL )
  12. staff:help( "Prints the list of staff online and what staff rank they are. !staff" )
  13.  
This command is for Admins if they want their IP and steam ID.
Code: Lua
  1. local CATEGORY_NAME = "Insert your category name here"
  2.  
  3. function ulx.astaff( calling_ply, ply )
  4.         local ply == ply:GetAll()
  5.         if ply:IsUserGroup( "" ) then -- Insert group name in tab -- Remember this line to the next similar comment
  6.                  ply:GetUserGroup() = group
  7.                  ply:SteamID() = id
  8.                  ply:IpAddress() = ip
  9.                 calling_ply:ChatPrint( ply, "#A is " .. group .. " on the server! Their Steam ID is " .. id .. " and their IP is " .. ip)
  10.         end -- Remember up to here, and then copy and paste all of this code between per group. So the if ply:IsUserGroup( "" ) then to the end on this line
  11. local astaff = ulx.command( CATEGORY_NAME, "ulx astaff", ulx.astaff, "!astaff" )
  12. astaff:defaultAccess( ULib.ACCESS_SUPERADMIN )
  13. astaff:help( "Prints the list of staff online, what staff rank they are, ID, and IP. !astaff" )
  14.  
« Last Edit: November 04, 2015, 04:02:18 pm by WispySkies »

Offline Sloth Armstronk

  • Newbie
  • *
  • Posts: 5
  • Karma: 0
  • Space. Space is.. Scary as
Re: a "who" modification
« Reply #2 on: November 04, 2015, 11:59:06 am »
Well the thing is that I don't want it to people who are non-staff to show up in the list

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: a "who" modification
« Reply #3 on: November 04, 2015, 01:11:42 pm »
I'll add in comments for you then. Also forgot to end the function earlier :p

Code: Lua
  1. --[[
  2. Staff Command - WispySkies
  3. NOTE: Below change the superadmin and admin to the groups you have set to be called, if they aren't correct, nothing will hapen.
  4. ]]--
  5.  
  6. local CATEGORY_NAME = "Yo wassup Dawg"
  7.  
  8. function ulx.staff( calling_ply, ply ) -- Calling_ply, who said the command, ply, just a temporary argument to be declared below when using ply:IsUserGroup
  9.         local ply == ply:GetAll() -- Makes ply EVERYONE
  10.         if ply:IsUserGroup( "superadmin" ) then -- If a ply is a superadmin then
  11.                 ply:GetUserGroup() == group -- Grab their group even if its in the if statement as you need to declare it as "group", used below
  12.                 calling_ply:ChatPrint( ply, "#A is #s on the server!", group ) -- Tell the calling_ply (who ran the command) that they are a superadmin
  13.         end -- Ends the if, self-explanatory
  14.         if ply:IsUserGroup( "admin" ) then -- If a ply is a admin then
  15.                 ply:GetUserGroup() == group -- Grab their group even if its in the if statement as you need to declare it as "group", used below
  16.                 calling_ply:ChatPrint( ply, "#A is #s on the server!", group ) -- Tell the calling_ply (who ran the command) that they are a superadmin
  17.         end -- Ends the if, self-explanatory
  18. end
  19. local staff = ulx.command( CATEGORY_NAME, "ulx staff", ulx.staff, "!staff" ) -- Normal ulx crap below
  20. staff:defaultAccess( ULib.ACCESS_ALL )
  21. staff:help( "Prints the list of staff online and what staff rank they are. !staff" )
  22.  
  23. -- Staff Command - Include Steam ID
  24.  
  25. local CATEGORY_NAME = "Yo wassup Dawg"
  26.  
  27. function ulx.staff( calling_ply, ply )
  28.         local ply == ply:GetAll() -- Makes ply EVERYONE
  29.         if ply:IsUserGroup( "superadmin" ) then -- If a ply is a superadmin then
  30.                 ply:SteamID() == id
  31.                 ply:GetUserGroup() == group -- Grab their group even if its in the if statement as you need to declare it as "group", used below
  32.                 calling_ply:ChatPrint( ply, "#A is " .. group .. " on the server! Their Steam ID is " .. id ) -- Tell the calling_ply (who ran the command) that they are a superadmin with their ID
  33.         end -- Ends the if, self-explanatory
  34.         -- Add more groups here, I gave an example above.
  35. end
  36. local staff = ulx.command( CATEGORY_NAME, "ulx staff", ulx.staff, "!staff" )
  37. staff:defaultAccess( ULib.ACCESS_ALL )
  38. staff:help( "Prints the list of staff online and what staff rank they are. !staff" )
  39.  
  40. -- Admin Staff Command - IP, ID, group
  41. local CATEGORY_NAME = "Yo wassup Dawg"
  42.  
  43. function ulx.astaff( calling_ply, ply )
  44.         local ply == ply:GetAll()
  45.         if ply:IsUserGroup( "superadmin" ) then
  46.                  ply:GetUserGroup() == group
  47.                  ply:SteamID() == id
  48.                  ply:IpAddress() == ip
  49.                 calling_ply:ChatPrint( ply, "#A is " .. group .. " on the server! Their Steam ID is " .. id .. " and their IP is " .. ip)
  50.         end
  51. end -- Look above to add more groups.
  52. local astaff = ulx.command( CATEGORY_NAME, "ulx astaff", ulx.astaff, "!astaff" )
  53. astaff:defaultAccess( ULib.ACCESS_SUPERADMIN )
  54. astaff:help( "Prints the list of staff online, what staff rank they are, ID, and IP. !astaff" )
  55.  
EDIT: Fixed grammar and spelling mistake in code.

EDIT2: Also, just because I don't have an else if they arent superadmin, it wont matter, it justs keeps running if they arent a superadmin. Yes you can save time and add an
Code: Lua
  1. if ply:IsUserGroup( "superadmin" ) then
  2. -- CODE
  3. else
  4. return
  5. end
« Last Edit: November 04, 2015, 01:14:38 pm by WispySkies »

Offline monkeymacman

  • Newbie
  • *
  • Posts: 44
  • Karma: 13
Re: a "who" modification
« Reply #4 on: November 04, 2015, 03:23:15 pm »
Wispy you were doing ply:GetUserGroup() == group when trying to set group to ply:GetUserGroup(). Only one equals, also if that prints to chat then that seems like it could really spam your chat in some situations.

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: a "who" modification
« Reply #5 on: November 04, 2015, 04:01:52 pm »
Fixed that, oops, it prints only to the calling_plys chat, so if he wants to spam himself, ok.

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: a "who" modification
« Reply #6 on: November 04, 2015, 07:33:09 pm »
Your code won't work at all. Lets go through the errors:

Code: Lua
  1. function ulx.staff( calling_ply, ply )

You have an unused argument 'ply'. You seem to think that in order to declare a variable in a function, you need to pass a non-existent variable as an argument. This is not true. You don't need that argument. I'm not sure if lua will error because of this, but it is not needed and it's better safe than sorry.

Code: Lua
  1. local ply == ply:GetAll()

Not an error in itself, but introduces problems down the road. You're treating ply as if it is a player. It is not. It is a table of players. You cannot run the functions 'IsUserGroup' or 'GetUserGroup' on a table, not even a table of players.

Code: Lua
  1. ply:GetUserGroup() == group

Order matters. Here you're trying to set the output of a function to an undeclared variable. You need to switch these two around, and you should add the 'local' keyword before the group variable.



A more efficient way of doing this would be to give staff members a special permission to differentiate their group. Then you can use this code to print a list of them:

Code: Lua
  1. local CATEGORY_NAME = "Utility"
  2.  
  3. ULib.ucl.registerAccess( "is_staff", ULib.ACCESS_ADMIN, "Print this player's name in the list of online staff", "Other" )
  4.  
  5. function ulx.staff( calling_ply )
  6.  
  7.   for k, ply in pairs( player.GetAll() ) do
  8.     if ULib.ucl.query( ply, "is_staff" ) then
  9.       local id = tostring( ply:UserID() )
  10.       local nick = ply:Nick()
  11.       local group = ply:GetUserGroup()
  12.      
  13.       calling_ply:PrintMessage( 3, id .. " " .. nick .. "         " .. group )
  14.     end
  15.   end
  16.  
  17. end
  18. local staff = ulx.command( CATEGORY_NAME, "ulx staff", ulx.staff, "!staff" )
  19. staff:defaultAccess( ULib.ACCESS_ALL )
  20. staff:help( "See information about currently online staff members." )
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: a "who" modification
« Reply #7 on: November 05, 2015, 02:14:36 pm »
Your code won't work at all. Lets go through the errors:

Code: Lua
  1. function ulx.staff( calling_ply, ply )

You have an unused argument 'ply'. You seem to think that in order to declare a variable in a function, you need to pass a non-existent variable as an argument. This is not true. You don't need that argument. I'm not sure if lua will error because of this, but it is not needed and it's better safe than sorry.

Code: Lua
  1. local ply == ply:GetAll()

Not an error in itself, but introduces problems down the road. You're treating ply as if it is a player. It is not. It is a table of players. You cannot run the functions 'IsUserGroup' or 'GetUserGroup' on a table, not even a table of players.

Code: Lua
  1. ply:GetUserGroup() == group

Order matters. Here you're trying to set the output of a function to an undeclared variable. You need to switch these two around, and you should add the 'local' keyword before the group variable.



A more efficient way of doing this would be to give staff members a special permission to differentiate their group. Then you can use this code to print a list of them:

Code: Lua
  1. local CATEGORY_NAME = "Utility"
  2.  
  3. ULib.ucl.registerAccess( "is_staff", ULib.ACCESS_ADMIN, "Print this player's name in the list of online staff", "Other" )
  4.  
  5. function ulx.staff( calling_ply )
  6.  
  7.   for k, ply in pairs( player.GetAll() ) do
  8.     if ULib.ucl.query( ply, "is_staff" ) then
  9.       local id = tostring( ply:UserID() )
  10.       local nick = ply:Nick()
  11.       local group = ply:GetUserGroup()
  12.      
  13.       calling_ply:PrintMessage( 3, id .. " " .. nick .. "         " .. group )
  14.     end
  15.   end
  16.  
  17. end
  18. local staff = ulx.command( CATEGORY_NAME, "ulx staff", ulx.staff, "!staff" )
  19. staff:defaultAccess( ULib.ACCESS_ALL )
  20. staff:help( "See information about currently online staff members." )

Always got to love you for shooting down my attempts :D
Still learning lua .-.

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: a "who" modification
« Reply #8 on: November 05, 2015, 03:02:06 pm »
Always got to love you for shooting down my attempts :D
Still learning lua .-.

I'm not sure if you intend to be passive aggressive, but I'm not trying to "shoot down your attempts". I'm just trying to help you. You'll never get better if you don't realize your mistakes.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: a "who" modification
« Reply #9 on: November 05, 2015, 03:59:27 pm »
I'm not sure if you intend to be passive aggressive, but I'm not trying to "shoot down your attempts". I'm just trying to help you. You'll never get better if you don't realize your mistakes.
I know, and I agree. Thats why I added the :D

  • Print