Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local open = false
- local function CreateCoinFlip()
- if open then return end
- open = true
- local enemy = net.ReadEntity()
- local amount = net.ReadFloat()
- local myteam = net.ReadFloat()
- local id = net.ReadFloat()
- local winner = net.ReadFloat()
- net.Start( "CFEndGame" )
- net.WriteFloat( id )
- net.SendToServer()
- print(id)
- local enemyteam = myteam == 1 and 2 or 1
- local CoinFrame = vgui.Create( "DFrame" )
- CoinFrame:SetSize( 680, 330 )
- CoinFrame:Center()
- CoinFrame:SetTitle( "" )
- CoinFrame:ShowCloseButton( false )
- CoinFrame:MakePopup()
- local fliptime = CF.FlipDelay
- local maintext = "Flipping in " .. fliptime
- local finishedtext = false
- local size = 128
- local finished = false
- local num = size
- local teammat = math.random( 1, 2 ) -- Let's randomize that starting coin :)
- local decreasing = true
- local function FlipCoin()
- timer.Simple( math.Rand( CF.FlipMinimum, CF.FlipMax ), function()
- finished = true
- end )
- hook.Add( "Think", "StartFlip", function()
- if num > 0 and decreasing then
- num = num - CF.FlipSpeed
- if num <= 0 then
- decreasing = false
- if teammat == 1 then
- teammat = 2
- else
- teammat = 1
- end
- end
- elseif !decreasing then
- num = num + CF.FlipSpeed
- if num >= size then
- if finished then
- if teammat == winner then
- hook.Remove( "Think", "StartFlip" )
- if winner == myteam then
- net.Start( "CFEndGame" )
- net.WriteFloat( id )
- net.SendToServer()
- end
- if winner == myteam then
- winner = LocalPlayer()
- else
- winner = enemy
- end
- finishedtext = true
- return
- end
- end
- decreasing = true
- end
- end
- end )
- end
- timer.Simple( CF.FlipDelay, function()
- FlipCoin()
- end )
- for i = 1, CF.FlipDelay do
- timer.Simple( i, function()
- maintext = "Flipping in " .. CF.FlipDelay - i
- end )
- end
- CoinFrame.Paint = function( s, w, h )
- surface.BlurPanel( s, 6 )
- draw.RoundedBox( 0, 0, 0, w, h, Color( 0, 0, 0, 220 ) )
- draw.RoundedBox( 0, 0, 0, w, 32, Color( 30, 30, 30 ) )
- draw.SimpleText( "$" .. string.Comma( amount ) .. " Coin Flip with " .. enemy:Nick(), "CoinTitle", w / 2, -1, Color( 255, 255, 255 ), TEXT_ALIGN_CENTER )
- if maintext == "Flipping in 0" then
- maintext = "Flipping..."
- end
- if finishedtext then
- maintext = winner:Nick() .. " has won $" .. string.Comma( amount * 2 ) .. "!"
- end
- draw.SimpleText( maintext, "CoinText", w / 2, 32 + 20, Color( 255, 255, 255 ), TEXT_ALIGN_CENTER )
- draw.SimpleText( LocalPlayer():Nick(), "CoinMain", 20 + 64 + 20, 32 + 64 + 32 + 3, Color( 255, 255, 255 ), TEXT_ALIGN_LEFT )
- draw.SimpleText( enemy:Nick(), "CoinMain", w - 20 - 64 - 20, 32 + 64 + 32 + 3, Color( 255, 255, 255 ), TEXT_ALIGN_RIGHT )
- local mat = Material( CF.Teams[ myteam ][ 2 ] )
- surface.SetMaterial( mat )
- surface.SetDrawColor( Color( 255, 255, 255 ) )
- surface.DrawTexturedRect( 30, h - 64 - 20, 64, 64 )
- local mat = Material( CF.Teams[ enemyteam ][ 2 ] )
- surface.SetMaterial( mat )
- surface.SetDrawColor( Color( 255, 255, 255 ) )
- local s = 76561198089985794
- surface.DrawTexturedRect( w - 64 - 30, h - 64 - 20, 64, 64 )
- local mat = Material( CF.Teams[ teammat ][ 2 ] )
- surface.SetMaterial( mat )
- surface.SetDrawColor( Color( 255, 255, 255 ) )
- surface.DrawTexturedRect( 340 - num / 2, h - 128 - 20, num, size )
- end
- local CoinClose = vgui.Create( "DButton", CoinFrame )
- CoinClose:SetColor( Color( 255, 255, 255 ) )
- CoinClose:SetText( "" )
- CoinClose:SetSize( 32, 32 )
- CoinClose:SetVisible( true )
- CoinClose:SetPos( CoinFrame:GetWide() - CoinClose:GetWide() - 2, 2 )
- CoinClose.DoClick = function()
- CoinFrame:Remove()
- open = false
- end
- CoinClose.Paint = function( s, w, h )
- local col = Color( 255, 255, 255 )
- if s.Hovered then
- col = Color( 255, 25, 25 )
- end
- draw.SimpleText( "x", "CoinClose", w / 2, h / 2 - 6, col, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
- end
- local avatar1 = vgui.Create( "CoinFlipAvatar", CoinFrame )
- avatar1:SetSize( 64, 64 )
- avatar1:SetPos( 30, 32 + 64 + 20 )
- avatar1:SetPlayer( LocalPlayer(), 64 )
- avatar1:SetMaskSize( 64 / 2 )
- avatar1:SetDegree( 360 )
- local avatar2 = vgui.Create( "CoinFlipAvatar", CoinFrame )
- avatar2:SetSize( 64, 64 )
- avatar2:SetPos( CoinFrame:GetWide() - 64 - 30, 32 + 64 + 20 )
- avatar2:SetPlayer( enemy, 64 )
- avatar2:SetMaskSize( 64 / 2 )
- avatar2:SetDegree( 360 )
- if CF.Animation then
- local winneravatar = vgui.Create( "CoinFlipAvatar", CoinFrame )
- winneravatar:SetSize( 128, 128 )
- winneravatar:SetPos( CoinFrame:GetWide() / 2 - 64, CoinFrame:GetTall() - 128 - 20 )
- if winner == myteam then
- winneravatar:SetPlayer( LocalPlayer(), 128 )
- else
- winneravatar:SetPlayer( enemy, 128 )
- end
- winneravatar:SetMaskSize( 128 / 2 )
- winneravatar:SetDegree( 0 )
- local defnum = -350
- hook.Add( "Think", "FadeAvatar", function()
- if finishedtext and CoinFrame and CoinFrame:IsValid() and ispanel( CoinFrame ) then
- defnum = defnum + 2
- if defnum >= 360 then
- defnum = 360
- hook.Remove( "Think", "FadeAvatar" )
- CoinClose:SetVisible( true )
- return
- end
- winneravatar:SetDegree( defnum )
- else
- return
- end
- end )
- end
- end
- net.Receive( "CFNewGame", CreateCoinFlip )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement