Ulysses
General => Developers Corner => Topic started by: BobTheDuck69 on March 12, 2015, 11:02:50 PM
-
I made this as a command for admins to talk without using ooc to talk about random things without interfeering with admin chat can you tell me how i can fix it i havent fully tested but i need it to work
local seeachatterAccess = "ulx seeachatter"
if SERVER then ULib.ucl.registerAccess( seeachatterAccess, ULib.ACCESS_OPERATOR, "Ability to see 'ulx achatter'", "Other" ) end -- Give operators access to see achatters echoes by default
function ulx.achatter( 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 = " <Achatter> #P #s"
end
local players = player.GetAll()
for i=#players, 1, -1 do
local v = players[ i ]
if not ULib.ucl.query( v, seeachatterAccess ) 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 achatter = ulx.command( CATEGORY_NAME, "ulx achatter", ulx.achatter, "!achatter", true, true )
achatter:addParam{ type=ULib.cmds.StringArg, hint="message", ULib.cmds.takeRestOfLine }
achatter:defaultAccess( ULib.ACCESS_ALL )
achatter:help( "Send a message to admins in the chat." )
-
So now i get this error in console while server starts.
// MODULE: achatter.lua //
[ERROR] addons/ulx/lua/ulx/sh_base.lua:45: table index is nil
1. command - addons/ulx/lua/ulx/sh_base.lua:45
2. unknown - addons/ulx/lua/ulx/modules/sh/achatter.lua:24
3. include - [C]:-1
4. unknown - addons/ulx/lua/ulx/init.lua:33
5. include - [C]:-1
6. unknown - addons/ulx/lua/ulib/modules/ulx_init.lua:2
7. include - [C]:-1
8. unknown - addons/ulib/lua/ulib/init.lua:68
9. include - [C]:-1
10. unknown - addons/ulib/lua/autorun/ulib_init.lua:3
-
Taking a while guess and saying it something with this line?
table.remove( players, i )
You're removing one value so the index or length of the table decreases. What happens when you reach i = total players? The index goes out of bounds. Sounds like that may be the source of the error. I would create a temporary table and just insert each player into it rather than trying to remove.
EDIT: Perhaps I'm partially wrong, if it errors on startup. Definitely something you'll have to fix tho.
EDIT2: Found it...
local achatter = ulx.command( CATEGORY_NAME, "ulx achatter", ulx.achatter, "!achatter", true, true )
CATEGORY_NAME doesn't exist by the looks of it. So it will mess up a bunch of things.
-
Well im doing better than i thought then. i thought i messed it up completely.