--g_factions --Name --Leader --Officers --name --name --name --name --Res --FactionName(used for other things)--g_factions--Real functions--appoint officer--change namefunction createFaction(plyr, factionname) --Object of the Leader-to-Be, Name of the Faction to be --Make sure plyr is valid if (plyr == nil) then g_arena:message('function createFaction(plyr, factioname) was passed a invalid player') return false end --Make sure the leader-to-be isn't the leader of anything else and that another faction of that name doesn't already exsist local leaderOf = '' local isLeader = false local nameTaken = false for i=1, table.getn(g_factions) do if (g_factions[i]['FactionName'] == factionname) then nameTaken = true end if (g_factions[i]['Leader'] == plyr.m_name) then isLeader = true leaderOf = g_factions[i]['FactionName'] end end if (isLeader == true) then plyr:message('You are already the leader of '..leaderOf..' and cannot create another faction') return false end if (nameTaken == true) then plyr:message('That name is already taken and you use that name. Note: Creating a faction with a 60% similiarity to the wone who took this name will get you banned') return false end --pass their name through the purge function to remove their status in other fations. purgeFaction(plyr.m_name) --Create the faction as they have passed the requirements to join it g_player[plyr.m_name]['Faction'] == factionname g_factions[factionname]['FactionName'] = factionname g_factions[factionname]['Leader'] = plyr.m_name g_factions[factionname]['Res'] = 0 plyr:changeteam(factionname, 'adminonly')endfunction purgeFaction(playername) for i=1, table.getn(g_factions) do for o=1, table.getn(g_factions[i]['Officers']) do if (g_factions[i]['Officers'][o] == playername) then g_factions[i]['Officers'][o] = '' end end end for i=1, table.getn(g_players) do if (g_players[i]['Faction'] ~= nil or g_players[i]['Faction'] ~= '') then g_players[i]['Faction'] = '' end endendfunction getStatus(plyr) if (plyr == nil) then g_arena:message('getStatus(plyr) was passed an invalid player object') return false end local factionname = g_player[plyr.m_name]['Faction'] if (g_factions[factionname]['Leader'] = plyr.m_name) then return 'Leader' end for i=1, table.getn(g_factions[factionname]['Officers']) do if (g_factions[factionname]['Officers'][i] == plyr.m_name) then return 'Officer' end end return 'Member'endfunction disbandFaction(plyr) if (plyr == nil) then g_arena:message('disbandFaction(plyr) was passed an invalid player object') return false end if (getStatus(plyr) ~= 'Leader') then plyr:message('You cannot disband this faction because you are not the leader.') return false end local factionname = g_players[plyr.m_name]['Faction'] for i=1, table.getn(g_players) do if (g_players[i]['Faction'] == factionname) then g_players[i]['Faction'] = nil end end g_factions[factionname] = nil plyr:message('Your faction has been disbanded.') local faction = team_fromName(g_arena, factionname) for i=1, faction:num() do local player = faction:get(i) if (player ~= nil) then player:changeTeam(player.m_name, 'adminonly') end endendfunction invite(plyr, newmembername) -- The object of the inviter, the name of the new member in a string. if (plyr == nil) then g_arena:message('function invite(plyr, newmembername) was passed an invalid player object') return false end if (newmembername == '') then g_arena:message('function invite(plyr, newmembername) was passed an invalid new member string') return false end if (getStatus(plyr) ~= 'Leader' or getStatus(plyr) ~= 'Officer') then plyr:message('You do not have the ability to invite new members') return false end local newmember = g_arena:getPlayer(newmembername) if (getStatus(newmember) == 'Leader') then plyr:message('That person is a Leader of another faction and cannot join yours.') return false elseif (getstatus(newmember) == 'Officer') then plyr:message('That person is a officer of another faction and cannot join yours.') return false else g_players[newmembername]['Invites'] = g_players[plyr.m_name]['Faction'] end newmember:message('You have received an invite to join the '..g_players[plyr.m_name]['Faction']..' faction.')endfunction join(plyr) if (plyr == nil) then g_arena:message('function join(plyr) has been passed a invalid player object') return false end if (g_players[plyr.m_name]['Invites'] == nil) then plyr:message('You do not have any Invites.') return false end g_players[plyr.m_name]['Faction'] = g_players[plyr.m_name]['Invites'] g_players[plyr.m_name]['Invites'] = nil plyr:changeTeam(g_players[plyr.m_name]['Faction'], 'adminonly')endfunction makeOfficer(plyr, newofficername) if (plyr == nil) then g_arena:message('makeOfficer(plyr, newofficername) has been passed an invalid player object') return false end if (newofficername == '') then g_arena:message('makeOfficer(plyr, newofficername) has been passed an invalid newoficername string') return false end if (getStatus(plyr) ~= 'Leader') then plyr:message('You do not have the power to appoint officers.') return false end local newofficer = g_arena:getPlayer(newofficername) if (g_players[plyr.m_name]['Faction'] ~= g_players[newofficer.m_name]['Faction']) then plyr:message('That man is not in your faction and therefore you cannot appoint him a officer.') return false end if (getStatus(newofficer) == 'Officer' or getStatus(newofficer) == 'Leader') then plyr:message('This person is already an officer or the leader of your faction.') return false end local faction = g_players[plyr.m_name]['Faction'] table.insert(g_faction[faction]['Officers'], newofficername)endfunction changeFactionName(plyr, newname) if (plyr == nil) then g_arena:message('function changeFactionName(plyr, newname) was passed an invalid player object.') return false end if (newname == '') then g_arena:message('function changeFactionName(plyr, newname) was passed an invalid newname string.') return false end if (getStatus(plyr) ~= 'Leader') then plyr:message('You do not have permission to change your Faction name') return false end local oldname = g_players[plyr.m_name]['Faction'] for i=1, table.getn(g_players) do if (g_players[i]['Faction'] == oldname) then g_players[i]['Faction'] = newname end end for i=1, table.getn(g_factions) do if (g_factions[i]['FactionName'] == oldname) then g_factions[i]['FactionName'] = newname end endend