• MetaTables and UserGroups
    3 replies, posted
Hi. I'm trying to create a meta function to detect the following ranks I put in there. Such as superadmin, or admin. And well, it's not turning out the way I want. I put k,v pairs to test and see if it does detect the players and there groups properly. But it just isn't working. Any help would be greatly appreciated. Here's what I got so far. Both shared and server side file in code quote below. Shared side [CODE]local meta = FindMetaTable( "Player" ) function meta:IsAdminP() self:IsUserGroup("admin") self:IsUserGroup("doubleadmin") self:IsUserGroup("superadmin") end[/CODE] Server side Using k v to test and see if it's working. Which it's not. >.> [CODE]for k,v in pairs(player.GetAll()) do if v:IsAdminP() then v:Kill() end end[/CODE]
That IsAdminP function doesn't return anything. Try something like: [code] function meta:IsAdminP() return self:IsUserGroup( "admin" ) or self:IsUserGroup( "doubleadmin" ) or self:IsUserGroup( "superadmin" ) end [/code] Alternatively [code] local AdminP = { admin = true, doubleadmin = true, superadmin = true } function meta:IsAdminP() return AdminP[ self:GetUserGroup() ] end [/code]
Great, well try these out in a few minutes. I'll be sure to edit/post back once I try it out. [editline]4th March 2016[/editline] [QUOTE=McDunkable;49867279]That IsAdminP function doesn't return anything. Try something like: [code] function meta:IsAdminP() return self:IsUserGroup( "admin" ) or self:IsUserGroup( "doubleadmin" ) or self:IsUserGroup( "superadmin" ) end [/code] [/QUOTE] This one worked well, thank you. I had a feeling return was needed in there, but I just didn't know out to make it out. Thanks for the help both of you. =b
Sorry, you need to Log In to post a reply to this thread.