ULX

Author Topic: Achatter admin chat  (Read 1659 times)

0 Members and 1 Guest are viewing this topic.

Offline BobTheDuck69

  • Newbie
  • *
  • Posts: 33
  • Karma: 1
Achatter admin chat
« 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
Code: [Select]
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." )
~The friendly neighborhood duckie~

Offline BobTheDuck69

  • Newbie
  • *
  • Posts: 33
  • Karma: 1
Re: Achatter admin chat
« Reply #1 on: March 12, 2015, 11:16:44 PM »
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
~The friendly neighborhood duckie~

Offline Aaron113

  • Hero Member
  • *****
  • Posts: 803
  • Karma: 102
Re: Achatter admin chat
« Reply #2 on: March 12, 2015, 11:23:50 PM »
Taking a while guess and saying it something with this line?

Code: [Select]
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...

Code: [Select]
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.
« Last Edit: March 12, 2015, 11:27:57 PM by Aaron113 »

Offline BobTheDuck69

  • Newbie
  • *
  • Posts: 33
  • Karma: 1
Re: Achatter admin chat
« Reply #3 on: March 13, 2015, 12:13:36 AM »
Well im doing better than i thought then. i thought i messed it up completely.
~The friendly neighborhood duckie~