Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*---------------------------------------------------------------------------
- Character Creation & Selection
- By Derpes, for Resolute Networks
- ---------------------------------------------------------------------------*/
- if(SERVER)then
- util.AddNetworkString("startCharWelcome")
- util.AddNetworkString("char_CreatedFirst")
- util.AddNetworkString("char_Spawned")
- util.AddNetworkString("char_closeF4")
- local charCooldown
- function charScreenF1( ply )
- if(ply.charCooldown)then return end
- if not(IsValid(ply))then
- timer.Simple(1,function()
- if not(IsValid(ply))then return end
- net.Start("startCharWelcome")
- net.WriteTable(TEAMWHITELIST.getAllWhitelists(ply) or {})
- net.Send(ply)
- end)
- else
- ply.charCooldown = true
- net.Start("startCharWelcome")
- net.WriteTable(TEAMWHITELIST.getAllWhitelists(ply) or {})
- net.Send(ply)
- timer.Simple(2,function()
- ply.charCooldown = false
- end)
- end
- end
- hook.Add("ShowHelp", "charScreenF1", charScreenF1)
- concommand.Add("character",charScreenF1)
- net.Receive("char_Spawned",function(len,ply)
- local jobToSpawn = net.ReadUInt(32)
- local modelToSpawn = net.ReadString()
- ply:SetTeam(jobToSpawn)
- ply:setDarkRPVar("job",jobToSpawn)
- ply:StripWeapons()
- ply:Spawn()
- ply:SetModel(modelToSpawn)
- end)
- net.Receive("char_CreatedFirst",function(len,ply)
- local nameToChangeTo = net.ReadString()
- ply:setRPName("CR "..math.random(1000,9999).." "..nameToChangeTo)
- ply:Spawn()
- end)
- elseif(CLIENT)then
- function closeF4ResChar()
- net.Start("char_closeF4")
- net.SendToServer()
- end
- surface.CreateFont("VChar_Title", { font = "bebasneue", size = 40})
- surface.CreateFont("VChar_SubText", { font = "Bebas Neue Book", size = 22,weight=500})
- surface.CreateFont("VChar_ErrText", { font = "Bebas Neue Book", size = 17,weight=500})
- surface.CreateFont("VChar_SubText2", { font = "Bebas Neue Book", size = 22,weight=500,outline=true})
- local charLogo = Material("gmodresolute/scoreboard/banner.png", "unlitgeneric")
- local charBackground = Material("gmodresolute/character/background.png", "unlitgeneric")
- local isOpen = false
- local toModelSend = 0
- local toBecomeSend = 0
- local curIndex = 1
- local skinIndex = 1
- local shownModel = "models/player/clone cadet/clonecadet.mdl"
- local shownRole = "Trainee"
- local shownDesc = "You're a cadet, you need to undergo training in order to join a regiment."
- net.Receive("startCharWelcome",function(ply)
- if(isOpen)then return end
- local jobs_unsanitized = net.ReadTable()
- local hasCreatedBefore = file.Exists("resolute_char.txt","DATA")
- local jobs = {}
- local indexTing = 2
- table.insert(jobs,1,{name="Trainee",model="models/player/clone cadet/clonecadet.mdl",id=1,team=1})
- for k,v in pairs(RPExtraTeams)do
- if(jobs_unsanitized[v.name])then
- table.insert(jobs,indexTing,v)
- indexTing=indexTing+1
- end
- end
- toModelSend=jobs[1].model
- toBecomeSend=jobs[1].team
- toDescSend=jobs[1].description
- curIndex = 1
- skinIndex = 1
- local nameToSend = ""
- local chosenFaction = "Galactic Republic"
- timer.Simple(1,function()
- isOpen = true
- local charFrame = vgui.Create( "DFrame" )
- charFrame:SetPos( 50, 50 )
- charFrame:SetSize( ScrW(), ScrH() )
- charFrame:SetTitle( "" )
- charFrame:SetVisible( true )
- charFrame:Center()
- charFrame:SetDraggable( false )
- charFrame:ShowCloseButton( false )
- charFrame:MakePopup()
- charFrame.Paint = function(s , w , h)
- --Background
- draw.RoundedBox(0,0,0,ScrW(),ScrH(),Color(15,15,15,255))
- surface.SetDrawColor(100,100,100,220)
- surface.SetMaterial( charBackground )
- surface.DrawTexturedRect( 0, 0, ScrW(), ScrH() )
- --Base
- draw.RoundedBox(0,-2,-2,ScrW()+4,ScrH()*0.12+4, Color(0,0,0,255))
- draw.RoundedBox(0,-1,-1,ScrW()+2,ScrH()*0.12+2, Color(80,80,80,255))
- draw.RoundedBox(0,0,0,ScrW(),ScrH()*0.12, Color(35,35,35,255))
- surface.SetDrawColor( 255, 255, 255, 255 )
- surface.SetMaterial( charLogo )
- surface.DrawTexturedRect( ScrW()/2-(ScrW()*0.28/2), 1, ScrW()*0.28, ScrH()*0.12 )
- --Faction Box
- draw.RoundedBox(0,ScrW()/2-150-2, ScrH()/4.05-2-72,304,34,Color(0,0,0,255))
- draw.RoundedBox(0,ScrW()/2-150-1, ScrH()/4.05-1-72,302,32,Color(110,110,110,255))
- draw.RoundedBox(0,ScrW()/2-150+35, ScrH()/4.05-72,230,30,Color(55,55,55,255))
- --Role Box
- draw.RoundedBox(0,ScrW()/2-150-2, ScrH()/4.05-2-36,304,34,Color(0,0,0,255))
- draw.RoundedBox(0,ScrW()/2-150-1, ScrH()/4.05-1-36,302,32,Color(110,110,110,255))
- draw.RoundedBox(0,ScrW()/2-150+35, ScrH()/4.05-36,230,30,Color(55,55,55,255))
- --Name Box
- if(hasCreatedBefore!=true)then
- draw.RoundedBox(0,ScrW()/2-150-2, ScrH()/4.05-2,304,34,Color(0,0,0,255))
- draw.RoundedBox(0,ScrW()/2-150-1, ScrH()/4.05-1,302,32,Color(110,110,110,255))
- draw.RoundedBox(0,ScrW()/2-150, ScrH()/4.05,300,30,Color(55,55,55,255))
- draw.SimpleTextOutlined("Enter your chosen clone name","VChar_SubText",ScrW()/2,ScrH()/4.05+13,Color(255,255,255,255),1,1,1,Color(0,0,0,255))
- end
- end
- local charModel = vgui.Create( "DModelPanel", charFrame )
- charModel:SetPos( ScrW()/2-((ScrW()*0.3)/2)+10,ScrH()/1.65-((ScrH()*0.7)/2) )
- charModel:SetPaintBackgroundEnabled( false )
- charModel:SetSize( ScrW()*0.3, ScrH()*0.7)
- charModel:SetColor( Color(255, 255, 255, 255) )
- charModel:IsDraggable( false )
- charModel:SetModel(shownModel)
- charModel:SetCamPos(Vector(50, 0, 50))
- charModel:SetAnimated( true )
- function charModel.Entity:GetPlayerColor() return Color(255,255,255) end
- function charModel:LayoutEntity( ent )
- self:RunAnimation()
- end
- if(hasCreatedBefore!=true)then
- local charNewName = vgui.Create( "DTextEntry", charFrame )
- charNewName:SetPos( ScrW()/2-152, ScrH()/3.5945 )
- charNewName:SetSize( 304, 30 )
- charNewName:SetFont("VChar_SubText")
- charNewName:SetText( "Enter Clone Name" )
- charNewName.OnEnter = function( self )
- chat.AddText( self:GetValue() )
- end
- charNewName.OnGetFocus = function( self )
- if(self:GetText()=="Enter Clone Name")then
- self:SetText("")
- end
- end
- charNewName.OnLoseFocus = function( self )
- nameToSend = tostring(self:GetValue())
- end
- end
- local charCurrentJob = vgui.Create( "DLabel", charFrame )
- charCurrentJob:SetPos( ScrW()/2, ScrH()/4.7475 )
- charCurrentJob:SetSize(300,30)
- charCurrentJob:SetText(shownRole)
- charCurrentJob:SetFont("VChar_SubText2")
- charCurrentJob:SetContentAlignment(5)
- charCurrentJob:CenterHorizontal(0.5)
- local charCurrentDesc = vgui.Create( "DLabel", charFrame )
- charCurrentDesc:SetPos( ScrW()/1, ScrH()/3.3 )
- charCurrentDesc:SetSize(ScrW()/2,30)
- charCurrentDesc:SetText(shownDesc or "You're a cadet, you need to undergo training in order to join a regiment.")
- charCurrentDesc:SetFont("VChar_SubText2")
- charCurrentDesc:SetContentAlignment(5)
- charCurrentDesc:CenterHorizontal(0.5)
- local charCurrentFaction = vgui.Create( "DLabel", charFrame )
- charCurrentFaction:SetPos( ScrW()/2, ScrH()/4.7475-36 )
- charCurrentFaction:SetSize(300,30)
- charCurrentFaction:SetText( chosenFaction )
- charCurrentFaction:SetFont("VChar_SubText2")
- charCurrentFaction:SetContentAlignment(5)
- charCurrentFaction:CenterHorizontal(0.5)
- local charPrevJob = vgui.Create( "DButton", charFrame )
- charPrevJob:SetText( "<" )
- charPrevJob:SetPos( ScrW()/2-151, ScrH()/4.7915 )
- charPrevJob:SetSize( 36, 32 )
- charPrevJob.DoClick = function()
- if not(hasCreatedBefore)then return end
- curIndex = curIndex - 1
- if curIndex <= 0 then
- curIndex = 1
- end
- charModel:SetModel("")
- if istable(jobs[curIndex].model) then
- charModel:SetModel(jobs[curIndex].model[1])
- else
- charModel:SetModel(jobs[curIndex].model)
- end
- charCurrentJob:SetText("")
- charCurrentJob:SetText(jobs[curIndex].name)
- charCurrentDesc:SetText(jobs[curIndex].description or "You're a cadet, you need to undergo training in order to join a regiment.")
- toBecomeSend = jobs[curIndex].team
- toModelSend = jobs[curIndex].model
- end
- function charPrevJob:Paint()
- if charPrevJob:IsHovered() then
- charPrevJobCol = Color(18,18,18,210)
- else
- charPrevJobCol = Color(5,5,5,170)
- end
- draw.RoundedBox( 0, 0, 0, self:GetWide(), self:GetTall(), Color(0,0,0,160) )
- draw.RoundedBox( 0, 1, 1, self:GetWide()-2, self:GetTall()-2, charPrevJobCol )
- draw.SimpleTextOutlined("<","VChar_SubText",charPrevJob:GetWide()/2, charPrevJob:GetTall()/2-1,Color(255,255,255,255),1,1,1,Color(0,0,0,255))
- end
- local charNextJob = vgui.Create( "DButton", charFrame )
- charNextJob:SetText( ">" )
- charNextJob:SetPos( ScrW()/2+151-36, ScrH()/4.7915 )
- charNextJob:SetSize( 36, 32 )
- charNextJob.DoClick = function()
- if not hasCreatedBefore then return end
- curIndex = curIndex + 1
- if curIndex >= #jobs then
- curIndex = #jobs
- end
- charModel:SetModel("")
- if istable(jobs[curIndex].model) then
- charModel:SetModel(jobs[curIndex].model[1])
- else
- charModel:SetModel(jobs[curIndex].model)
- end
- charCurrentJob:SetText("")
- charCurrentJob:SetText(jobs[curIndex].name)
- charCurrentDesc:SetText(jobs[curIndex].description)
- toBecomeSend = jobs[curIndex].team
- toModelSend = jobs[curIndex].model
- end
- function charNextJob:Paint()
- if charNextJob:IsHovered() then
- charNxtJobCol = Color(18,18,18,210)
- else
- charNxtJobCol = Color(5,5,5,170)
- end
- draw.RoundedBox( 0, 0, 0, self:GetWide(), self:GetTall(), Color(0,0,0,160) )
- draw.RoundedBox( 0, 1, 1, self:GetWide()-2, self:GetTall()-2, charNxtJobCol )
- draw.SimpleTextOutlined(">","VChar_SubText",charNextJob:GetWide()/2, charNextJob:GetTall()/2-1,Color(255,255,255,255),1,1,1,Color(0,0,0,255))
- end
- local charPrevFaction = vgui.Create( "DButton", charFrame )
- charPrevFaction:SetText( "<" )
- charPrevFaction:SetPos( ScrW()/2-151, ScrH()/4.7915-36 )
- charPrevFaction:SetSize( 36, 32 )
- charPrevFaction.DoClick = function()
- charCurrentFaction:SetText("Galactic Republic")
- end
- function charPrevFaction:Paint()
- if charPrevFaction:IsHovered() then
- charPrevFactionCol = Color(18,18,18,210)
- else
- charPrevFactionCol = Color(5,5,5,170)
- end
- draw.RoundedBox( 0, 0, 0, self:GetWide(), self:GetTall(), Color(0,0,0,160) )
- draw.RoundedBox( 0, 1, 1, self:GetWide()-2, self:GetTall()-2, charPrevFactionCol )
- draw.SimpleTextOutlined("<","VChar_SubText",charPrevFaction:GetWide()/2, charPrevFaction:GetTall()/2-1,Color(255,255,255,255),1,1,1,Color(0,0,0,255))
- end
- local charNextFaction = vgui.Create( "DButton", charFrame )
- charNextFaction:SetText( ">" )
- charNextFaction:SetPos( ScrW()/2+151-36, ScrH()/4.7915-36 )
- charNextFaction:SetSize( 36, 32 )
- charNextFaction.DoClick = function()
- charCurrentFaction:SetText("The Seperatists")
- end
- function charNextFaction:Paint()
- if charNextFaction:IsHovered() then
- charNxtFactionCol = Color(18,18,18,210)
- else
- charNxtFactionCol = Color(5,5,5,170)
- end
- draw.RoundedBox( 0, 0, 0, self:GetWide(), self:GetTall(), Color(0,0,0,160) )
- draw.RoundedBox( 0, 1, 1, self:GetWide()-2, self:GetTall()-2, charNxtFactionCol )
- draw.SimpleTextOutlined(">","VChar_SubText",charNextFaction:GetWide()/2, charNextFaction:GetTall()/2-1,Color(255,255,255,255),1,1,1,Color(0,0,0,255))
- end
- local charPrevSkin = vgui.Create( "DButton", charFrame )
- charPrevSkin:SetText( "<" )
- charPrevSkin:SetPos( ScrW()/2-(ScrW()*0.1), ScrH()/2 )
- charPrevSkin:SetSize( 36, 32 )
- charPrevSkin.DoClick = function()
- if(curIndex==nil)then return end
- if(jobs[curIndex].model==nil)then return end
- if istable(jobs[curIndex].model) then
- local skinCount = table.Count(jobs[curIndex].model)
- skinIndex = skinIndex - 1
- if skinIndex < 1 then
- skinIndex = 1
- end
- charModel:SetModel("")
- charModel:SetModel(jobs[curIndex].model[skinIndex])
- toModelSend = jobs[curIndex].model[skinIndex]
- end
- end
- function charPrevSkin:Paint()
- if charPrevSkin:IsHovered() then
- charNxtJobCol = Color(18,18,18,80)
- else
- charNxtJobCol = Color(5,5,5,40)
- end
- draw.RoundedBox( 0, 0, 0, self:GetWide(), self:GetTall(), Color(0,0,0,30) )
- draw.RoundedBox( 0, 1, 1, self:GetWide()-2, self:GetTall()-2, charNxtJobCol )
- draw.SimpleTextOutlined("<","VChar_SubText",charPrevSkin:GetWide()/2, charPrevSkin:GetTall()/2-1,Color(255,255,255,255),1,1,1,Color(0,0,0,255))
- end
- local charNextSkin = vgui.Create( "DButton", charFrame )
- charNextSkin:SetText( ">" )
- charNextSkin:SetPos( ScrW()/2+(ScrW()*0.1), ScrH()/2 )
- charNextSkin:SetSize( 36, 32 )
- charNextSkin.DoClick = function()
- if(curIndex==nil)then return end
- if(jobs[curIndex].model==nil)then return end
- if istable(jobs[curIndex].model) then
- local skinCount = table.Count(jobs[curIndex].model)
- skinIndex = skinIndex + 1
- if skinIndex > skinCount then
- skinIndex = skinCount
- end
- charModel:SetModel("")
- charModel:SetModel(jobs[curIndex].model[skinIndex])
- toModelSend = jobs[curIndex].model[skinIndex]
- end
- end
- function charNextSkin:Paint()
- if charNextSkin:IsHovered() then
- charNxtJobCol = Color(18,18,18,80)
- else
- charNxtJobCol = Color(5,5,5,40)
- end
- draw.RoundedBox( 0, 0, 0, self:GetWide(), self:GetTall(), Color(0,0,0,30) )
- draw.RoundedBox( 0, 1, 1, self:GetWide()-2, self:GetTall()-2, charNxtJobCol )
- draw.SimpleTextOutlined(">","VChar_SubText",charNextSkin:GetWide()/2, charNextSkin:GetTall()/2-1,Color(255,255,255,255),1,1,1,Color(0,0,0,255))
- end
- timer.Simple(0.2,function()
- local charCreateButton = vgui.Create( "DButton", charFrame )
- charCreateButton:SetPos( ScrW()/2-100, ScrH()-70 )
- charCreateButton:SetSize( 200, 30 )
- charCreateButton:SetText( "" )
- function charCreateButton:Paint()
- if charCreateButton:IsHovered() then
- VCharAcceptColor = Color(80,0,0,180)
- else
- VCharAcceptColor = Color(130,0,0,180)
- end
- draw.RoundedBox( 0, 0, 0, self:GetWide(), self:GetTall(), Color(0,0,0,160) )
- draw.RoundedBox( 0, 1, 1, self:GetWide()-2, self:GetTall()-2, VCharAcceptColor )
- if(hasCreatedBefore==true)then
- draw.SimpleTextOutlined("Spawn","VChar_SubText",charCreateButton:GetWide()/2, charCreateButton:GetTall()/2-1,Color(70,255,70,255),1,1,1,Color(0,0,0,255))
- else
- draw.SimpleTextOutlined("Create Character","VChar_SubText",charCreateButton:GetWide()/2, charCreateButton:GetTall()/2-1,Color(70,255,70,255),1,1,1,Color(0,0,0,255))
- end
- end
- function charCreateButton:DoClick()
- if(hasCreatedBefore==true)then
- if(isstring(toModelSend))then
- charFrame:SlideUp(0.15)
- net.Start("char_Spawned")
- net.WriteUInt(toBecomeSend,32)
- net.WriteString(toModelSend)
- net.SendToServer()
- end
- else
- if(string.len(nameToSend)<3)then
- local charLengthError = vgui.Create( "DFrame" )
- charLengthError:SetPos( 50, 50 )
- charLengthError:SetSize( 350, 100 )
- charLengthError:SetTitle( "" )
- charLengthError:SetVisible( true )
- charLengthError:Center()
- charLengthError:SetDraggable( false )
- charLengthError:ShowCloseButton( false )
- charLengthError:MakePopup()
- charLengthError.Paint = function(s,w,h)
- draw.RoundedBox(0,0,0,w,h,Color(30,30,30,255))
- draw.RoundedBox(0,0,0,w,30,Color(150,0,0,255))
- draw.DrawText("Name Error", "VChar_SubText", 5, 2, Color(255, 255, 255, 255), TEXT_ALIGN_LEFT)
- draw.DrawText("Name must be at least 3 characters long", "VChar_SubText", 175, 37, Color(200, 30, 30, 255), TEXT_ALIGN_CENTER)
- end
- local charLengthOk = vgui.Create( "DButton", charLengthError )
- charLengthOk:SetPos( charLengthError:GetWide()/2-50, 65 )
- charLengthOk:SetSize( 100, 30 )
- charLengthOk:SetText( "" )
- function charLengthOk:Paint()
- draw.RoundedBox( 0, 0, 0, self:GetWide(), self:GetTall(), Color( 0, 150, 150, 255 ) )
- draw.DrawText("Understood", "VChar_SubText", self:GetWide()/2, 3, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER)
- end
- function charLengthOk:DoClick()
- charLengthError:Remove()
- end
- return
- end
- shownModel = jobs[1].model
- shownRole = jobs[1].name
- shownDesc = jobs[1].description
- curIndex = 1
- skinIndex = 1
- charModel:SetModel("")
- charFrame:SlideUp(0.15)
- charFrame:Remove()
- if not(file.Exists("resolute_char.txt","DATA"))then
- net.Start("char_CreatedFirst")
- net.WriteString(nameToSend)
- net.SendToServer()
- file.Write( "resolute_char.txt", "Character created on Derpes shitty creation thing!" )
- end
- end
- jobs_unsanitized = {}
- jobs = {}
- isOpen = false
- end
- local charBackButton = vgui.Create( "DButton", charFrame )
- charBackButton:SetPos( ScrW()/2-100, ScrH()-36 )
- charBackButton:SetSize( 200, 30 )
- charBackButton:SetText( "" )
- function charBackButton:Paint()
- if not(hasCreatedBefore)then return end
- if charBackButton:IsHovered() then
- VCharAcceptColor = Color(80,0,0,180)
- else
- VCharAcceptColor = Color(130,0,0,180)
- end
- draw.RoundedBox( 0, 0, 0, self:GetWide(), self:GetTall(), Color(0,0,0,160) )
- draw.RoundedBox( 0, 1, 1, self:GetWide()-2, self:GetTall()-2, VCharAcceptColor )
- draw.SimpleTextOutlined("Return To MOTD","VChar_SubText",charBackButton:GetWide()/2, charBackButton:GetTall()/2-1,Color(223,223,223,255),1,1,1,Color(0,0,0,255))
- end
- function charBackButton:DoClick()
- if not(hasCreatedBefore)then return end
- shownModel = jobs[1].model
- shownRole = jobs[1].name
- shownDesc = jobs[1].description
- curIndex = 1
- skinIndex = 1
- RunConsoleCommand("motd")
- charModel:SetModel("")
- charFrame:SlideUp(0.15)
- charFrame:Remove()
- jobs_unsanitized = {}
- jobs = {}
- isOpen = false
- end
- end)
- end)
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement