• Print

Author Topic: ULX Admin Chat  (Read 13604 times)

0 Members and 1 Guest are viewing this topic.

Offline Darkblizzard

  • Newbie
  • *
  • Posts: 39
  • Karma: 1
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: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • 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 »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
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 PM.

Offline monkeymacman

  • Newbie
  • *
  • Posts: 44
  • Karma: 13
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

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
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 PM.

Offline Darkblizzard

  • Newbie
  • *
  • Posts: 39
  • Karma: 1
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: 44
  • Karma: 13
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

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
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 PM.

  • Print