Author Topic: ulx asay  (Read 3253 times)

0 Members and 1 Guest are viewing this topic.

Offline Sweepyoface

  • Newbie
  • *
  • Posts: 12
  • Karma: -1
ulx asay
« on: January 09, 2015, 12:31:24 PM »
I am trying to make it so when people that do not have access to 'ulx seeasay' use @ it has a different format than people who do have access to it. For example:

Admins using asay: (Admins) Sweepyoface: Hello!
User using asay: (Admin Request) bob123: Help! RDM!

I know its in here but I don't know how to code it.

Code: [Select]
------------------------------ Asay ------------------------------
local seeasayAccess = "ulx seeasay"
if SERVER then ULib.ucl.registerAccess( seeasayAccess, ULib.ACCESS_OPERATOR, "Ability to see 'ulx asay'", "Other" ) end -- Give operators access to see asays echoes by default

function ulx.asay( calling_ply, message )
local format
local me = "/me "
if message:sub( 1, me:len() ) == me then
format = "(ADMINS) *** #P #s"
message = message:sub( me:len() + 1 )
else
format = "#P to admins: #s"
end

local players = player.GetAll()
for i=#players, 1, -1 do
local v = players[ i ]
if not ULib.ucl.query( v, seeasayAccess ) and v ~= calling_ply then -- Calling player always gets to see the echo
table.remove( players, i )
end
end

ulx.fancyLog( players, format, calling_ply, message )
end
local asay = ulx.command( CATEGORY_NAME, "ulx asay", ulx.asay, "@", true, true )
asay:addParam{ type=ULib.cmds.StringArg, hint="message", ULib.cmds.takeRestOfLine }
asay:defaultAccess( ULib.ACCESS_ALL )
asay:help( "Send a message to currently connected admins." )

Edit: I made a little something, I'm pretty sure this won't work. Can anyone help?

Code: [Select]
function ulx.asay( calling_ply, message )
local format
if calling_ply(seeasayAccess) ~= true then
format = "(Admin Request) #P: #s"
else
format = "(Admins) #P: #s"
end
« Last Edit: January 09, 2015, 12:37:52 PM by Sweepyoface »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ulx asay
« Reply #1 on: January 09, 2015, 03:16:42 PM »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Sweepyoface

  • Newbie
  • *
  • Posts: 12
  • Karma: -1
Re: ulx asay
« Reply #2 on: January 09, 2015, 03:59:26 PM »
I'm not really sure how to implement that.. Would it be something like this?

Code: [Select]
function ulx.asay( calling_ply, message )
local format
if ULib.ucl.query( seeasayAccess ) ~= calling_ply true then
format = "(Admin Request) #P: #s"
else
format = "(Admins) #P: #s"
end

local players = player.GetAll()
for i=#players, 1, -1 do
local v = players[ i ]
if not ULib.ucl.query( v, seeasayAccess ) and v ~= calling_ply then -- Calling player always gets to see the echo
table.remove( players, i )
end
end

Edit:
« Last Edit: January 09, 2015, 04:45:23 PM by Sweepyoface »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ulx asay
« Reply #3 on: January 09, 2015, 10:10:24 PM »
No, you still have to specify the player to check. The link shows how.
There's an example farther down in the code of it being used, v in the example is a player object, in that case though, it is going through a for loop of all players, so v is a value of the loop.

All this being said, I'd strongly recommend you make a new command rather than editing our code.
Learning lua by example is fine, but also, you're re-inventing the wheel.
And that wheel even comes with a menu.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Sweepyoface

  • Newbie
  • *
  • Posts: 12
  • Karma: -1
Re: ulx asay
« Reply #4 on: January 09, 2015, 11:02:38 PM »
I don't understand why this code doesn't work. I'm planning to get that addon you mentioned it's just I'm trying to learn and I don't know why it's not working. Bit of a noob, sorry.

Code: [Select]
function ulx.asay( calling_ply, message )
local format
if ULib.ucl.query( calling_ply, "ulx seeasay" ) == true then
format = "(Admins) #P: #s"
else
format = "(Admin Request) #P: #s"
end

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ulx asay
« Reply #5 on: January 10, 2015, 08:21:18 AM »
Other than you keep changing up variables that may or may not be defined in the rest of the script, I really don't kow.
See this. Untested, but should work in theory, if it were replacing the original asay command in the original chat.lua file (becuase there's other setup of variables not included in this example)
I've commented the area that changed (some lines are still original, but commented because lines changed after)

Code: [Select]
function ulx.asay( calling_ply, message )
local format
local me = "/me "
if message:sub( 1, me:len() ) == me then -- test if person used "@ /me <action>"
if ULib.ucl.query ( calling_ply, seeasayAccess ) == true then -- test if calling player has (previously defined) seeasayAccess
format = "(ADMINS) *** #P #s" -- player had it, they're an "admin" (or at least have access), do normal
else -- player isn't an "admin" (no seeasay)
format = "(ADMINS REPORT) *** #P #s" -- therefore player is making report
end -- end of checking if calling player can see asay
message = message:sub( me:len() + 1 ) -- change of message to remove "/me" if calling player used it
else -- end of "/me" replacement, they didn't use /me, use normal non-action formatting
if ULib.ucl.query ( calling_ply, seeasayAccess ) == true then -- test if calling player has (previously defined) seeasayAccess
format = "#P to admins: #s" -- player had it, they're an "admin" (or at least have access), do normal
else -- player isn't an "admin" (no seeasay)
format = "#P ADMINS REPORT: #s" -- therefore player is making report
end -- end of checking if calling player can see asay
end -- end of checking if player used /me and formatting as such or not
local players = player.GetAll()
for i=#players, 1, -1 do
local v = players[ i ]
if not ULib.ucl.query( v, seeasayAccess ) and v ~= calling_ply then -- Calling player always gets to see the echo
table.remove( players, i )
end
end
ulx.fancyLog( players, format, calling_ply, message )
end
« Last Edit: January 10, 2015, 08:23:55 AM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Sweepyoface

  • Newbie
  • *
  • Posts: 12
  • Karma: -1
Re: ulx asay
« Reply #6 on: January 10, 2015, 11:38:27 AM »
Even that exact code doesn't work. It goes to ADMINS REPORT no matter if I have access to seeasay or not. That's odd..

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: ulx asay
« Reply #7 on: January 10, 2015, 11:54:01 AM »
Try debugging your code -- put print statements between statements with the values of the variables so you can see what's going on.
Experiencing God's grace one day at a time.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ulx asay
« Reply #8 on: January 10, 2015, 02:28:07 PM »
You keep saying 'I' as though your testing instead of having a regular player.
Besides what Megiddo suggests,
1) make sure the group you are in isn't inheriting another group that has it.
2) Make sure you aren't testing in listen server or single player (You have access to all in that manner).
Make sure you've restarted server after editing code (A) again, we're not recommending you even edit, but, if you just must try yourself then (B) we recommend not having server even running when editing code)
And, last, make sure your editing your server's code and not your local (unless of course it's listen server, but then again, see 2).
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming