PlyGroups = {}
PlyGroups.group = {}
local meta = FindMetaTable("Player")
function string.sanitise( str )
return string.Trim(string.Replace(string.Replace(string.Replace( tostring(str), "\\", "/" ), "\"", ""), ";", ""))
end
function meta:GetGroup()
self.Group = self:GetPData( "PlayerGroup", "none" )
if( not self.Group ) then error("This player is not in a group.") return end
return self.Group
end
function PlyGroups.GetCurrentGroups()
local oldgroups = {}
local duplicates = 0
for k,_ in pairs(PlyGroups.group) do
if( table.HasValue(oldgroups, k) ) then
PlyGroups.group[k] = nil
duplicates = duplicates + 1
end
table.insert( oldgroups, k )
end
print( tostring(duplicates) .. " have been removed." )
return oldgroups
end
function PlyGroups.CreateGroupsTable()
local newgroups = 0
for k,v in pairs(player.GetAll()) do
if not PlyGroups.group[v:GetGroup()] then
PlyGroups.group[v:GetGroup()] = {}
newgroups = newgroups + 1
end
table.insert( PlyGroups.group[v:GetGroup()], v )
end
return newgroups
end
function meta:SetGroup( group )
local g = group
local c = PlyGroups.GetCurrentGroups()
if( type(g) != "string" ) then error("The value you specified is not a string!") return end
self:SetPData( "PlayerGroup", g )
self.Group = g
end
function meta:CreateGroup( group, password )
local g = string.Left(string.sanitise(group), 26)
local p = string.sanitise(password)
local c = PlyGroups.GetCurrentGroups()
------------
if( type(g) != "string" ) then error("The value you specified is not a string!") return end
if not self then error("No player specified.") return end
if not self:IsValid() then Msg("The player specified is no longer valid!") return end
if not self:IsPlayer() then error("That is not a player...") return end
------------
if( table.HasValue( c, g ) ) then
if( self != PlyGroups.group[g].owner ) then
self:SetGroup( g )
end
elseif( #c < PlyGroups.MaxGroups ) then
self:SetGroup( g )
PlyGroups.group[g].owner = self
PlyGroups.group[g].password = p
self:ChatPrint("\n\nNew group \"" .. g .. "\" has been created!")
self:ChatPrint("---|Owner: " .. tostring(PlyGroups.group[g].owner:Nick()))
self:ChatPrint("---|Password: " .. tostring(p) .. "\n\n")
Msg("\nNew group \"" .. g .. "\" has been created!\n")
Msg("\n---|Owner: " .. tostring(PlyGroups.group[g].owner) .. "\n")
Msg("\n---|Password: " .. tostring(p) .. "\n")
PlyGroups.CreateGroupsTable()
else
self:ChatPrint("\n\nCan not create new group. (Limmit Reached.)\n\n")
end
end