General > Developers Corner

Custom ULX AddTrustie code

(1/3) > >>

cold12141:
The console error that was being received was something about the table.

Also, what is wrong with this code:

--- Code: ---function ulx.cc_addtrustie( ply, command, argv, args )
if #argv < 1 then
if #argv ~= 0 then
ULib.tsay( ply, ulx.LOW_ARGS )
else
ULib.console( ply, "ulx addtrustie <user>" )
end
return
end

local target, err = ULib.getUser( argv[ 1 ], _, ply )
if not target then
ULib.tsay( ply, err )
return
end

if target:IsUserGroup( ULib.ACCESS_SUPERADMIN ) and ply:IsValid() and not ply:IsListenServerHost() then
ULib.tsay( ply, "Sorry, for security reasons, you can't change the access of a superadmin!" )
return
end

local info = ULib.ucl.authed[ target ]
if not info then
ULib.ucl.addUser( target:Nick(), "steamid", target:SteamID(), "trusted", {allow={}, deny={}} , _, _, true )
else
ULib.ucl.addUser( info.account, info.type, info.id, "trusted", {allow={}, deny={}} , _, _, true )
end
end
ulx.concommand( "addtrustie", ulx.cc_addtrustie, "<user>", ULib.ACCESS_MEMBER, _, _, ulx.ID_PLAYER_HELP )

--- End code ---

JamminR:
Cold, hope you don't mind, moved your post to Developers corner and started a new topic with it.
Some day I intend to make a sticky somewhere and point to various bits of code people here have done, and separating this from the 'preventing users from building by group' post seems logical.

Also, if you haven't already, may I suggest making this a custom file in your gmod/addons/ulib/lua/ULib/modules
That way when ULX/Ulib is updated, your code won't get overwritten.

I'm looking over the code now, will edit my post if I see any mistakes.
In the meantime, what error are you getting, if any?

JamminR:
Ok, Think I found a major problem to your code.
The ULib.ucl.addUser requires you to add people to a 'group' as a table.
You're passing it a string "trusted"

1) I strongly recommend keeping our immunity code in there. It will allow you to make a trusted user immune later if you wish.
2) Don't forget to re-add the logging code. Any access level changes should be logged, custom or not. Just good security of any access in life. :)

This should fix your problem (I left out the immunity for now, but still, I recommend it)

--- Code: --- local groups = { "trusted" }

local info = ULib.ucl.authed[ target ]
if not info then
ULib.ucl.addUser( target:Nick(), "steamid", target:SteamID(), groups, {allow={}, deny={}} , _, _, true )
else
ULib.ucl.addUser( info.account, info.type, info.id, groups, {allow={}, deny={}} , _, _, true )
end

--- End code ---

Hope that fixes it for you. If not, let us know.

cold12141:
That did not fix it.

This is the error I receive when trying to add a user.

--- Code: ---[LS ULIB ERROR] Bad user passed to addUser! User account name was nil
--- End code ---

JamminR:

--- Quote from: cold12141 on May 10, 2007, 04:24:42 PM ---That did not fix it.

This is the error I receive when trying to add a user.

--- Code: ---[LS ULIB ERROR] Bad user passed to addUser! User account name was nil
--- End code ---

--- End quote ---

What are you passing after ulx addtrustie? Player name? SteamID? Is the player connected?
Sounds like this line

--- Code: ---local target, err = ULib.getUser( argv[ 1 ], _, ply )
--- End code ---
is running, but, doesn't contain the information info variable expects.


Navigation

[0] Message Index

[#] Next page

Go to full version