General > Developers Corner

ulx asay

(1/2) > >>

Sweepyoface:
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: --------------------------------- 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." )
--- End code ---

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


--- Code: ---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
--- End code ---

JamminR:
ULib.ucl.query()

Sweepyoface:
I'm not really sure how to implement that.. Would it be something like this?


--- Code: ---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
--- End code ---

Edit:

JamminR:
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.

Sweepyoface:
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: ---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
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version