• Print

Author Topic: Forward Slashes in Commands  (Read 5625 times)

0 Members and 1 Guest are viewing this topic.

Offline BlueNova

  • Full Member
  • ***
  • Posts: 113
  • Karma: 13
  • The most powerful force in the universe.
Forward Slashes in Commands
« on: March 10, 2017, 09:57:32 pm »
So before I start I didn't know how to make the title short and sweet while staying on point so that's the best I could do.

Now a couple weeks ago I made a custom chat for moderators only. The command format being /m <message> I'm a large fan of forward slashes for chat. However this conflicts with the darkrp command for going moderator on duty (/mod). So currently when you do /mod to change your job class it just returns with (Mod Chat) <Your Name>: <message> Is there a way around this? Or so is it something I could change in ULX or would it be something else? Or would I have to just change the command in general? Thanks.

Here's the code to the command:

Code: Lua
  1. local seemodchatAccess = "seemodchat"
  2. if SERVER then ULib.ucl.registerAccess( seemodchatAccess, ULib.ACCESS_ADMIN, "Ability to see the mod chat", "Other" ) end
  3.  
  4. function ulx.modchat( calling_ply, message )
  5.        
  6.         local players = ULib.getUsers( "#superadmin, #admin, #moderator ", true )
  7.         for i=#players, 1, -1 do
  8.                 local v = players[ i ]
  9.                 if ULib.ucl.query( calling_ply, seemodchatAccess ) and v~=calling_ply then
  10.                         if ULib.ucl.query( calling_ply, seemodchatAccess ) then
  11.                                 if not calling_ply:IsValid() then
  12.                                         ULib.tsayColor( v, 1, "(Mod Chat)", console, "(Console)", mod, ": ", message )
  13.                                 else
  14.                                         ULib.tsayColor( v, 1, "(Mod Chat) ", team.GetColor(calling_ply:Team()), calling_ply:Nick(), mod, ": ", message )
  15.                                 end
  16.                         end
  17.                 end
  18.                
  19.                 if v == calling_ply then
  20.                         ULib.tsayColor( v, 1, "(Mod Chat) ", team.GetColor(calling_ply:Team()), calling_ply:Nick(), mod, ": ", message )
  21.                 end
  22.         end
  23.        
  24.         local logFile = ulx.convar( "logFile", "1", "Log to file (Can still echo if off). This is a global setting, nothing will be logged to file with this off.", ULib.ACCESS_SUPERADMIN )
  25.                 if not calling_ply:IsValid() and logFile:GetBool() then
  26.                         ulx.logString( "(Mod Chat) " .. "(Console)" .. ": " .. message, true )
  27.                 elseif logFile:GetBool() then
  28.                         ulx.logString( "(Mod Chat) " .. calling_ply:Nick() .. ": " .. message, true )
  29.                 end
  30. end
  31.  
  32. local modchat = ulx.command( CATEGORY_NAME, "ulx modchat", ulx.modchat, "/m", true, true )
  33. modchat:addParam{ type=ULib.cmds.StringArg, hint="message", ULib.cmds.takeRestOfLine }
  34. modchat:defaultAccess( ULib.ACCESS_ADMIN )
  35. modchat:help( "Sends a message to all currently connected moderators" )
  36.  

It's messy I know, I never really bothered to clean it up. Thanks in advance.

Offline Timmy

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 252
  • Karma: 168
  • Code monkey
Re: Forward Slashes in Commands
« Reply #1 on: March 11, 2017, 12:57:35 am »
Hey BlueNova!

local modchat = ulx.command( CATEGORY_NAME, "ulx modchat", ulx.modchat, "/m", true, true )

See that last 'true' in ulx.command? That tells ULX a space after the chat command is optional. This allows you to say /mTimmy is a hacker and the command would still work as expected.

You can remove the sixth argument or set it to false to turn off this behavior.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Forward Slashes in Commands
« Reply #2 on: March 11, 2017, 07:19:41 am »
Just a question because it bothers me, why do you have
Code: Lua
  1. ulx.logString( "(Mod Chat) " .. "(Console)" .. ": " .. message, true )
?

You're concatenating a bunch of strings that could just be put into one string, it's less work for the server to do:

Code: Lua
  1. ulx.logString( "(Mod Chat) (Console): " .. message, true )
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline BlueNova

  • Full Member
  • ***
  • Posts: 113
  • Karma: 13
  • The most powerful force in the universe.
Re: Forward Slashes in Commands
« Reply #3 on: March 11, 2017, 09:47:33 am »
Hey BlueNova!

local modchat = ulx.command( CATEGORY_NAME, "ulx modchat", ulx.modchat, "/m", true, true )

See that last 'true' in ulx.command? That tells ULX a space after the chat command is optional. This allows you to say /mTimmy is a hacker and the command would still work as expected.

You can remove the sixth argument or set it to false to turn off this behavior.

I'll give it a shot. Thanks

Just a question because it bothers me, why do you have
Code: Lua
  1. ulx.logString( "(Mod Chat) " .. "(Console)" .. ": " .. message, true )
?

You're concatenating a bunch of strings that could just be put into one string, it's less work for the server to do:

Code: Lua
  1. ulx.logString( "(Mod Chat) (Console): " .. message, true )

I wrote this a while back and just now wanted to change it to accommodate for the errors I was having. I know it's messy and I may do a spring cleaning with it.

Edit: It works now. Thanks Timmy (And I suppose I'll be posting in the Developer's Corner more often so the forum mods/admins don't have the go through the trouble of moving my little posts.)
« Last Edit: March 11, 2017, 09:56:49 am by BlueNova »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Forward Slashes in Commands
« Reply #4 on: March 11, 2017, 01:06:22 pm »
(And I suppose I'll be posting in the Developer's Corner more often so the forum mods/admins don't have the go through the trouble of moving my little posts.)

No worries.
Though your question did have to do with ULib/ULX support, it fit better into developers corner.
The general help/support forum area is intended more for how to work with / use / troubleshoot commands and projects we've released more than how to code for it.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

  • Print