So I am attempting to create a meta table that either returns the name of a table or false. Before I go into more depth, here's what I think is on the right track to what I think I'm trying to do (if that makes sense).
[CODE]
local meta = FindMetaTable("Player")
function meta:InGroup()
if table.HasValue ( GROUPS.group1.members , self:SteamID() )
return group1
else return false
end
end
[/CODE]
Now the problem is that within the GROUPS table their can be more "groups". For instance their can be a group2 or a group3 for example, so I'm not sure how to make this so it checks all possible tables within the GROUPS table and how to also return the specific group# table that the player is in.
I apologize in advance to my obvious cluelessness...
It'd be easier for you if you'd store the group in a player, not a player in a group.
For example
GROUPS.usergroups[self:SteamID() ] = "group1"
local the_groyp = GROUPS.usergroups[ self:SteamID() ]
And then if you want to get the group table, you could just do GROUPS[ the_groyp ] or something.
[editline]21st July 2015[/editline]
But in your case you could do
[code]
for id, group in pairs( GROUPS ) do
if table.HasValue( group .members , self:SteamID() ) then
return group
end
return false
end
[/code]
[QUOTE=MelonPimp;48255511]So I am attempting to create a meta table that either returns the name of a table or false. Before I go into more depth, here's what I think is on the right track to what I think I'm trying to do (if that makes sense).
[CODE]
local meta = FindMetaTable("Player")
function meta:InGroup()
if table.HasValue ( GROUPS.group1.members , self:SteamID() )
return group1
else return false
end
end
[/CODE]
Now the problem is that within the GROUPS table their can be more "groups". For instance their can be a group2 or a group3 for example, so I'm not sure how to make this so it checks all possible tables within the GROUPS table and how to also return the specific group# table that the player is in.
I apologize in advance to my obvious cluelessness...[/QUOTE]
Couldn't you do ply:SetUserGroup(group) and then just do ply:GetUserGroup() ?
EDIT:
Didn't fully read the thread, you should store the groups in the player like so:
ply.groups = {}
ply.groups[groupname] = true
EDIT:
Ninja'ed by robotboy!
Sorry, you need to Log In to post a reply to this thread.