faction = { }; // http://pastebin.com/3qKnLSsp // Add factions // Example, name = faction name, ownerID = person who owns faction (add and remove users), allowedTeams = What teams can they play, // userid = too add users manually add their steamID unless you have the team already created and saved, then edit the txt document in data/server faction[1] = { name = "Delta", ownerID = "STEAM_0:0:43447569", allowedTeams = {"Civil Protection", "Delta General", "Delta 1-1", "Delta 1-2", "Delta 1-3"}, usersid = {"", } }; faction[2] = { name = "Taxi", ownerID = "STEAM_0:0:43447569", allowedTeams = {"Taxi Driver"}, usersid = {"", } }; faction[3] = { name = "Engineer", ownerID = "STEAM_0:0:43447569", allowedTeams = {"Engineer"}, usersid = {"", } }; //faction[2] = { name = "Swag", ownerID = "STEAM_0:1:357302", allowedTeams = {"Team 1", "Team 2"}, usersid = {"", } }; // Don't touch code below unless aware of what you are doing.. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // Setup util.AddNetworkString("factionNum") util.AddNetworkString("ControlPanel") util.AddNetworkString("showFactions") util.AddNetworkString( "requestInfo" ) meta = FindMetaTable( "Player" ); function meta:SetupDataTables() self:InstallDataTable(); self:NetworkVar( "Int", 0, "FNumber" ); end function playerJoina(ply) ply:SetupDataTables(); databaseCheck(); end hook.Add( "PlayerInitialSpawn", "playerInitialSpawnaaa", playerJoina ) function factionMain( ply, text ) ply:SetupDataTables(); for s,d in pairs(faction) do local plyr = idToEntity(faction[s].ownerid) if(GetFaction(plyr) == nil) then table.insert(faction[s].usersid, faction[s].ownerid); databaseSave( s ); databaseRead( s ); end end databaseCheck(); plyFaction = ply:GetFNumber(); if( string.sub( text, 1, 9 ) == "!factions") then if(plyFaction != nil and plyFaction != 0) then net.Start( "factionNum" ) net.WriteString( plyFaction ) net.WriteTable(faction[plyFaction]) net.Send(ply); else DarkRP.notify(ply, HUD_PRINTTALK, 5,"You are not in a faction, to join a faction type !factionlist"); end end if( string.sub( text, 1, 12 ) == "!factionlist") then net.Start("showFactions") net.WriteTable(faction); net.Send(ply); end if(plyFaction != nil and plyFaction != 0) then if(string.sub( text, 1, string.len(faction[plyFaction].name) + 1 ) == "!"..string.lower(faction[plyFaction].name)) then ply:setDarkRPVar("job", faction[plyFaction].name) end end -- if( string.sub( text, 1, 5 ) == "!plyt" ) then -- print("BLAH"); -- for k,v in pairs(faction[1].usersid) do -- print("BLAH"); -- ply:PrintMessage(HUD_PRINTTALK, v); -- end -- end -- if( string.sub( text, 1, 5 ) == "!plyy" ) then -- print("BLAH"); -- for k,v in pairs(faction[2].usersid) do -- print("BLAH"); -- ply:PrintMessage(HUD_PRINTTALK, v); -- end -- end -- if( string.sub( text, 1, 2 ) == "!t" ) then -- print("BLAH"); -- RemovePlayer(2, ply:SteamID()) -- AddPlayer(1, ply:SteamID(), ply); -- end -- if( string.sub( text, 1, 2 ) == "!y" ) then -- print("BLAH"); -- RemovePlayer(1, ply:SteamID()) -- AddPlayer(2, ply:SteamID(), ply); -- end end hook.Add("PlayerSay","factiondarkrp",factionMain); function JobChecker(ply, teamc, force) teamc = team.GetName(teamc); local a = ply:GetFNumber() for k,v in pairs(faction) do if(faction[k].allowedteams == nil) then databaseCheck(); end for _,b in pairs(faction[k].allowedteams) do if(teamc == b and a != k) then DarkRP.notify(ply, HUD_PRINTTALK, 5,"You need to be in the "..faction[k].name.." faction, to join this job"); return false; elseif(teamc != b and a == k) then DarkRP.notify(ply, HUD_PRINTTALK, 5,"You are in the "..faction[k].name.." faction, you can only use jobs in that faction"); return false; elseif(teamc == b and a == k) then return true; end end end -- print(teamc); -- if(a == nil and !ply:isArrested()) then -- return true -- else -- for k,v in pairs(faction[a].allowedTeams) do -- if(teamc == v) then -- return true; -- end -- end -- ply:PrintMessage(HUD_PRINTTALK, "You are in the police faction, you can only join police related jobs"); -- return false; -- end DarkRP.notify(ply, HUD_PRINTTALK, 5,"Error Probably"); return true end hook.Add("playerCanChangeTeam","teamchangefaction",JobChecker); net.Receive( "ControlPanel", function( len, ply ) numa = net.ReadString(); command = net.ReadString(); target = net.ReadString(); num = tonumber(net.ReadString()) localply = net.ReadEntity(); //args = net.ReadString(); if(command == "1") then AddPlayer(num, target, localply); factionMain(ply, "!factions") elseif(command == "2") then RemovePlayer(num, target); target = idToEntity(target) target:SetFNumber(0) factionMain(ply, "!factions") elseif(command == "3") then ply:SetFNumber(tonumber(numa)); factionMain(ply, "!factions") elseif(command == "4") then factionMain(ply, "!factionlist"); elseif(command == "5") then factionMain(ply, "!factions"); end databaseSave(num); end ) function GetFaction( ply ) for k,v in pairs(faction) do for a,b in pairs(faction[k].usersid) do if(IsEntity(ply)) then if(faction[k].usersid[a] == ply:SteamID()) then return k; end elseif(ply == "NULL") then if(faction[k].usersid[a] == "NULL") then return k; end end end end end function idToEntity( id ) for k,v in pairs(player.GetAll()) do if( id == "NULL") then -- print("Is Bot") return "NULL"; elseif(v:SteamID() == id) then return v; end end end // function RemovePlayer( num, ply) if(IsEntity(ply)) then ply = ply:SteamID(); end //faction[num].usersid[ply] = nil for k,v in pairs(faction[num].usersid) do if(v == ply || faction[num].usersid[k] == ply) then table.remove(faction[num].usersid, k); end end for g = 0, 100 do if( faction[num].usersid[g] == ply ) then table.remove(faction[num].usersid, g); faction[num].usersid[g] = nil; break; end end end // function databaseExists( num ) local f = file.Exists("server/faction"..num..".txt", "DATA") return f end function databaseCheck() for k,v in pairs(faction) do local f = databaseExists( k ) if f then databaseRead( k ) else databaseSave( k ); end end end function databaseRead(num) if(!databaseExists( num )) then databaseSave(num); else local str = file.Read("server/faction"..num..".txt", "DATA") faction[num] = ( util.KeyValuesToTable(str) ) // end end function databaseSave(num) //if(num == 0 ) then return end; if(num != nil) then local str = util.TableToKeyValues(faction[num]) file.Write("server/faction"..num..".txt", str) else for k,v in pairs(faction) do local str = util.TableToKeyValues(faction[k]) file.Write("server/faction"..k..".txt", str) end end //databaseCheck(); end function AddPlayer( num, ply, localplyr) local plyFac = GetFaction(idToEntity(ply)) if(plyFac == nil ) then table.insert(faction[num].usersid, ply); else localplyr:PrintMessage(HUD_PRINTTALK, "Player is already in "..faction[plyFac].name); end end -- function ShowFactionNames( name ) -- for k,v in pairs(faction) do -- if(faction[k].name == name) then -- for a,b in pairs(faction[k].usersid) do -- print(b); -- end -- end -- end -- end