General > Developers Corner
Trying to merge ulx adduser/removeuser and FAdmin setaccess into one
strategos:
I'm trying to, when ulx adduser(id)/removeuser(id) is run, to auto-add them to the co-responding FAdmin group when the command is successfully run.
The format for fadmin setaccess is: Fadmin setaccess "nick/steamid" "group"
The functions adduser, adduserid, removeuser, and removeuserid have been modified
It adds them to the ulx group but it returns this (something similar each time)
[addons\ulx\lua\ulx\modules\sh\user.lua:79] attempt to perform arithmetic on a string value
--- Code: ---function ulx.adduser( calling_ply, target_ply, group_name )
group_name = group_name:lower()
local userInfo = ULib.ucl.authed[ target_ply:UniqueID() ]
local id = ULib.ucl.getUserRegisteredID( target_ply )
if not id then id = target_ply:SteamID() end
ULib.ucl.addUser( id, userInfo.allow, userInfo.deny, group_name )
calling_ply:ConCommand("fadmin", "setaccess " + id + group_name)
ulx.fancyLogAdmin( calling_ply, "#A added #T to group #s", target_ply, group_name )
end
local adduser = ulx.command( CATEGORY_NAME, "ulx adduser", ulx.adduser )
adduser:addParam{ type=ULib.cmds.PlayerArg }
adduser:addParam{ type=ULib.cmds.StringArg, completes=ulx.group_names_no_user, hint="group", error="invalid group \"%s\" specified", ULib.cmds.restrictToCompletes }
adduser:defaultAccess( ULib.ACCESS_SUPERADMIN )
adduser:help( "Add a user to specified group." )
function ulx.adduserid( calling_ply, id, group_name )
id = id:upper() -- Steam id needs to be upper
group_name = group_name:lower()
-- Check for valid and properly formatted ID
if not checkForValidId( calling_ply, id ) then return false end
-- Now add the fool!
ULib.ucl.addUser( id, allows, denies, group_name )
calling_ply:ConCommand("fadmin", "setaccess " + id + " " + group_name)
if ULib.ucl.users[ id ] and ULib.ucl.users[ id ].name then
ulx.fancyLogAdmin( calling_ply, "#A added #s to group #s", ULib.ucl.users[ id ].name, group_name )
else
ulx.fancyLogAdmin( calling_ply, "#A added userid #s to group #s", id, group_name )
end
end
local adduserid = ulx.command( CATEGORY_NAME, "ulx adduserid", ulx.adduserid )
adduserid:addParam{ type=ULib.cmds.StringArg, hint="SteamID, IP, or UniqueID" }
adduserid:addParam{ type=ULib.cmds.StringArg, completes=ulx.group_names_no_user, hint="group", error="invalid group \"%s\" specified", ULib.cmds.restrictToCompletes }
adduserid:defaultAccess( ULib.ACCESS_SUPERADMIN )
adduserid:help( "Add a user by ID to specified group." )
function ulx.removeuser( calling_ply, target_ply )
ULib.ucl.removeUser( target_ply:UniqueID() )
calling_ply:ConCommand("fadmin", "setaccess " + tostring(target_ply:SteamID()) + " user")
ulx.fancyLogAdmin( calling_ply, "#A removed all access rights from #T", target_ply )
end
local removeuser = ulx.command( CATEGORY_NAME, "ulx removeuser", ulx.removeuser )
removeuser:addParam{ type=ULib.cmds.PlayerArg }
removeuser:defaultAccess( ULib.ACCESS_SUPERADMIN )
removeuser:help( "Permanently removes a user's access." )
function ulx.removeuserid( calling_ply, id )
id = id:upper() -- Steam id needs to be upper
-- Check for valid and properly formatted ID
if not checkForValidId( calling_ply, id ) then return false end
if not ULib.ucl.authed[ id ] and not ULib.ucl.users[ id ] then
ULib.tsayError( calling_ply, "No player with id \"" .. id .. "\" exists in the ULib user list", true )
return false
end
local name = (ULib.ucl.authed[ id ] and ULib.ucl.authed[ id ].name) or (ULib.ucl.users[ id ] and ULib.ucl.users[ id ].name)
ULib.ucl.removeUser( id )
calling_ply:ConCommand("fadmin", "setaccess " + id + " user")
if name then
ulx.fancyLogAdmin( calling_ply, "#A removed all access rights from #s", name )
else
ulx.fancyLogAdmin( calling_ply, "#A removed all access rights from #s", id )
end
end
local removeuserid = ulx.command( CATEGORY_NAME, "ulx removeuserid", ulx.removeuserid )
removeuserid:addParam{ type=ULib.cmds.StringArg, hint="SteamID, IP, or UniqueID" }
removeuserid:defaultAccess( ULib.ACCESS_SUPERADMIN )
removeuserid:help( "Permanently removes a user's access by ID." )
--- End code ---
JamminR:
--- Quote from: strategos on November 20, 2011, 05:18:27 PM ---The functions adduser, adduserid, removeuser, and removeuserid have been modified
--- End quote ---
Don't modify.
ULib has hooks for during and post command.
Use them instead, and make your own addon folder.
--- Quote from: strategos on November 20, 2011, 05:18:27 PM ---[addons\ulx\lua\ulx\modules\sh\user.lua:79] attempt to perform arithmetic on a string value
--- Code: --- calling_ply:ConCommand("fadmin", "setaccess " + id + group_name)
calling_ply:ConCommand("fadmin", "setaccess " + id + " " + group_name)
calling_ply:ConCommand("fadmin", "setaccess " + tostring(target_ply:SteamID()) + " user")
calling_ply:ConCommand("fadmin", "setaccess " + id + " user")
--- End code ---
--- End quote ---
"+" is a math statement.
I'm pretty sure I know what you're trying to do with +, but that's not how you do it in Lua. :)
I'm not going to give it away and will let you search a bit on your own.
EDIT = Regarding the hooks.
See ULibCommandCalled or ULibPostTranslatedCommand
That will allow you to monitor for any of the normal ULX commands, and run things in addition to them.
MrPresident:
Ahh, that's harsh Jam. hah! .. I really hope that he can figure out what he needs to use instead of "+".. you know .. so that he can finish his script and get it up and running.
Aaron113:
Too much coding in E2 :D
JamminR:
--- Quote from: MrPresident on November 20, 2011, 09:29:14 PM ---Ahh, that's harsh Jam. hah!
--- End quote ---
I know, I'm so mean.
Seriously though, I don't know how many times I learned something new from (Lua/Glua/insert any scripting language I know enough to be dangerous with here) while searching for a solution to something else.
A bit of searching, even through other ulx code examples, shouldn't take toooo long.
:)
Navigation
[0] Message Index
[#] Next page
Go to full version