• Print

Author Topic: Is this a good idea? (Code for grouping people who are on the same team.)  (Read 4202 times)

0 Members and 1 Guest are viewing this topic.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Code: Lua
  1. PlyGroups = {}
  2. PlyGroups.group = {}
  3. local meta = FindMetaTable("Player")
  4.  
  5. function string.sanitise( str )
  6.         return string.Trim(string.Replace(string.Replace(string.Replace( tostring(str), "\\", "/" ), "\"", ""), ";", ""))
  7. end
  8.  
  9. function meta:GetGroup()
  10.         self.Group = self:GetPData( "PlayerGroup", "none" )
  11.         if( not self.Group ) then error("This player is not in a group.") return end
  12.         return self.Group
  13. end
  14.  
  15. function PlyGroups.GetCurrentGroups()
  16.         local oldgroups = {}
  17.         local duplicates = 0
  18.         for k,_ in pairs(PlyGroups.group) do
  19.                 if( table.HasValue(oldgroups, k) ) then
  20.                         PlyGroups.group[k] = nil
  21.                         duplicates = duplicates + 1
  22.                 end
  23.                 table.insert( oldgroups, k )
  24.         end
  25.         print( tostring(duplicates) .. " have been removed." )
  26.         return oldgroups
  27. end
  28.  
  29. function PlyGroups.CreateGroupsTable()
  30.         local newgroups = 0
  31.         for k,v in pairs(player.GetAll()) do
  32.                 if not PlyGroups.group[v:GetGroup()] then
  33.                         PlyGroups.group[v:GetGroup()] = {}
  34.                         newgroups = newgroups + 1
  35.                 end
  36.                 table.insert( PlyGroups.group[v:GetGroup()], v )
  37.         end
  38.         return newgroups
  39. end
  40.  
  41. function meta:SetGroup( group )
  42.         local g = group
  43.         local c = PlyGroups.GetCurrentGroups()
  44.         if( type(g) != "string" ) then error("The value you specified is not a string!") return end
  45.         self:SetPData( "PlayerGroup", g )
  46.         self.Group = g
  47. end
  48.  
  49. function meta:CreateGroup( group, password )
  50.         local g = string.Left(string.sanitise(group), 26)
  51.         local p = string.sanitise(password)
  52.         local c = PlyGroups.GetCurrentGroups()
  53.         ------------
  54.         if( type(g) != "string" ) then error("The value you specified is not a string!") return end
  55.         if not self then error("No player specified.") return end
  56.         if not self:IsValid() then Msg("The player specified is no longer valid!") return end
  57.         if not self:IsPlayer() then error("That is not a player...") return end
  58.         ------------
  59.         if( table.HasValue( c, g ) ) then
  60.                 if( self != PlyGroups.group[g].owner ) then
  61.                         self:SetGroup( g )
  62.                 end
  63.         elseif( #c < PlyGroups.MaxGroups ) then
  64.                 self:SetGroup( g )
  65.                 PlyGroups.group[g].owner = self
  66.                 PlyGroups.group[g].password = p
  67.                 self:ChatPrint("\n\nNew group \"" .. g .. "\" has been created!")
  68.                 self:ChatPrint("---|Owner: " .. tostring(PlyGroups.group[g].owner:Nick()))
  69.                 self:ChatPrint("---|Password: " .. tostring(p) .. "\n\n")
  70.                 Msg("\nNew group \"" .. g .. "\" has been created!\n")
  71.                 Msg("\n---|Owner: " .. tostring(PlyGroups.group[g].owner) .. "\n")
  72.                 Msg("\n---|Password: " .. tostring(p) .. "\n")
  73.                 PlyGroups.CreateGroupsTable()
  74.         else
  75.                 self:ChatPrint("\n\nCan not create new group. (Limmit Reached.)\n\n")
  76.         end
  77. end
  78.  

I started making the above code for DarkRP but then I thought to my self, do we really need group management in DarkRP (separate from  teams, so that a group of gangsters can in a group called "The Vultures", while another cluster of gangsters is called "Night Feather").

---

So long story short, I am not sure if I should finish this code or not,  also ideas would be highly appreciated.

If you have any thoughts or ideas please comment below.
« Last Edit: October 01, 2013, 10:23:27 pm by HeLLFox_15 »
I cry every time I see that I am not a respected member of this community.

Offline iSnipeu

  • Jr. Member
  • **
  • Posts: 83
  • Karma: 12
If it's a big server and you want to have separate gangs then I'd say yeah.

  • Print