Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if SERVER then -- START OF SERVER
- local DefaultMotdInfo = [[
- snip
- ]]
- local DefaultMotw = "Testing new MOTD!"
- local DefaultAdmins = ""
- function CheckForMOTD()
- if !file.Exists( "motd/motw.txt" ) and !file.Exists( "motd/admins.txt" ) and !file.Exists( "motd/rules.txt" ) then
- file.CreateDir( "motd/" )
- end
- if !file.Exists( "motd/motw.txt" ) then
- file.Write( "motd/motw.txt", DefaultMotw )
- end
- if !file.Exists( "motd/admins.txt" ) then
- file.Write( "motd/admins.txt", DefaultAdmins )
- end
- if !file.Exists( "motd/rules.txt" ) then
- file.Write( "motd/rules.txt", DefaultMotdInfo )
- end
- end
- CheckForMOTD()
- local bitsize = 32 -- I'm not sure exactly how much text can be sent alongside pointers so you can toy with this number
- local bits = {}
- function GetMoTD()
- local txt = file.Read("motd/rules.txt")
- bits = {} -- Clears the table in case the function is ran again (loading a new motd)
- while (string.len(txt) > bitsize) do
- local bit = string.sub(txt, 1, bitsize)
- table.insert(bits, bit)
- txt = string.sub(txt, bitsize + 1)
- end
- end
- function GetAdmins()
- local txt = file.Read("motd/admins.txt")
- bits = {} -- Clears the table in case the function is ran again (loading a new motd)
- while (string.len(txt) > bitsize) do
- local bit = string.sub(txt, 1, bitsize)
- table.insert(bits, bit)
- txt = string.sub(txt, bitsize + 1)
- end
- end
- function GetMotw()
- local txt = file.Read("motd/motw.txt")
- bits = {} -- Clears the table in case the function is ran again (loading a new motd)
- while (string.len(txt) > bitsize) do
- local bit = string.sub(txt, 1, bitsize)
- table.insert(bits, bit)
- txt = string.sub(txt, bitsize + 1)
- end
- end
- hook.Add( "PlayerInitialSpawn", "SendPlayerMOTD", function( ply )
- print( ply:Nick() )
- SendRules(ply)
- end )
- function SendRules(pl)
- GetMoTD()
- for k, v in pairs(bits) do
- umsg.Start("RecieveRules", pl)
- umsg.Short(k) -- k ranges from 1 to #bits and is in order because of the while function. It can serve as the pointer
- umsg.Short(#bits) -- Tells the client how many bits are in the entire MoTD so it knows when to stitch them
- umsg.String(v)
- umsg.End()
- end
- SendAdmins(pl)
- end
- function SendAdmins(pl)
- GetAdmins()
- for k, v in pairs(bits) do
- umsg.Start("RecieveAdmins", pl)
- umsg.Short(k) -- k ranges from 1 to #bits and is in order because of the while function. It can serve as the pointer
- umsg.Short(#bits) -- Tells the client how many bits are in the entire MoTD so it knows when to stitch them
- umsg.String(v)
- umsg.End()
- end
- SendMotw(pl)
- end
- function SendMotw(pl)
- GetMotw()
- for k, v in pairs(bits) do
- umsg.Start("RecieveMotw", pl)
- umsg.Short(k) -- k ranges from 1 to #bits and is in order because of the while function. It can serve as the pointer
- umsg.Short(#bits) -- Tells the client how many bits are in the entire MoTD so it knows when to stitch them
- umsg.String(v)
- umsg.End()
- end
- end
- end -- END OF SERVER
- if CLIENT then
- local RulesInfo = ""
- local AdminsInfo = ""
- local MotwInfo = ""
- local Rulesbits = {}
- local Adminsbits = {}
- local Motwbits = {}
- usermessage.Hook( "RecieveRules", function(u)
- local bitnum = u:ReadShort()
- local numbits = u:ReadShort()
- local bit = u:ReadString()
- Rulesbits[bitnum] = bit
- if (#bits == numbits) then -- Stitch the MoTD
- RulesInfo = table.concat(Rulesbits, "")
- end
- end )
- usermessage.Hook( "RecieveAdmins", function(u)
- local bitnum = u:ReadShort()
- local numbits = u:ReadShort()
- local bit = u:ReadString()
- Adminsbits[bitnum] = bit
- if (#bits == numbits) then -- Stitch the MoTD
- AdminsInfo = table.concat(Adminsbits, "")
- end
- end )
- usermessage.Hook( "RecieveMotw", function(u)
- local bitnum = u:ReadShort()
- local numbits = u:ReadShort()
- local bit = u:ReadString()
- Motwbits[bitnum] = bit
- if (#bits == numbits) then -- Stitch the MoTD
- MotwInfo = table.concat(Motwbits, "")
- Welcome()
- end
- end )
- function Welcome()
- MainMenu = vgui.Create( "DFrame" )
- MainMenu:SetPos( 450, 190 )
- MainMenu:SetSize( 360, 455 )
- MainMenu:SetTitle( "MOTD" )
- MainMenu:SetBackgroundBlur( true )
- MainMenu:SetVisible( true )
- MainMenu:SetDraggable( false )
- MainMenu:ShowCloseButton( false )
- MainMenu:MakePopup()
- PropertySheet = vgui.Create( "DPropertySheet")
- PropertySheet:SetParent( MainMenu )
- PropertySheet:SetPos( 5, 30 )
- PropertySheet:SetSize( 350, 340 )
- local DermaButton = vgui.Create( "DButton", DermaPanel )
- DermaButton:SetText( "Agree" )
- DermaButton:SetSize( 165, 75 )
- DermaButton:SetPos( 7, 373 )
- DermaButton:SetParent( MainMenu )
- DermaButton.DoClick = function()
- MainMenu:Close()
- RunConsoleCommand( "say", "I have read and agree with the rules")
- end
- local DermaButton = vgui.Create( "DButton", DermaPanel )
- DermaButton:SetText( "Disagree" )
- DermaButton:SetSize( 165, 75 )
- DermaButton:SetPos( 190, 373 )
- DermaButton:SetParent( MainMenu )
- DermaButton.DoClick = function()
- MainMenu:Close()
- surface.PlaySound( "buttons/button8.wav" )
- RunConsoleCommand( "say", "I disagree with the rules, I will now be disconnected.")
- RunConsoleCommand( "disconnect" )
- end
- local TabOne = vgui.Create( "DPanel" ) --Rules
- TabOne:SetVisible( true )
- local Info = vgui.Create("DLabel", TabOne)
- Info:SetText(
- [[ Welcome to ]] .. GetHostName() .. [[!
- MOTW: ]] .. MotwInfo .. [[
- Rules: ]] .. RulesInfo .. [[
- ]]
- )
- Info:SetTextColor( Color( 0, 0, 0, 255 ) )
- Info:SetPos( 5, 20 )
- Info:SizeToContents( )
- local TabThree = vgui.Create( "DPanel" ) --Donate
- TabThree:SetVisible( true )
- local Info = vgui.Create("DLabel", TabThree)
- Info:SetText( "" )
- Info:SetTextColor( Color( 0, 0, 0, 255 ) )
- Info:SetPos( 5, 20 )
- Info:SizeToContents( )
- local TabTwo = vgui.Create( "DPanel" ) --Admins
- TabTwo:SetVisible( true )
- local Info = vgui.Create("DLabel", TabTwo)
- Info:SetText( AdminsInfo )
- Info:SetTextColor( Color( 0, 0, 0, 255 ) )
- Info:SetPos( 5, 20 )
- Info:SizeToContents( )
- local TabFour = vgui.Create( "DPanel" ) --Events
- TabThree:SetVisible( true )
- local Info = vgui.Create("DLabel", TabFour)
- Info:SetText( [[
- snip
- ]]
- )
- Info:SetTextColor( Color( 0, 0, 0, 255 ) )
- Info:SetPos( 5, 20 )
- Info:SizeToContents( )
- local TabFive = vgui.Create( "DPanel" ) --Servers
- TabThree:SetVisible( true )
- local Info = vgui.Create("DLabel", TabFive)
- Info:SetText( [[
- Servers:
- snip
- ]]
- )
- Info:SetTextColor( Color( 0, 0, 0, 255 ) )
- Info:SetPos( 5, 20 )
- Info:SizeToContents( )
- PropertySheet:AddSheet( "Rules", TabOne, "gui/silkicons/exclamation", false, false, "Rules!" )
- PropertySheet:AddSheet( "Admins", TabTwo, "gui/silkicons/shield", false, false, "Admins!" )
- PropertySheet:AddSheet( "Donate", TabThree, "gui/silkicons/heart", false, false, "Donate!" )
- --PropertySheet:AddSheet( "Events", TabFour, "gui/silkicons/group", false, false, "Events!" )
- PropertySheet:AddSheet( "Servers", TabFive, "gui/silkicons/page_white_wrench", false, false, "Servers!" )
- end
- concommand.Add("OpenMotd", Welcome )
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement