ULX

Author Topic: Error, can't seem to fix it.  (Read 2273 times)

0 Members and 1 Guest are viewing this topic.

Offline Adult

  • Newbie
  • *
  • Posts: 15
  • Karma: 1
Error, can't seem to fix it.
« on: January 10, 2013, 07:34:43 AM »
Hey there, I was trying to make a new command, and I was getting a strange error involving ULib.cmds.TranslateCommand.

Here is the code I used:

Code: [Select]
local f = "ULib/restricted_concommands.txt"
local data = file.Read( f, "DATA" ) or {}



--------------- Helpers -----------------
local function saveFile()
file.Write( f, util.TableToKeyValues( data ) )
end

local function loadFile()
data = file.Read( f, "DATA" ) or {}
end

-- Important that you don't call this after making
-- changes to permissions without saving your changes.
local function loadFuncs()
local old_comms = concommand.GetTable()
loadFile()

for k,v in pairs( old_comms ) do
concommand.Remove( k ) -- Remove it first
-- Create a new function that calls the hook first
local new = function( ply, cmd, args, str )
local allow = hook.Call( "ConCommandRan", GAMEMODE, ply, cmd, args, str )
if not allow then return end
v( ply, cmd, args, str )
end

-- Use that function as the new console command.
concommand.Add( k, new )
end
end

-- Can the player use the command?
local function allowed( cmd, ply )
local group = ply:GetUserGroup()
local groupInfo = data[group]

return groupInfo.allow[cmd] ~= false
end

--------------------------------------------------

-- ulx --
function ulx.groupallowcmd( caller, group, cmd )
local groupInfo = data[group]
if not groupInfo.allow[cmd] then
ULib.tsayError( caller, "Group \'#s\' does not have access to #s", group, cmd )
return false
end

groupInfo.allow[cmd] = true   
saveFile()
ulx.fancyLogAdmin( caller, false, "#A restricted command #s from group #s.", cmd, group )
end


local allow = ulx.command( "User Management", ulx.groupallowcmd, "ulx groupallowcmd" )
allow:addParam{ type=ULib.cmds.StringArg, completes=ulx.group_names, hint="group", error="invalid group \"%s\" specified", ULib.cmds.restrictToCompletes }
allow:addParam{ type=ULib.cmds.StringArg, hint="command" }
allow:defaultAccess( ULib.ACCESS_SUPERADMIN )
allow:help( "Allows a group's access to a command." )


function ulx.groupdenycmd( caller, group, cmd )
local groupInfo = data[group]
if not groupInfo.allow[cmd] then
ULib.tsayError( caller, "Group \'#s\' does not have access to #s", group, cmd )
return false
end

groupInfo.allow[cmd] = false 
saveFile()
ulx.fancyLogAdmin( caller, false, "#A restricted command #s from group #s.", cmd, group )
end

local deny = ulx.command( "User Management", ulx.groupdenycmd, "ulx groupdenycmd" )
deny:addParam{ type=ULib.cmds.StringArg, completes=ulx.group_names, hint="group", error="invalid group \"%s\" specified", ULib.cmds.restrictToCompletes }
deny:addParam{ type=ULib.cmds.StringArg, hint="command" }
deny:defaultAccess( ULib.ACCESS_SUPERADMIN )
deny:help( "Denies a group's access to a command." )


-- hooks --

local function concommandRan( ply, cmd, args, str )
if not allowed( cmd, ply ) then
ULib.tsayError( ply, "You don't have access to this command, " .. ply:Name() )
return false
end

return true
end

hook.Add( "ConCommandRan", "ULX_RestrictConcommands", concommandRan )

local function init()
-- New hook, leave it blank for now. We'll right the ulx hook later.
-- return true to allow it to run, return false to deny.
function GAMEMODE:ConCommandRan( ply, cmd, args, str )
return true
end

loadFuncs()
end

hook.Add( "Initialize", "ULX_LoadConcommands", init )

and here is the error:


To save you the trouble, the error is referring to this function:
Code: [Select]
function ulx.groupallowcmd( caller, group, cmd )
local groupInfo = data[group]
if not groupInfo.allow[cmd] then
ULib.tsayError( caller, "Group \'#s\' does not have access to #s", group, cmd )
return false
end

groupInfo.allow[cmd] = true   
saveFile()
ulx.fancyLogAdmin( caller, false, "#A restricted command #s from group #s.", cmd, group )
end


-- THIS LINE SPECIFICALLY. ->>> local allow = ulx.command( "User Management", ulx.groupallowcmd, "ulx groupallowcmd" )
allow:addParam{ type=ULib.cmds.StringArg, completes=ulx.group_names, hint="group", error="invalid group \"%s\" specified", ULib.cmds.restrictToCompletes }
allow:addParam{ type=ULib.cmds.StringArg, hint="command" }
allow:defaultAccess( ULib.ACCESS_SUPERADMIN )
allow:help( "Allows a group's access to a command." )

As you can tell, the script is saved in ulx/lua/ulx/modules/sh

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Error, can't seem to fix it.
« Reply #1 on: January 10, 2013, 09:27:31 AM »
The format for ulx.command is:

Code: [Select]
ulx.command( (string) category, (string) consoleCommand, (function) callback, (string) chatCommand )
So the error is what I would expect to see -- it is expecting a string, but is given a function instead.
Experiencing God's grace one day at a time.

Offline Adult

  • Newbie
  • *
  • Posts: 15
  • Karma: 1
Re: Error, can't seem to fix it.
« Reply #2 on: January 10, 2013, 11:58:34 AM »
Oh my, how silly of me. Thank you.