i keep getting errors and also no one names show after i did this?
[ERROR] addons/silkchat/lua/autorun/silkchat.lua:75: attempt to call method 'IsOwner' (a nil value)
1. getPlayerIcon - addons/silkchat/lua/autorun/silkchat.lua:75
2. fn - addons/silkchat/lua/autorun/silkchat.lua:182
3. unknown - addons/ulib/lua/ulib/shared/hook.lua:183
[CODE]
if ply:IsSuperAdmin() then
icon = "icon16/shield_add.png"
elseif ply:IsAdmin() then
icon = "icon16/shield.png"
elseif ply:IsOwner() then
icon = "icon16/shield_rainbow.png"
elseif ply:IsModerator() then
icon = "icon16/shield_silver.png"
elseif ply:IsVip() then
icon = "icon16/rosette_blue.png"
end[/CODE]
Is Owner an actual group?
[QUOTE=Triple-X;39273076]Is Owner an actual group?[/QUOTE]
ya all i want to do is add extra groups and new icons but i dont know how to if you want full code i will show you
Lua doesn't just magically create functions for you; you need to create them.
[lua]
local meta = FindMetaTable( "Player" )
function meta:IsOwner()
return self:IsUserGroup("owner")
end[/lua]
and so on. Of course there's no reason to do this instead of just using IsUserGroup.
[QUOTE=.\\Shadow};39273107]Lua doesn't just magically create functions for you; you need to create them.
[lua]
local meta = FindMetaTable( "Player" )
function meta:IsOwner()
return self:IsUserGroup("owner")
end[/lua]
and so on. Of course there's no reason to do this instead of just using IsUserGroup.[/QUOTE]
where would i but the group and icons i want in?
I would do something like this:
[lua]
local UserManagement = {
["owner"] = {Icon = "icon16/shield_rainbow.png"},
["superadmin"] = {Icon = "icon16/shield_add.png"},
["admin"] = {Icon = "icon16/shield.png"},
["moderator"] = {Icon = "icon16/shield_silver.png"},
["vip"] = {Icon = "icon16/rosette_blue.png"}
}
function GetUserIcon(ply)
if !ply then return end
local group = ply:GetUserGroup()
local icon = UserManagement[group]
if icon then
return icon.Icon
end
return ""
end
--Example
print(GetUserIcon(Entity(1)))--me
print(GetUserIcon(Entity(2)))--bot returns ""
[/lua]
ply:GetUserGroup() doesn't exist by default- you should use ply:GetNWString( "UserGroup" ) to avoid people without whatever addon is creating it from getting errors.
[QUOTE=.\\Shadow};39275209]ply:GetUserGroup() doesn't exist by default- you should use ply:GetNWString( "UserGroup" ) to avoid people without whatever addon is creating it from getting errors.[/QUOTE]
I was only considering it for ULX users.
[QUOTE=brandonj4;39275237]I was only considering it for ULX users.[/QUOTE]
Well, he didn't really specify he was using ULX- so there's a chance it wouldn't even work for the person it was intended for. Plus, why make it incompatible like that? There's no reason [i]not[/i] to just check the group nwstring.
Sorry, you need to Log In to post a reply to this thread.