Author Topic: ULX Admin Chat  (Read 660 times)

0 Members and 1 Guest are viewing this topic.

Offline Darkblizzard

  • Newbie
  • *
  • Posts: 30
  • Karma: 0
    • View Profile
Re: ULX Admin Chat
« Reply #15 on: July 16, 2017, 12:31:28 PM »
To think it wasn't going to be too hard to learn, this extra step got me.


Ah, so they're all placed as separate args, then.

Easy fix:

Code: Lua
  1. hook.Add( "ULibCommandCalled", "admin chat replace", function( ply, cmd, args )
  2.     if cmd == "ulx asay" then
  3.         local admins = {}
  4.         local final_str = ""
  5.         for _, player in pairs( player.GetAll() ) do
  6.             if ULib.ucl.query( player, "ulx seeasay" ) then
  7.                 table.insert( admins, player )
  8.             end
  9.         end
  10.         for _, arg in pairs( args ) do
  11.             final_str = final_str .. arg -- Goes through each arg and concatenates it to "final_str"
  12.         end
  13.         for _, player in pairs( admins ) do
  14.             ULib.tsayColor( player, "", Color( 0, 255, 0 ), "[Admin Request] ", Color( 255, 255, 255 ), ply:Nick() .. ": " .. final_str )
  15.         end
  16.         return false
  17.     end
  18. end )
  19.  
  20.  

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 7740
  • Karma: 352
  • Sertafide Ulysses Jenius
    • View Profile
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ULX Admin Chat
« Reply #16 on: July 16, 2017, 03:35:45 PM »
I could have sworn there is an argument shortcut? args* or args[2-] or something, so you wouldn't have to do a loop.
Code: [Select]
for _, arg in pairs( args ) do
            final_str = final_str .. arg -- Goes through each arg and concatenates it to "final_str"
        end
could maybe be replaced with final_str = args... or something. Not quite sure.

EDIT - Found this -
https://wiki.garrysmod.com/page/Category:vararg
Doesn't easily explain what I think I remember in my head, but, I think it's getting closer.
« Last Edit: July 16, 2017, 03:38:31 PM by JamminR »
The price one pays for pursuing any profession or calling is an intimate knowledge of its ugly side. - James Baldwin

Offline iViscosity

  • Hero Member
  • *****
  • Posts: 691
  • Karma: 37
    • View Profile
    • iViscosity Gaming
Re: ULX Admin Chat
« Reply #17 on: July 16, 2017, 03:56:00 PM »
Oh. I think I know what you're talking about. I think it's args[ 1:: ] or something.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me a PM or Join my Discord!.
--==[ Links ]==--
Steam
YouTube
Steam Group (feel free to join!)
Forums
Public Discord
Teamspeak

Quote from: Steve Jobs
Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven't found it yet, keep looking. Don't settle. As with all matters of the heart, you'll know when you find it. And, like any great relationship, it just gets better and better as the years roll on. So keep looking until you find it. Don't settle.

Offline monkeymacman

  • Newbie
  • *
  • Posts: 43
  • Karma: 12
    • View Profile
Re: ULX Admin Chat
« Reply #18 on: July 17, 2017, 09:49:35 AM »
It seems like you should be able to turn a table (such as args) into varargs (which should be able to be printed) by doing unpack(args).


Example of this sort of functionality




Edit: This would leave out the spaces when using Ulib Tsay, so it would be so much better to just have the message be table.concat(args, " ")


Edit 2: Wait, but the code that loops through just concats the arguments without spaces, so... what am I missing that adds the space in that?
« Last Edit: July 17, 2017, 10:17:48 AM by monkeymacman »

Offline iViscosity

  • Hero Member
  • *****
  • Posts: 691
  • Karma: 37
    • View Profile
    • iViscosity Gaming
Re: ULX Admin Chat
« Reply #19 on: July 17, 2017, 08:33:57 PM »
Edit 2: Wait, but the code that loops through just concats the arguments without spaces, so... what am I missing that adds the space in that?

I guess I assumed that because it's a message there would be spaces that I thought would automatically be placed. Now that I think about it, I don't think it'd happen.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me a PM or Join my Discord!.
--==[ Links ]==--
Steam
YouTube
Steam Group (feel free to join!)
Forums
Public Discord
Teamspeak

Quote from: Steve Jobs
Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven't found it yet, keep looking. Don't settle. As with all matters of the heart, you'll know when you find it. And, like any great relationship, it just gets better and better as the years roll on. So keep looking until you find it. Don't settle.

Offline Darkblizzard

  • Newbie
  • *
  • Posts: 30
  • Karma: 0
    • View Profile
Re: ULX Admin Chat
« Reply #20 on: July 18, 2017, 12:00:48 AM »
Yeah, it would appear that any more than one word will still be cut off.

Offline monkeymacman

  • Newbie
  • *
  • Posts: 43
  • Karma: 12
    • View Profile
Re: ULX Admin Chat
« Reply #21 on: July 18, 2017, 06:27:46 PM »
I guess I assumed that because it's a message there would be spaces that I thought would automatically be placed. Now that I think about it, I don't think it'd happen.
No, the thing is that that does work, but manually putting in strings without the spaces does not add spaces, so I'm very confused about what makes that work.

Offline iViscosity

  • Hero Member
  • *****
  • Posts: 691
  • Karma: 37
    • View Profile
    • iViscosity Gaming
Re: ULX Admin Chat
« Reply #22 on: July 19, 2017, 01:10:01 AM »
No, the thing is that that does work, but manually putting in strings without the spaces does not add spaces, so I'm very confused about what makes that work.


So I did a little digging and I found out why.
Basically, ULib trims down non-quoted sentences and adds them into a table, for example: 'I am cool' would be returned at { "I", "am", "cool" }. While, '"I am cool" lol' is returned at { "I am cool", "lol" }
I'm iViscosity. I like gaming and programming. Need some help? Shoot me a PM or Join my Discord!.
--==[ Links ]==--
Steam
YouTube
Steam Group (feel free to join!)
Forums
Public Discord
Teamspeak

Quote from: Steve Jobs
Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven't found it yet, keep looking. Don't settle. As with all matters of the heart, you'll know when you find it. And, like any great relationship, it just gets better and better as the years roll on. So keep looking until you find it. Don't settle.