From 868e729d68b5913716bfe5ddb512f4099851e9a2 Mon Sep 17 00:00:00 2001 From: Apickx Date: Mon, 28 Dec 2015 19:18:30 -0500 Subject: Initial commit --- gamemode/autolua.lua | 29 ++++++ gamemode/cl_hud/draw.lua | 9 ++ gamemode/cl_hud/draw_battery.lua | 10 ++ gamemode/cl_hud/draw_blockhud.lua | 9 ++ gamemode/cl_hud/draw_chatbox.lua | 136 ++++++++++++++++++++++++++ gamemode/cl_hud/draw_functions.lua | 53 ++++++++++ gamemode/cl_hud/draw_healthbox.lua | 10 ++ gamemode/cl_hud/draw_nametag.lua | 30 ++++++ gamemode/cl_hud/draw_pickup.lua | 4 + gamemode/cl_hud/draw_playercircle.lua | 1 + gamemode/cl_hud/draw_scoreboard.lua | 35 +++++++ gamemode/cl_hud/draw_voicechat.lua | 42 ++++++++ gamemode/cl_hud/vgui/mbbrowser.lua | 43 +++++++++ gamemode/cl_hud/vgui/mbbutton.lua | 66 +++++++++++++ gamemode/cl_hud/vgui/mbframe.lua | 84 ++++++++++++++++ gamemode/cl_hud/vgui/mblabel.lua | 108 +++++++++++++++++++++ gamemode/cl_hud/vgui/mbmodel.lua | 53 ++++++++++ gamemode/cl_hud/vgui/mbpanellist.lua | 67 +++++++++++++ gamemode/cl_hud/vgui/mbtab.lua | 106 ++++++++++++++++++++ gamemode/cl_hud/vgui/mbtree.lua | 92 ++++++++++++++++++ gamemode/cl_hud/vgui/mbuserbrowser.lua | 76 +++++++++++++++ gamemode/cl_init.lua | 17 ++++ gamemode/cl_various/calcview.lua | 172 +++++++++++++++++++++++++++++++++ gamemode/cl_various/colors.lua | 17 ++++ gamemode/cl_various/fonts.lua | 11 +++ gamemode/cl_various/hooks.lua | 14 +++ gamemode/cl_various/input.lua | 27 ++++++ gamemode/cl_various/material.lua | 18 ++++ gamemode/cl_various/motd.lua | 34 +++++++ gamemode/cl_various/paperdoll.lua | 27 ++++++ gamemode/cl_various/rendersunflare.lua | 62 ++++++++++++ gamemode/init.lua | 47 +++++++++ gamemode/sh_var/globalshvar.lua | 53 ++++++++++ gamemode/sh_var/shvar.lua | 84 ++++++++++++++++ gamemode/sh_various/hooks.lua | 14 +++ gamemode/sh_various/math_ext.lua | 57 +++++++++++ gamemode/sh_various/note.lua | 62 ++++++++++++ gamemode/sh_various/perlins_noise.lua | 2 + gamemode/shared.lua | 23 +++++ gamemode/sv_various/globalsettings.lua | 20 ++++ gamemode/sv_various/hooks.lua | 29 ++++++ gamemode/sv_various/mysql.lua | 38 ++++++++ gamemode/sv_various/resource.lua | 6 ++ 43 files changed, 1897 insertions(+) create mode 100644 gamemode/autolua.lua create mode 100644 gamemode/cl_hud/draw.lua create mode 100644 gamemode/cl_hud/draw_battery.lua create mode 100644 gamemode/cl_hud/draw_blockhud.lua create mode 100644 gamemode/cl_hud/draw_chatbox.lua create mode 100644 gamemode/cl_hud/draw_functions.lua create mode 100644 gamemode/cl_hud/draw_healthbox.lua create mode 100644 gamemode/cl_hud/draw_nametag.lua create mode 100644 gamemode/cl_hud/draw_pickup.lua create mode 100644 gamemode/cl_hud/draw_playercircle.lua create mode 100644 gamemode/cl_hud/draw_scoreboard.lua create mode 100644 gamemode/cl_hud/draw_voicechat.lua create mode 100644 gamemode/cl_hud/vgui/mbbrowser.lua create mode 100644 gamemode/cl_hud/vgui/mbbutton.lua create mode 100644 gamemode/cl_hud/vgui/mbframe.lua create mode 100644 gamemode/cl_hud/vgui/mblabel.lua create mode 100644 gamemode/cl_hud/vgui/mbmodel.lua create mode 100644 gamemode/cl_hud/vgui/mbpanellist.lua create mode 100644 gamemode/cl_hud/vgui/mbtab.lua create mode 100644 gamemode/cl_hud/vgui/mbtree.lua create mode 100644 gamemode/cl_hud/vgui/mbuserbrowser.lua create mode 100644 gamemode/cl_init.lua create mode 100644 gamemode/cl_various/calcview.lua create mode 100644 gamemode/cl_various/colors.lua create mode 100644 gamemode/cl_various/fonts.lua create mode 100644 gamemode/cl_various/hooks.lua create mode 100644 gamemode/cl_various/input.lua create mode 100644 gamemode/cl_various/material.lua create mode 100644 gamemode/cl_various/motd.lua create mode 100644 gamemode/cl_various/paperdoll.lua create mode 100644 gamemode/cl_various/rendersunflare.lua create mode 100644 gamemode/init.lua create mode 100644 gamemode/sh_var/globalshvar.lua create mode 100644 gamemode/sh_var/shvar.lua create mode 100644 gamemode/sh_various/hooks.lua create mode 100644 gamemode/sh_various/math_ext.lua create mode 100644 gamemode/sh_various/note.lua create mode 100644 gamemode/sh_various/perlins_noise.lua create mode 100644 gamemode/shared.lua create mode 100644 gamemode/sv_various/globalsettings.lua create mode 100644 gamemode/sv_various/hooks.lua create mode 100644 gamemode/sv_various/mysql.lua create mode 100644 gamemode/sv_various/resource.lua (limited to 'gamemode') diff --git a/gamemode/autolua.lua b/gamemode/autolua.lua new file mode 100644 index 0000000..373a36d --- /dev/null +++ b/gamemode/autolua.lua @@ -0,0 +1,29 @@ + +function AddLuaCSFolder(DIR) + local Dir = GM.Folder:gsub("gamemodes/","").."/gamemode/" + local GAMEFIL = file.Find(Dir..DIR.."/*.lua","LUA") + + for k,v in pairs( GAMEFIL ) do + if (CLIENT) then include(Dir..DIR.."/"..v) + else AddCSLuaFile(Dir..DIR.."/"..v) end + end +end + +function AddLuaSVFolder(DIR) + local Dir = GM.Folder:gsub("gamemodes/","").."/gamemode/" + local GAMEFIL = file.Find(Dir..DIR.."/*.lua","LUA") + + for k,v in pairs( GAMEFIL ) do + if (SERVER) then include(Dir..DIR.."/"..v) end + end +end + +function AddLuaSHFolder(DIR) + local Dir = GM.Folder:gsub("gamemodes/","").."/gamemode/" + local GAMEFIL = file.Find(Dir..DIR.."/*.lua","LUA") + + for k,v in pairs( GAMEFIL ) do + if (SERVER) then AddCSLuaFile(Dir..DIR.."/"..v) end + include(Dir..DIR.."/"..v) + end +end diff --git a/gamemode/cl_hud/draw.lua b/gamemode/cl_hud/draw.lua new file mode 100644 index 0000000..86faaf6 --- /dev/null +++ b/gamemode/cl_hud/draw.lua @@ -0,0 +1,9 @@ + +function GM:HUDPaint() + DrawRect( 0, 0, ScrW(), 20, MAIN_COLOR ) + DrawText( GM.Name, "Trebuchet18", 5, 0, MAIN_TEXTCOLOR ) + + DrawHealthbar() + DrawBatteryLife() +end + diff --git a/gamemode/cl_hud/draw_battery.lua b/gamemode/cl_hud/draw_battery.lua new file mode 100644 index 0000000..b2ba854 --- /dev/null +++ b/gamemode/cl_hud/draw_battery.lua @@ -0,0 +1,10 @@ +local X = ScrW()-104 + +function DrawBatteryLife() + local W = system.BatteryPower() + if (W > 100) then return end + + DrawRect(X,4,100,12,MAIN_BLACKCOLOR) + DrawRect(X,4,math.Clamp(W,0,100),12,MAIN_GREENCOLOR) + DrawText("Battery: "..W.."%","Trebuchet18",X-5,2,MAIN_TEXTCOLOR,2) +end \ No newline at end of file diff --git a/gamemode/cl_hud/draw_blockhud.lua b/gamemode/cl_hud/draw_blockhud.lua new file mode 100644 index 0000000..9aa4994 --- /dev/null +++ b/gamemode/cl_hud/draw_blockhud.lua @@ -0,0 +1,9 @@ +local Blocks = {} + +function GM:AddBlockCHud(Str) + if (!table.HasValue(Blocks,Str)) then table.insert(Blocks,Str) end +end + +hook.Add( "HUDShouldDraw", "ShouldDraw", function( name ) + if (table.HasValue(Blocks,name)) then return false end +end) \ No newline at end of file diff --git a/gamemode/cl_hud/draw_chatbox.lua b/gamemode/cl_hud/draw_chatbox.lua new file mode 100644 index 0000000..07e9d26 --- /dev/null +++ b/gamemode/cl_hud/draw_chatbox.lua @@ -0,0 +1,136 @@ +local MChatTab = {} +local TextCol = Color(255,255,255,255) +local TextCol2 = Color(200,50,50,255) +local TextCol3 = Color(160,200,240,255) +local x = 20 +local y = ScrH() - 300 +local d = {} +CHAT_PAN = nil + +hook.Add("Initialize","ChatboxSpawn",function() + CHAT_PAN = vgui.Create("MBFrame") + CHAT_PAN:SetPos(x,y) + CHAT_PAN:SetSize(400,200) + CHAT_PAN:SetTitle("ChatBawx") + CHAT_PAN:SetVisible(false) + CHAT_PAN:ShowCloseButton(false) + + CHAT_TEXT = vgui.Create("MBPanelList") + CHAT_TEXT:SetPos( x+5,y+25 ) + CHAT_TEXT:SetSize( 390, 150 ) + CHAT_TEXT:SetSpacing( 1 ) + CHAT_TEXT:EnableHorizontal( false ) + CHAT_TEXT:EnableVerticalScrollbar( true ) + CHAT_TEXT:SetLimit(30) + CHAT_TEXT:SetMouseInputEnabled(false) + + CHAT_PAN.Typer = vgui.Create("DTextEntry",CHAT_PAN) + CHAT_PAN.Typer:SetPos(5,175) + CHAT_PAN.Typer:SetSize(370,20) + CHAT_PAN.Typer:SetText("Say: ") +end) + +function GM:SetEnableMawChat(bool) + self.UseMawChat = bool + + if (!bool) then CHAT_PAN:SetVisible(false) CHAT_TEXT:SetVisible(false) + else CHAT_TEXT:SetVisible(true) end +end + +function GM:StartChat() + if (!self.UseMawChat) then return false end + if (!CHAT_PAN) then return end + + CHAT_TEXT:SetMouseInputEnabled(true) + CHAT_PAN:SetVisible(true) + return true +end + +function GM:FinishChat() + if (!self.UseMawChat) then return end + if (!CHAT_PAN) then return end + + CHAT_TEXT:SetMouseInputEnabled(false) + CHAT_PAN:SetVisible(false) +end + +function GM:ChatTextChanged(text) + if (!self.UseMawChat) then return end + if (!CHAT_PAN) then return end + + CHAT_PAN.Typer:SetText("Say: "..text) +end + +function IsChatOpen() + return (CHAT_PAN and CHAT_PAN:IsVisible()) +end + +local function GenerateText(tab) + if (type(tab):lower() != "table") then return end + + local a = vgui.Create("MBLabel") + a:SetSize(CHAT_TEXT:GetWide()-5,1) + + for k,v in pairs(tab) do a:AddText(v[1],v[2],v[3]) end + + a:SetupLines() --You need to call this AFTER adding the text... + + CHAT_TEXT:AddItem(a) + CHAT_TEXT:InvalidateLayout(true) + CHAT_TEXT:AddVScroll(40) +end + +function GM:OnPlayerChat( pl , text , teamtext , dead ) + if (!self.UseMawChat) then return end + if (!IsValid(pl)) then return end --This function is now getting called when console talks.. odd... + + local dat = { + { + "", + "MBChatFont_Tag", + MAIN_GREENCOLOR, + }, + { + pl:Nick()..": ", + "MBChatFont", + MAIN_YELLOWCOLOR, + }, + { + text, + "MBChatFont", + TextCol, + }, + } + + if (text:lower() == ":awesome:") then pl.FaceTime = CurTime()+20 end + if (text:lower() == "/clearchat" and pl == LocalPlayer()) then CHAT_TEXT:Clear(true) CHAT_TEXT:InvalidateLayout() return end + + if (teamtext) then dat[1][1] = "(Team)" + elseif (dead) then dat[1][1] = "(Dead)" dat[1][3] = TextCol2 + elseif (pl:IsAdmin()) then dat[1][1] = "(Admin)" dat[1][3] = TextCol2 + else table.remove(dat,1) end + + chat.AddText(MAIN_YELLOWCOLOR,pl:Nick()..": ",TextCol,text) + GenerateText(dat) +end + +function GM:ChatText( int , name , text ) + if (!self.UseMawChat) then return end + if (int == 0) then + local dat = { + { + "God: ", + "MBChatFont", + TextCol3, + }, + { + text, + "MBChatFont", + TextCol, + }, + } + + chat.AddText(MAIN_COLOR,"Game: ",TextCol,text) + GenerateText(dat) + end +end \ No newline at end of file diff --git a/gamemode/cl_hud/draw_functions.lua b/gamemode/cl_hud/draw_functions.lua new file mode 100644 index 0000000..6ad625d --- /dev/null +++ b/gamemode/cl_hud/draw_functions.lua @@ -0,0 +1,53 @@ + +local Grad = surface.GetTextureID("gui/gradient") + +function DrawBoxy(x,y,w,h,color) + draw.RoundedBox( 8, x, y, w, h, color ) +end + +function DrawText(text,font,x,y,color,bCentered) + draw.SimpleText( text, font, x, y, color, bCentered or 0, bCentered or 0 ) +end + +function DrawRect(x,y,w,h,color) + surface.SetDrawColor( color.r, color.g, color.b, color.a ) + surface.DrawRect( x, y, w, h ) +end + +function DrawOutlinedRect(x,y,w,h,color) + surface.SetDrawColor( color.r, color.g, color.b, color.a ) + surface.DrawOutlinedRect( x, y, w, h ) +end + +function DrawLeftGradient(x,y,w,h,color) + DrawTexturedRect(x,y,w,h,color,Grad) +end + +function DrawTexturedRect(x,y,w,h,color,texture) + surface.SetTexture( texture ) + surface.SetDrawColor( color.r, color.g, color.b, color.a ) + surface.DrawTexturedRect( x, y, w, h ) +end + +function DrawTexturedRectRotated(x,y,w,h,color,texture,rot) + surface.SetTexture( texture ) + surface.SetDrawColor( color.r, color.g, color.b, color.a ) + surface.DrawTexturedRectRotated( x, y, w, h, rot ) +end + +function DrawMaterialRect(x,y,w,h,color,material) + surface.SetMaterial( material ) + surface.SetDrawColor( color.r, color.g, color.b, color.a ) + surface.DrawTexturedRect( x, y, w, h ) +end + +function DrawMaterialRectRotated(x,y,w,h,color,material,rot) + surface.SetMaterial( material ) + surface.SetDrawColor( color.r, color.g, color.b, color.a ) + surface.DrawTexturedRectRotated( x, y, w, h, rot ) +end + +function DrawLine(x,y,x2,y2,color) + surface.SetDrawColor( color.r, color.g, color.b, color.a ) + surface.DrawLine( x, y, x2, y2 ) +end \ No newline at end of file diff --git a/gamemode/cl_hud/draw_healthbox.lua b/gamemode/cl_hud/draw_healthbox.lua new file mode 100644 index 0000000..0801181 --- /dev/null +++ b/gamemode/cl_hud/draw_healthbox.lua @@ -0,0 +1,10 @@ +function DrawHealthbar() + local HP = LocalPlayer():Health() + local MP = 100 --player:GetMaxHealth() apparently doesn't work quite well on Clients... + local C = math.Clamp(HP/MP,0,1) + + DrawBoxy( 10, ScrH()-60, 200, 50, MAIN_COLOR ) + DrawRect( 20, ScrH()-50, 180, 30, MAIN_BLACKCOLOR ) + DrawRect( 20, ScrH()-50, 180*C, 30, MAIN_GREENCOLOR ) + DrawText( HP.."/"..MP, "Trebuchet24", 110, ScrH()-35, MAIN_TEXTCOLOR, 1 ) +end \ No newline at end of file diff --git a/gamemode/cl_hud/draw_nametag.lua b/gamemode/cl_hud/draw_nametag.lua new file mode 100644 index 0000000..a15b69f --- /dev/null +++ b/gamemode/cl_hud/draw_nametag.lua @@ -0,0 +1,30 @@ + +local UpVec = Vector(0,0,80) +local C = MAIN_TEXTCOLOR +local EnaTa = true + +function GM:SetEnableMawNameTag(bool) + EnaTa = bool +end + +hook.Add("HUDPaint","DrawingNames",function() + if (!EnaTa) then hook.Remove("HUDPaint","DrawingNames") return end + + for k,pl in pairs( player.GetAll() ) do + if (LocalPlayer() != pl) then + local Dis = pl:GetPos():Distance(LocalPlayer():GetPos()) + + if (Dis < 800) then + local spos = (pl:GetPos()+UpVec):ToScreen() + local Alpha = math.Clamp(Dis/800,0,1) + local A = C.a*1 + + C.a = A-A*Alpha + + DrawText( pl:Nick(), "MBPlayerNameFont", spos.x, spos.y, C, 1 ) + + C.a = A + end + end + end +end) \ No newline at end of file diff --git a/gamemode/cl_hud/draw_pickup.lua b/gamemode/cl_hud/draw_pickup.lua new file mode 100644 index 0000000..ec2a96e --- /dev/null +++ b/gamemode/cl_hud/draw_pickup.lua @@ -0,0 +1,4 @@ + + +function GM:HUDWeaponPickedUp( W ) +end \ No newline at end of file diff --git a/gamemode/cl_hud/draw_playercircle.lua b/gamemode/cl_hud/draw_playercircle.lua new file mode 100644 index 0000000..68498aa --- /dev/null +++ b/gamemode/cl_hud/draw_playercircle.lua @@ -0,0 +1 @@ +local CIRCLE = surface.GetTextureID("SGM/playercircle") local CIROFF = Vector(0,0,1) local CIROF2 = Vector(0,0,10) local CIRDOW = Vector(0,0,150) local CIRANG = Angle(0,0,0) local CIRENA = true local CIRCOL = MAIN_COLOR function GM:SetEnableMawCircle(bool) CIRENA = bool end function GM:SetMawCircleTexture(TexID) CIRCLE = TexID end function GM:SetMawCircleColor(Col) CIRCOL = Col end hook.Add("PostPlayerDraw","DrawingPlayerCircle",function(pl) if (!CIRENA) then return end local p = pl:GetPos() local t = { start = p+CIROF2, endpos = p-CIRDOW, filter = pl, mask = MASK_SOLID_BRUSHONLY, } t = util.TraceLine(t) local B = CIRCOL.a*1 CIRCOL.a = math.Clamp(140-p:Distance(t.HitPos),0,250) if (t.Hit) then cam.Start3D2D(t.HitPos+CIROFF,CIRANG,0.2) DrawTexturedRect( -100, -100, 200, 200, CIRCOL, CIRCLE) cam.End3D2D() end CIRCOL.a = B end) \ No newline at end of file diff --git a/gamemode/cl_hud/draw_scoreboard.lua b/gamemode/cl_hud/draw_scoreboard.lua new file mode 100644 index 0000000..1d1da16 --- /dev/null +++ b/gamemode/cl_hud/draw_scoreboard.lua @@ -0,0 +1,35 @@ +local SCOREBOARD_FADE = Color(20,20,20,70) + +local SCOREBOARD_OFF = 101 +local SCOREBOARD_WIDTH = 700 +local SCOREBOARD_X = ScrW() / 2 - SCOREBOARD_WIDTH / 2 + +function GM:ScoreboardShow() + self.ShowSB = true +end + +function GM:ScoreboardHide() + self.ShowSB = false +end + +function GM:HUDDrawScoreBoard() + if (!self.ShowSB) then return end + + local NPly = #player.GetAll() + local Tall = SCOREBOARD_OFF + 20 * NPly + 20 + local y = ScrH() / 2 - Tall / 2 + local by = y + SCOREBOARD_OFF + + DrawBoxy(SCOREBOARD_X, y, SCOREBOARD_WIDTH, Tall, MAIN_COLOR) + DrawRect(SCOREBOARD_X, by, SCOREBOARD_WIDTH, NPly*20, MAIN_COLORD) + + DrawText(self.Name, "ScoreboardFont", SCOREBOARD_X + 20, y + 20, MAIN_TEXTCOLOR) + + for k,v in pairs( player.GetAll() ) do + local Y = by + 20 * (k-1) + + DrawText(v:Nick(), "Trebuchet18", SCOREBOARD_X + 2, Y, MAIN_TEXTCOLOR) + DrawText(v:Ping(), "Trebuchet18", SCOREBOARD_X + SCOREBOARD_WIDTH - 30, Y, MAIN_TEXTCOLOR) + end +end + diff --git a/gamemode/cl_hud/draw_voicechat.lua b/gamemode/cl_hud/draw_voicechat.lua new file mode 100644 index 0000000..b087eb9 --- /dev/null +++ b/gamemode/cl_hud/draw_voicechat.lua @@ -0,0 +1,42 @@ +local VoiceMat = surface.GetTextureID("voice/speaker4") +local VoiceEna = true +local VOCOL = table.Copy(MAIN_COLOR) + +function GM:PlayerStartVoice( ply ) + if (!VoiceEna) then self.BaseClass:PlayerStartVoice( ply ) return end + ply.Talking = true +end + +function GM:PlayerEndVoice( ply ) + if (!VoiceEna) then self.BaseClass:PlayerEndVoice( ply ) return end + ply.Talking = nil +end + +function GM:SetEnableMawVoiceHUD(bool) + VoiceEna = bool +end + +hook.Add("HUDPaint","_VoiceChatDraw",function() + if (!VoiceEna) then return end + + local D = 0 + + for k,v in pairs( player.GetAll() ) do + if (v.Talking) then + local H = 30 + 30*D + D = D+1 + + local V = v:VoiceVolume() + local D = MAIN_COLOR + + VOCOL.r = math.Clamp(D.r-100*V,0,255) + VOCOL.g = math.Clamp(D.g+200*V,0,255) + VOCOL.b = math.Clamp(D.b-100*V,0,255) + + DrawRect( 0, H, 200, 25, VOCOL ) + + DrawTexturedRect( 180, H+4, 16, 16, MAIN_TEXTCOLOR, VoiceMat ) + DrawText( v:Nick(), "Trebuchet18", 4, H+3, MAIN_TEXTCOLOR ) + end + end +end) \ No newline at end of file diff --git a/gamemode/cl_hud/vgui/mbbrowser.lua b/gamemode/cl_hud/vgui/mbbrowser.lua new file mode 100644 index 0000000..738c8ed --- /dev/null +++ b/gamemode/cl_hud/vgui/mbbrowser.lua @@ -0,0 +1,43 @@ +local PANEL = {} + +function PANEL:Init() + self.bgcol = MAIN_COLOR + self.fgcol = MAIN_COLOR2 + + self.HTML = vgui.Create( "HTML" , self ) + self.HTML:OpenURL("www.google.com") + self.HTML.StatusChanged = function( s , str ) self.Status = str end + + self.Status = "Ready." + + self:SetPaintBackgroundEnabled( false ) + self:SetPaintBorderEnabled( false ) +end + +function PANEL:OpenURL(url) + self.HTML:OpenURL(url) +end + +function PANEL:SetFGColor( col ) + self.fgcol = col +end + +function PANEL:SetBGColor( col ) + self.bgcol = col +end + +function PANEL:Paint(w,h) + DrawBoxy( 0 , 0 , w , h , self.bgcol ) + DrawLine( 0 , 20 , w , 20 , self.fgcol ) + + DrawText( self.Status , "Trebuchet18" , 5 , self:GetTall()-20 , MAIN_WHITECOLOR ) + + return true +end + +function PANEL:PerformLayout() + self.HTML:SetPos(1,22) + self.HTML:SetSize(self:GetWide()-2,self:GetTall()-44) +end + +vgui.Register( "MBBrowser", PANEL , "MBFrame" ) \ No newline at end of file diff --git a/gamemode/cl_hud/vgui/mbbutton.lua b/gamemode/cl_hud/vgui/mbbutton.lua new file mode 100644 index 0000000..a5c0363 --- /dev/null +++ b/gamemode/cl_hud/vgui/mbbutton.lua @@ -0,0 +1,66 @@ +local PANEL = {} + +function PANEL:Init() + self.Hover = false + self.Pressed = false + self.Text = "No-Title Button" + self.ClickSound = "buttons/lightswitch2.wav" + self.ClickEnable = true + + self.HoverSound = "common/bugreporter_succeeded.wav" + self.HoverEnable = false + + + self:SetText("") + self.SetText = function(s,txt) self.Text = txt end +end + +function PANEL:OnCursorEntered() + self.Hover = true + if (self.HoverEnable) then surface.PlaySound(self.HoverSound) end +end + +function PANEL:EnableHoverSound(bool) + self.HoverEnable = bool +end + +function PANEL:SetHoverSound(sound) + self.HoverSound = sound +end + +function PANEL:EnableClickSound(bool) + self.ClickEnable = bool +end + +function PANEL:SetClickSound(sound) + self.ClickSound = sound +end + +function PANEL:OnMousePressed() + self.Pressed = true + self:MouseCapture( true ) +end + +function PANEL:OnMouseReleased() + if (self.Pressed) then surface.PlaySound(self.ClickSound) self:DoClick() end + + self.Pressed = false + self:MouseCapture( false ) +end + +function PANEL:OnCursorExited() + self.Hover = false +end + +function PANEL:Paint(w,h) + if (self.Pressed) then DrawRect( 0 , 0 , w , h , MAIN_GREENCOLOR ) + elseif (self.Hover) then DrawRect( 0 , 0 , w , h , MAIN_COLOR2 ) + else DrawRect( 0 , 0 , w , h , MAIN_COLORD ) end + + DrawText( self.Text, "Trebuchet18", w/2, h/2, MAIN_TEXTCOLOR, 1 ) +end + +function PANEL:PerformLayout() +end + +vgui.Register( "MBButton", PANEL , "Button" ) \ No newline at end of file diff --git a/gamemode/cl_hud/vgui/mbframe.lua b/gamemode/cl_hud/vgui/mbframe.lua new file mode 100644 index 0000000..ab99fd7 --- /dev/null +++ b/gamemode/cl_hud/vgui/mbframe.lua @@ -0,0 +1,84 @@ +local PANEL = {} +local Close = surface.GetTextureID("gearfox/vgui/close") + +function PANEL:Init() + self.bgcol = MAIN_COLOR + self.fgcol = MAIN_COLOR2 + + self.Font = "Trebuchet18" + self.Text = "No-Title MBFrame" + self.TextCol = MAIN_TEXTCOLOR + self.BrigCol = MAIN_WHITECOLOR + self.CloseRem = false + self.ShowClose = true + + self:SetPaintBackgroundEnabled( false ) + self:SetPaintBorderEnabled( false ) +end + +function PANEL:OnClose() +end + +function PANEL:SetDeleteOnClose( bool ) + self.CloseRem = bool +end + +function PANEL:SetTitle( name ) + self.Text = name +end + +function PANEL:SetFGColor( col ) + self.fgcol = col +end + +function PANEL:SetBGColor( col ) + self.bgcol = col +end + +function PANEL:SetTextColor( col ) + self.TextCol = col +end + +function PANEL:SetTextFont( font ) + self.Font = font +end + +function PANEL:ShowCloseButton( bool ) + self.ShowClose = bool +end + +function PANEL:OnMousePressed() + if (!self.ShowClose) then return end + + local x,y = self:LocalToScreen( self:GetWide()-17 , 3 ) + + if (input.IsMouseInBox( x , y , 14 , 14 )) then + self:OnClose() + + if (self.CloseRem) then self:Remove() + else self:SetVisible(false) end + end +end + +function PANEL:Paint(w,h) + DrawBoxy( 0 , 0 , w , h , self.bgcol ) + DrawLine( 0 , 20 , w , 20 , self.fgcol ) +end + +function PANEL:PaintOver(w,h) + DrawText( self.Text , self.Font , 2 , 2 , self.TextCol ) + + if (self.ShowClose) then + local x,y = self:GetPos() + + if (input.IsMouseInBox(x+w-17 , y+3 , 14 , 14)) then DrawTexturedRect( w-17 , 3 , 14 , 14 , self.BrigCol , Close ) + else DrawTexturedRect( w-17 , 3 , 14 , 14 , self.TextCol , Close ) end + end + + return true +end + +function PANEL:PerformLayout() +end + +vgui.Register( "MBFrame", PANEL, "EditablePanel" ) \ No newline at end of file diff --git a/gamemode/cl_hud/vgui/mblabel.lua b/gamemode/cl_hud/vgui/mblabel.lua new file mode 100644 index 0000000..1f1e3bb --- /dev/null +++ b/gamemode/cl_hud/vgui/mblabel.lua @@ -0,0 +1,108 @@ +local PANEL = {} + +function PANEL:Init() + self.Lines = {} + self.Texts = {} + + self.LineHeight = 20 +end + +function PANEL:AddText(text,font,color) + if (!font) then font = "Trebuchet18" end + if (!color) then color = MAIN_TEXTCOLOR end + + text = " "..text + + table.insert(self.Texts,{text,font,color,}) +end + +function PANEL:ClearText() + self.Lines = {} + self.Texts = {} +end + +function PANEL:SetupLines() + local w = 0 + local dat = {} + local Tal = 20 + + for k,v in pairs( self.Texts ) do + surface.SetFont(v[2]) + local a,b = surface.GetTextSize(v[1]) + + if (b > Tal) then Tal = b end + + if (w+a > self:GetWide()) then + local Exp = string.Explode(" ",v[1]) + local Dat = "" + local Tab = {} + local wi = 0 + + for p,d in pairs( Exp ) do + local si,so = surface.GetTextSize(" "..d) + + wi = wi + si + + if (w+wi < self:GetWide()) then + Dat = Dat.." "..d + else + table.insert(dat,{Dat,v[2],v[3],}) + table.insert(self.Lines,dat) + + dat = {} + Dat = " "..d + wi = 0 + w = 0 + end + end + + table.insert(dat,{Dat,v[2],v[3],}) + else + w = w + a + table.insert(dat,v) + end + end + + table.insert(self.Lines,dat) + + Tal = Tal*#self.Lines + self:SetTall(Tal) + + self.Texts = nil --Since this function is called to setup a wrapped text, we no longer need the table with shit on. +end + +function PANEL:SetTextColor( col ) +end + +function PANEL:SetTextFont( font ) +end + +function PANEL:Paint() + if (self.Lines) then + for k,v in pairs(self.Lines) do + local w = 0 + for c,j in pairs(v) do + local Text = j[1] + local Font = j[2] + local Col = j[3] + + surface.SetFont(Font) + + local wid,hei = surface.GetTextSize(Text) + + surface.SetTextColor(Col) + surface.SetTextPos(w,self.LineHeight*(k-1)) + surface.DrawText(Text) + + w = w+wid + end + end + end + + return true +end + +function PANEL:PerformLayout() +end + +vgui.Register( "MBLabel", PANEL , "DLabel" ) \ No newline at end of file diff --git a/gamemode/cl_hud/vgui/mbmodel.lua b/gamemode/cl_hud/vgui/mbmodel.lua new file mode 100644 index 0000000..373c98a --- /dev/null +++ b/gamemode/cl_hud/vgui/mbmodel.lua @@ -0,0 +1,53 @@ +local PANEL = {} +local Zero = Vector(0,0,0) +local One = Vector(1,1,1) + +function PANEL:Init() + self.bgcol = MAIN_COLOR2 + + self.Model = vgui.Create( "DModelPanel" , self ) + self.Model:SetCamPos( Vector( 30, 30, 30 ) ) + self.Model:SetLookAt( Zero ) + self.Model:SetSize( self:GetWide() , self:GetTall() ) + self.Model:SetPos( 0 , 0 ) + + self.Model.DoRightClick = function(s) self:DoRightClick() end + self.Model.DoClick = function(s) self:DoLeftClick() end +end + +function PANEL:DoRightClick() +end + +function PANEL:DoLeftClick() +end + +function PANEL:SetModel( name , Texture ) + self.Model:SetModel( name ) + + local MSize,SSize = self.Model.Entity:GetRenderBounds() + SSize = SSize:Length() + + self.Model:SetCamPos( One * SSize ) + self.Model:SetLookAt( Zero ) + + if (Texture) then self.Model.Entity:SetMaterial(Texture) end +end + +function PANEL:GetModel() + return self.Model.Entity:GetModel() +end + +function PANEL:SetBGColor( col ) + self.bgcol = col +end + +function PANEL:Paint(w,h) + DrawRect( 0 , 0 , w , h , self.bgcol ) +end + +function PANEL:PerformLayout() + self.Model:SetSize( self:GetWide() , self:GetTall() ) + self.Model:SetPos( 0 , 0 ) +end + +vgui.Register( "MBModel", PANEL , "Panel" ) \ No newline at end of file diff --git a/gamemode/cl_hud/vgui/mbpanellist.lua b/gamemode/cl_hud/vgui/mbpanellist.lua new file mode 100644 index 0000000..3e9666a --- /dev/null +++ b/gamemode/cl_hud/vgui/mbpanellist.lua @@ -0,0 +1,67 @@ +local PANEL = {} + +function PANEL:Init() + self.bgcol = MAIN_COLORD + self.Limit = 100 + + self:SetPadding( 1 ) + self:SetSpacing( 1 ) + self:SetAutoSize(false) + self:EnableHorizontal( false ) + self:EnableVerticalScrollbar( true ) + self.VBar.Paint = function(s) end + self.VBar.btnGrip.Paint = function(s,w,h) DrawRect( 2 , 0 , w-4 , h , self.bgcol ) end + self.VBar.btnDown.Paint = function(s,w,h) DrawRect( 2 , 2 , w-4 , h-4 , self.bgcol ) end + self.VBar.btnUp.Paint = function(s,w,h) DrawRect( 2 , 2 , w-4 , h-4 , self.bgcol ) end + + self.Delta = 0 + self.Smooth = 0 +end + +function PANEL:OnMouseWheeled(Delta) + self.Delta = self.Delta+Delta +end + +function PANEL:SetVScroll(num) + self.VBar:SetScroll(num) +end + +function PANEL:AddVScroll(num) + self.VBar:AddScroll(num) +end + +function PANEL:SetFGColor( col ) + self.fgcol = col +end + +function PANEL:SetLimit(l) + self.Limit = l +end + +function PANEL:RemoveItem( item ) + for k, v in pairs( self.Items ) do + if ( v == item ) then + table.remove(self.Items,k) + v:Remove() + + self:InvalidateLayout() + break + end + end +end + +function PANEL:Think() + local It = self:GetItems() + if (#It > self.Limit) then self:RemoveItem(It[#It-self.Limit]) end + + if (self.Delta > 0.01 or self.Delta < -0.01 or self.Smooth > 0.01 or self.Smooth < -0.01) then + self.Delta = self.Delta - self.Delta/8 + self.Smooth = self.Smooth + (self.Delta-self.Smooth)/32 + self:AddVScroll(-self.Smooth/2) + end +end + +function PANEL:Paint() +end + +vgui.Register( "MBPanelList", PANEL , "DPanelList" ) \ No newline at end of file diff --git a/gamemode/cl_hud/vgui/mbtab.lua b/gamemode/cl_hud/vgui/mbtab.lua new file mode 100644 index 0000000..3899f69 --- /dev/null +++ b/gamemode/cl_hud/vgui/mbtab.lua @@ -0,0 +1,106 @@ +local PANEL = {} + +function PANEL:Init() + self.bgcol = MAIN_COLOR + self.fgcol = MAIN_COLOR2 + + self.TabsBut = {} + self.Tabs = {} + self.TabSel = "" + self.VertTabs = false + + self.Slide = 0 +end + +function PANEL:OnClose() +end + +function PANEL:SetVerticalTabs( bool ) + self.VertTabs = bool +end + +function PANEL:SetTitle( name ) +end + +function PANEL:SetFGColor( col ) + self.fgcol = col +end + +function PANEL:SetBGColor( col ) + self.bgcol = col +end + +function PANEL:AddTab(Text) + local A = vgui.Create("MBFrame",self) + A:SetTitle("") + A:SetVisible(false) + A:ShowCloseButton(false) + A:SetPos(0,20) + A:SetSize(self:GetWide(),self:GetTall()-25) + A.Paint = function(s,w,h) DrawRect(0,0,w,h,self.bgcol) end + + local D = vgui.Create("MBButton",self) + D:SetText(Text) + D.T = #self.TabsBut*1 + + if (D.T < 1) then A:SetVisible(true) self.TabSel = D.T end + + D.Paint = function(s,w,h) + if (self.TabSel == s.T) then DrawRect(0,0,w,h,self.bgcol) + else DrawRect(0,0,w,h,self.fgcol) end + + DrawText( s.Text, "Trebuchet18", w/2, h/2, MAIN_TEXTCOLOR, 1 ) + end + + D.DoClick = function() + for k,v in pairs(self.Tabs) do + v:SetVisible(false) + end + + self.Tabs[D.T]:SetVisible(true) + self.TabSel = D.T + end + + table.insert(self.TabsBut,D) + self.Tabs[D.T] = A + + return self.Tabs[D.T] +end + + +function PANEL:Paint() + return true +end + +function PANEL:Think() + local Num = #self.TabsBut + local W = self:GetWide() + local SW = 100*Num + local X,Y = self:LocalToScreen() + + if (SW > self:GetWide()) then + if (input.IsMouseInBox(X,Y,20,20) and self.Slide > 0) then + self.Slide = self.Slide-1 + + self:PerformLayout() + elseif (input.IsMouseInBox(X+W-20,Y,20,20) and self.Slide < SW-W) then + self.Slide = self.Slide+1 + + self:PerformLayout() + end + end +end + +function PANEL:PerformLayout() + for k,v in pairs(self.TabsBut) do + v:SetPos(100*(k-1)-self.Slide,0) + v:SetSize(97,20) + end + + if (self.Tabs[self.TabSel]) then + self.Tabs[self.TabSel]:SetPos(0,20) + self.Tabs[self.TabSel]:SetSize(self:GetWide(),self:GetTall()-25) + end +end + +vgui.Register( "MBTab", PANEL ) \ No newline at end of file diff --git a/gamemode/cl_hud/vgui/mbtree.lua b/gamemode/cl_hud/vgui/mbtree.lua new file mode 100644 index 0000000..e2be877 --- /dev/null +++ b/gamemode/cl_hud/vgui/mbtree.lua @@ -0,0 +1,92 @@ +local PANEL = {} + +function PANEL:Init() + self.bgcol = MAIN_COLOR2 + self.hovercol = MAIN_COLORD + self.foldecol = MAIN_COLORD2 + self.selecCol = MAIN_GREENCOLOR + + self.VBar.Paint = function(s) end + self.VBar.btnGrip.Paint = function(s) DrawRect( 2 , 0 , s:GetWide()-4 , s:GetTall() , self.bgcol ) end + self.VBar.btnDown.Paint = function(s) DrawRect( 2 , 2 , s:GetWide()-4 , s:GetTall()-4 , self.bgcol ) end + self.VBar.btnUp.Paint = function(s) DrawRect( 2 , 2 , s:GetWide()-4 , s:GetTall()-4 , self.bgcol ) end + + self.Delta = 0 + self.Smooth = 0 + self.BGEnabled = true +end + +function PANEL:OnMouseWheeled(Delta) + self.Delta = self.Delta+Delta +end + +function PANEL:SetVScroll(num) + self.VBar:SetScroll(num) +end + +function PANEL:AddVScroll(num) + self.VBar:AddScroll(num) +end + +function PANEL:SetBGColor( col ) + self.bgcol = col +end + +function PANEL:EnableNodeBG( bool ) + self.BGEnabled = bool +end + +function PANEL:AddNode( text ) + local V = self.BaseClass.AddNode( self, text ) + + V.BGEnabled = self.BGEnabled + + V.FolCol = self.foldecol + V.HovCol = self.hovercol + V.SelCol = self.selecCol + V.OAddNode = V.AddNode + + V.Label:SetFont("Trebuchet18") + V.Label.Paint = function(s,w,h) + if (V:HasChildren() and V.BGEnabled) then DrawRect( 0 , 1 , w , h-2 , V.FolCol ) + elseif (!V:HasChildren() and self:GetSelectedItem()==V) then DrawRect( 0 , 1 , w , h-2 , V.SelCol ) + elseif (V.Hovered) then DrawRect( 0 , 1 , w , h-2 , V.HovCol ) end + end + + V.AddNode = function(s,txt) + local D = s.OAddNode(s,txt) + + D.FolCol = s.FolCol + D.HovCol = s.HovCol + D.SelCol = s.SelCol + D.BGEnabled = s.BGEnabled + + D.Label:SetFont("Trebuchet18") + + D.Label.Paint = function(p,w,h) + if (D:HasChildren() and D.BGEnabled) then DrawRect( 0 , 1 , w , h-2 , D.FolCol ) + elseif (!D:HasChildren() and self:GetSelectedItem()==D) then DrawRect( 0 , 1 , w , h-2 , D.SelCol ) + elseif (D.Hovered) then DrawRect( 0 , 1 , w , h-2 , D.HovCol ) end + end + + D.OAddNode = D.AddNode + D.AddNode = s.AddNode + + return D + end + + return V +end + +function PANEL:Think() + if (self.Delta > 0.01 or self.Delta < -0.01 or self.Smooth > 0.01 or self.Smooth < -0.01) then + self.Delta = self.Delta - self.Delta/8 + self.Smooth = self.Smooth + (self.Delta-self.Smooth)/32 + self:AddVScroll(-self.Smooth/2) + end +end + +function PANEL:Paint() +end + +vgui.Register( "MBTree", PANEL , "DTree" ) \ No newline at end of file diff --git a/gamemode/cl_hud/vgui/mbuserbrowser.lua b/gamemode/cl_hud/vgui/mbuserbrowser.lua new file mode 100644 index 0000000..8249662 --- /dev/null +++ b/gamemode/cl_hud/vgui/mbuserbrowser.lua @@ -0,0 +1,76 @@ +local PANEL = {} + +function PANEL:Init() + self.bgcol = MAIN_COLOR + self.fgcol = MAIN_COLOR2 + + self:SetTitle( "UserBrowser" ) + + self.HTML = vgui.Create( "HTML" , self ) + self.HTML:OpenURL( "www.google.com" ) + + self.HTML.StatusChanged = function( s , str ) self.Status = str end + self.HTML.PageTitleChanged = function( s , title ) self:SetTitle(title) end + self.HTML.FinishedURL = function( s , url ) self.URLBar:SetText(url) end + + self.Status = "Ready." + + self.BackB = vgui.Create( "MBButton" , self ) + self.BackB:SetText("<") + self.BackB:EnableHoverSound(false) + self.BackB.DoClick = function() self.HTML:HTMLBack() end + + self.RefreshB = vgui.Create( "MBButton" , self ) + self.RefreshB:SetText("Refresh") + self.RefreshB:EnableHoverSound(false) + self.RefreshB.DoClick = function() self.HTML:Refresh() end + + self.ForwardB = vgui.Create( "MBButton" , self ) + self.ForwardB:SetText(">") + self.ForwardB:EnableHoverSound(false) + self.ForwardB.DoClick = function() self.HTML:HTMLForward() end + + self.URLBar = vgui.Create( "DTextEntry" , self ) + self.URLBar:SetText("www.google.com") + self.URLBar.OnEnter = function(s) self.HTML:OpenURL(s:GetValue()) end +end + +function PANEL:OpenURL(url) + self.HTML:OpenURL(url) +end + +function PANEL:SetFGColor( col ) + self.fgcol = col +end + +function PANEL:SetBGColor( col ) + self.bgcol = col +end + +function PANEL:Paint(w,h) + DrawBoxy( 0 , 0 , w , h , self.bgcol ) + DrawLine( 0 , 20 , w , 20 , self.fgcol ) + + DrawText( self.Status , "Trebuchet18" , 5 , h-20 , MAIN_WHITECOLOR ) + + return true +end + +function PANEL:PerformLayout() + self.HTML:SetPos(1,42) + self.HTML:SetSize(self:GetWide()-2,self:GetTall()-64) + + self.BackB:SetPos(10,22) + self.BackB:SetSize(20,20) + + self.RefreshB:SetPos(60,22) + self.RefreshB:SetSize(80,20) + + self.ForwardB:SetPos(35,22) + self.ForwardB:SetSize(20,20) + + self.URLBar:SetPos(145,22) + self.URLBar:SetSize(self:GetWide()-150,20) +end + +vgui.Register( "MBUserBrowser", PANEL , "MBFrame" ) \ No newline at end of file diff --git a/gamemode/cl_init.lua b/gamemode/cl_init.lua new file mode 100644 index 0000000..abfaee7 --- /dev/null +++ b/gamemode/cl_init.lua @@ -0,0 +1,17 @@ + +include( "shared.lua" ) + +GM.UseMawChat = true +GM.UseMawBlockCHud = true +GM.UseMawSun = false + +function GM:Initialize() +end + +function GM:ShouldDrawLocalPlayer() + return (!IsFirstPerson()) +end + +function GM:CallScreenClickHook() +end + diff --git a/gamemode/cl_various/calcview.lua b/gamemode/cl_various/calcview.lua new file mode 100644 index 0000000..2530025 --- /dev/null +++ b/gamemode/cl_various/calcview.lua @@ -0,0 +1,172 @@ + +local Camdist = 60 --Dont change this +local Camcdist = 60 --Dont change this +local CamMin = 20 +local CamMax = 200 +local Campos = Vector( 0 , 0 , 0 ) +local Aimpos = Vector( 0 , 0 , 0 ) +local AimVect = Vector( 0 , 0 , 0 ) +local RPos = Campos +local CamEnt = NULL +local DefDCam = nil +local EnabledFT = true +local CamZNear = 1 +local CamZFar = nil +local CamKey = KEY_C +local CamHeight = 0 +local NewFunc = nil + +--I was wondering if I should use the vgui functions or the bindpress. The advantage is that the vgui one works even when your mouse is out. +--However, it might get annoying when you are trying to scroll a scrollbar. ;P +vgui.GetWorldPanel():SetWorldClicker(false) + +hook.Add("PlayerBindPress","CameraScroll",function(ply,bind,pressed) + self = GM or GAMEMODE + + if (EnabledFT and (!CamKey or input.IsKeyDown(CamKey))) then + if (bind == "invnext") then + self:AddCameraDistance(10) + return true + end + + if (bind == "invprev") then + self:AddCameraDistance(-10) + return true + end + end +end) + +function GM:SetCameraKey(KEY) + CamKey = KEY +end + +function GM:SetCameraDistance(dist) + if (dist > CamMax) then dist = CamMax end + if (dist < CamMin) then dist = CamMin end + + if (Camdist != dist and LocalPlayer():Alive()) then + if (dist == CamMin) then OnCameraModeSwitch(true) + elseif (Camdist == CamMin) then OnCameraModeSwitch(false) end + end + + Camdist = dist +end + +function GM:AddCameraDistance(add) + local dist = Camdist + add + if (dist > CamMax) then dist = CamMax end + if (dist < CamMin) then dist = CamMin end + + if (Camdist != dist and LocalPlayer():Alive()) then + if (dist == CamMin) then self:OnCameraModeSwitch(true) + elseif (Camdist == CamMin) then self:OnCameraModeSwitch(false) end + end + + Camdist = dist +end + +function GM:SetEnableThirdPerson(bool) + EnabledFT = bool +end + +function IsFirstPerson() + return (Camdist <= CamMin or !EnabledFT) +end + +function GM:OnCameraModeSwitch(bFirstPerson) +end + +function GetCameraPos() + return RPos +end + +function SetCameraObject(Ent) + CamEnt = Ent +end + +function SetDefaultDeathPos(Pos) + DefDCam = Pos +end + +function SetCameraMinDistance(Dist) + CamMin = Dist +end + +function SetCameraMaxDistance(Dist) + CamMax = Dist +end + +function SetCameraZNear(Near) + CamZNear = Near +end + +function SetCameraZFar(Far) + CamZFar = Far +end + +function SetCameraOffsetHeight(H) + CamHeight=H +end + +function OverrideDefaultGFCamera(Fun) + NewFunc = Fun +end + +hook.Add("CalcView","View",function(ply, origin, angles, fov) + if (NewFunc) then + local Cal = NewFunc(ply, origin, angles, fov) + + if (Cal) then return Cal end + end + + local view = {} + + AimPos = ply:GetAimVector() + AimVect = AimVect + (AimPos-AimVect)/2 + + view.znear = CamZNear + view.zfar = CamZFar + + view.origin = origin + + if (!ply:Alive()) then + if (DefDCam) then origin = DefDCam end + + view.origin = origin + AimPos * -80 + RPos = view.origin + return view + end + + if (!EnabledFT) then return view end + + if (Camdist > CamMin or IsValid(CamEnt)) then + Camcdist = Camcdist + (Camdist-Camcdist)/16 + local Distance = Camcdist + + Campos = ply:GetShootPos() + Campos.z = Campos.z + + if (IsValid(CamEnt)) then Campos = CamEnt:GetPos() end + + local Aimer = AimVect + local data = {} + + data.start = Campos + data.endpos = Campos - Aimer * Distance + data.filter = ply + data.mask = MASK_SOLID_BRUSHONLY + data.mins = ply:OBBMaxs()/3*-1 + data.maxs = ply:OBBMaxs()/3 + + local trace = util.TraceHull( data ) + + view.origin = trace.HitPos + view.angles = Aimer:Angle() + end + + view.origin.z = view.origin.z + CamHeight + + RPos = view.origin or origin + + return view +end) \ No newline at end of file diff --git a/gamemode/cl_various/colors.lua b/gamemode/cl_various/colors.lua new file mode 100644 index 0000000..07f2965 --- /dev/null +++ b/gamemode/cl_various/colors.lua @@ -0,0 +1,17 @@ +//Global Colors! + +MAIN_COLORD2 = Color( 40, 55, 70, 200 ) +MAIN_COLORD = Color( 40, 55, 70, 100 ) +MAIN_COLOR = Color( 60, 90, 120, 200 ) +MAIN_COLOR2 = Color( 80, 130, 180, 200 ) +MAIN_TEXTCOLOR = Color( 200, 200, 200, 250 ) +MAIN_BLACKCOLOR = Color( 20, 20, 20, 250 ) +MAIN_NOCOLOR = Color( 0, 0, 0, 0 ) +MAIN_GREENCOLOR = Color( 100, 200, 100, 200 ) +MAIN_YELLOWCOLOR = Color( 250, 250, 50, 200 ) +MAIN_REDCOLOR = Color( 250, 50, 50, 250 ) +MAIN_BLUECOLOR = Color( 50, 50, 250, 250 ) +MAIN_WHITECOLOR = Color( 255, 255, 255, 255 ) +MAIN_GREYCOLOR = Color( 155, 155, 155, 255 ) +MAIN_WHITECOLORT = Color( 255, 255, 255, 100 ) + diff --git a/gamemode/cl_various/fonts.lua b/gamemode/cl_various/fonts.lua new file mode 100644 index 0000000..ba62ff5 --- /dev/null +++ b/gamemode/cl_various/fonts.lua @@ -0,0 +1,11 @@ +//Fonts + +surface.CreateFont( "ScoreboardFont", {size = 64, weight = 400, font = "coolvetica"} ) +surface.CreateFont( "MBDefaultFont", {size = 16, weight = 500} ) +surface.CreateFont( "MBDefaultFontMedium", {size = 24, weight = 500} ) +surface.CreateFont( "MBDefaultFontLarge", {size = 32, weight = 500} ) +surface.CreateFont( "MBDefaultFontVeryLarge", {size = 48, weight = 500} ) +surface.CreateFont( "MBDefaultFontSuperLarge", {size = 64, weight = 500} ) +surface.CreateFont( "MBChatFont", {size = 16, weight = 900, shadow = true} ) +surface.CreateFont( "MBChatFont_Tag", {size = 18, weight = 700, antialias = false, font = "Akbar", shadow = true} ) +surface.CreateFont( "MBPlayerNameFont", {size = 30, weight = 900, shadow = true} ) \ No newline at end of file diff --git a/gamemode/cl_various/hooks.lua b/gamemode/cl_various/hooks.lua new file mode 100644 index 0000000..636025c --- /dev/null +++ b/gamemode/cl_various/hooks.lua @@ -0,0 +1,14 @@ + + +hook.Add("Initialize","GearFoxInit",function() + self = GM or GAMEMODE + + if (self.UseMawBlockCHud) then + self:AddBlockCHud("CHudWeaponSelection") + self:AddBlockCHud("CHudHealth") + self:AddBlockCHud("CHudBattery") + self:AddBlockCHud("CHudDamageIndicator") + self:AddBlockCHud("CHudAmmo") + self:AddBlockCHud("CHudSecondaryAmmo") + end +end) diff --git a/gamemode/cl_various/input.lua b/gamemode/cl_various/input.lua new file mode 100644 index 0000000..519dbaf --- /dev/null +++ b/gamemode/cl_various/input.lua @@ -0,0 +1,27 @@ +local B = {} +local A = {} + +function input.IsMouseInBox( x , y , w , h ) + local mx, my = gui.MousePos() + return (mx > x and mx < x+w and my > y and my < y+h) +end + +function input.IsInBox( x2 , y2 , x , y , w , h ) + return (x2 > x and x2 < x+w and y2 > y and y2 < y+h) +end + +function input.KeyPress(KEY,ID) + ID = ID or "" + if (input.IsKeyDown(KEY) and !IsChatOpen()) then + if (!A[KEY..ID]) then A[KEY..ID] = true return true + else return false end + elseif (A[KEY..ID]) then A[KEY..ID] = false end +end + +function input.MousePress(MOUSE,ID) + ID = ID or "" + if (input.IsMouseDown(MOUSE)) then + if (!B[MOUSE..ID]) then B[MOUSE..ID] = true return true + else return false end + elseif (B[MOUSE..ID]) then B[MOUSE..ID] = false end +end diff --git a/gamemode/cl_various/material.lua b/gamemode/cl_various/material.lua new file mode 100644 index 0000000..bd48612 --- /dev/null +++ b/gamemode/cl_various/material.lua @@ -0,0 +1,18 @@ + +local SourceSkyname = GetConVar("sv_skyname"):GetString() --We need the source of the maps original skybox texture so we can manipulate it. +local SourceSkyPre = {"lf","ft","rt","bk","dn","up",} +local SourceSkyMat = { + Material("skybox/"..SourceSkyname.."lf"), + Material("skybox/"..SourceSkyname.."ft"), + Material("skybox/"..SourceSkyname.."rt"), + Material("skybox/"..SourceSkyname.."bk"), + Material("skybox/"..SourceSkyname.."dn"), + Material("skybox/"..SourceSkyname.."up"), +} + +function ChangeSkybox(skyboxname) + for i = 1,6 do + local D = Material("skybox/"..skyboxname..SourceSkyPre[i]):GetTexture("$basetexture") + SourceSkyMat[i]:SetTexture("$basetexture",D) + end +end \ No newline at end of file diff --git a/gamemode/cl_various/motd.lua b/gamemode/cl_various/motd.lua new file mode 100644 index 0000000..7602c30 --- /dev/null +++ b/gamemode/cl_various/motd.lua @@ -0,0 +1,34 @@ + +local MOTD_URL = "www.google.com" --Change URL here. +local MOTD_ENABLE = true + +function GM:SetMOTD(url) + MOTD_URL = url +end + +function GM:EnableMOTD(boolean) + MOTD_ENABLE = boolean +end + +function GM:ReloadMOTD() + if (!MOTD_ENABLE) then return end + + if (GM.MOTD) then + GM.MOTD:OpenURL(MOTD_URL) + GM.MOTD:SetVisible(true) + end +end + + +hook.Add("InitPostEntity","GearFox_MOTD",function() + if (!MOTD_ENABLE) then return end + + GM = GM or GAMEMODE + + GM.MOTD = vgui.Create("MBBrowser") + GM.MOTD:SetTitle("Message of the Day") + GM.MOTD:SetPos(100,100) + GM.MOTD:SetSize(ScrW()-200,ScrH()-200) + GM.MOTD:OpenURL(MOTD_URL) + GM.MOTD:MakePopup() +end) \ No newline at end of file diff --git a/gamemode/cl_various/paperdoll.lua b/gamemode/cl_various/paperdoll.lua new file mode 100644 index 0000000..4bc9841 --- /dev/null +++ b/gamemode/cl_various/paperdoll.lua @@ -0,0 +1,27 @@ +local meta = FindMetaTable("Player") + +function meta:AttachModel(ID,BoneID,offpos,offang,scale,Model) + if (!self._AM) then self._AM = {} end + if (self._AM[ID] and IsValid(self._AM[ID].CEnt)) then self._AM[ID].CEnt:Remove() end + + self._AM[ID] = {CEnt = ClientsideModel(Model), BID = BoneID,} + self._AM[ID].CEnt:SetModelScale(scale) + self._AM[ID].CEnt:FollowBone(self,BoneID) + self._AM[ID].CEnt:SetLocalPos(offpos) + self._AM[ID].CEnt:SetLocalAngles(offang) +end + +function meta:DetachModel(ID) + if (!self._AM) then return end + if (self._AM[ID] and IsValid(self._AM[ID].CEnt)) then self._AM[ID].CEnt:Remove() end + self._AM[ID] = nil +end + +function meta:GetModelByID(ID) + if (!self._AM) then return NULL end + return self._AM[ID] +end + +function meta:GetModels() + return self._AM or {} +end diff --git a/gamemode/cl_various/rendersunflare.lua b/gamemode/cl_various/rendersunflare.lua new file mode 100644 index 0000000..0383639 --- /dev/null +++ b/gamemode/cl_various/rendersunflare.lua @@ -0,0 +1,62 @@ + +local SunFlares = { + surface.GetTextureID("mawbase/sunflares/flare1"), + surface.GetTextureID("mawbase/sunflares/flare2"), + surface.GetTextureID("mawbase/sunflares/s1"), + surface.GetTextureID("mawbase/sunflares/s2"), + surface.GetTextureID("mawbase/sunflares/s3"), + surface.GetTextureID("mawbase/sunflares/s4"), +} + +local SunGlow = surface.GetTextureID("sun/overlay") + +MAIN_MAWSUNCOLOR = Color(255,255,255,255) + +hook.Add("HUDPaint","RenderMawSunflare",function() + GM = GM or GAMEMODE + if (!GM.UseMawSun) then return end + + local Sun = GM:GetGlobalSHVar("SunPos") + + if (type(Sun):lower() != "vector") then return end + + local LPo = GetCameraPos() + local SPos = LPo+Sun + local T = { + start = LPo, + endpos = LPo+(Sun:GetNormal()*10000), + filter = LocalPlayer(), + } + + T = util.TraceLine(T) + + if (T.Hit and !T.HitSky) then return end + + local Pos = SPos:ToScreen() + local Dot = math.Clamp((LocalPlayer():GetAimVector():DotProduct( (SPos - LPo):GetNormal() )-0.5)*2,0,1) + + if (Dot <= 0) then return end + + local Size = 400+100*Dot + + local Cx = ScrW()/2 + local Cy = ScrH()/2 + + local Gx = Pos.x-Cx + local Gy = Pos.y-Cy + + local Col = MAIN_MAWSUNCOLOR + Col.a = 250*Dot + + DrawTexturedRectRotated(Pos.x,Pos.y,Size*0.6,Size*0.6,Col,SunFlares[1],0) + DrawTexturedRectRotated(Pos.x,Pos.y,Size,Size,Col,SunFlares[2],0) + + DrawTexturedRectRotated(Cx,Cy,64,64,Col,SunFlares[5],0) + DrawTexturedRectRotated(Cx+Gx*0.5,Cy+Gy*0.5,140,140,Col,SunFlares[6],0) + DrawTexturedRectRotated(Cx+Gx*0.2,Cy+Gy*0.2,50,50,Col,SunFlares[5],0) + DrawTexturedRectRotated(Cx+Gx*0.30,Cy+Gy*0.30,53,53,Col,SunFlares[5],0) + DrawTexturedRectRotated(Cx+Gx*0.25,Cy+Gy*0.25,90,90,Col,SunFlares[6],0) + DrawTexturedRectRotated(Cx-Gx*0.12,Cy-Gy*0.12,90,90,Col,SunFlares[4],0) + DrawTexturedRectRotated(Cx-Gx*0.2,Cy-Gy*0.2,210,210,Col,SunFlares[3],0) + +end) \ No newline at end of file diff --git a/gamemode/init.lua b/gamemode/init.lua new file mode 100644 index 0000000..1e2e506 --- /dev/null +++ b/gamemode/init.lua @@ -0,0 +1,47 @@ + +AddCSLuaFile( "autolua.lua" ) +AddCSLuaFile( "cl_init.lua" ) +AddCSLuaFile( "shared.lua" ) + +include( "shared.lua" ) + +function GM:Initialize() +end + +function GM:PlayerInitialSpawn(pl) +end + +function GM:Think() +end + +function GM:PlayerCanHearPlayersVoice() + return true, true +end + +function GM:CheckPassword(Mystery,IP,ServerPassword,Name) + --This new hook returns AllowJoin,BlockMessage +end + + +function GM:PlayerSpawn(pl) + hook.Call( "PlayerSetModel" , self , pl ) + self:PlayerLoadout(pl) +end + +function GM:PlayerLoadout( ply ) + ply:Give("weapon_physcannon") + ply:Give("weapon_physgun") + ply:SelectWeapon("weapon_physgun") + + for k,v in pairs(ply:GetWeapons()) do + v:DrawShadow(false) + end + + return true +end + + + + + + diff --git a/gamemode/sh_var/globalshvar.lua b/gamemode/sh_var/globalshvar.lua new file mode 100644 index 0000000..332708a --- /dev/null +++ b/gamemode/sh_var/globalshvar.lua @@ -0,0 +1,53 @@ +local EPT = FindMetaTable("Entity") +local SHQTab = 0 +local SHQLimit = 200 +local SHQSend = {} +local SHNonTemp = {} + +GM._GlobalSHVars = {} + +if (CLIENT) then + net.Receive("_ReceiveGlobalSHVar",function(size) + local Dat = net.ReadTable() + self._GlobalSHVars[Dat.Name] = Dat.Value + end) +else + hook.Add("PlayerAuthed","_AddGlobalSHVar",function(pl,sid,uid) + GM = GM or GAMEMODE + + for k,v in pairs( GM._GlobalSHVars ) do + GM:SetGlobalSHVar(k,v,pl) + end + end) + + util.AddNetworkString("_ReceiveGlobalSHVar") +end + +function GM:GetGlobalSHVarTable() + return self._GlobalSHVars +end + +function GM:SetGlobalSHVar(Name,Var,ply) + self._GlobalSHVars[Name] = Var + + if (CLIENT) then return end + + local Dat = { + Name = Name, + Value = Var, + } + + net.Start( "_ReceiveGlobalSHVar" ) + net.WriteTable( Dat ) + + if (IsValid(ply)) then + net.Send(ply) + else + net.Broadcast() + end +end + +function GM:GetGlobalSHVar(Name,Var) + if (!self._GlobalSHVars or self._GlobalSHVars[Name] == nil) then return Var or nil end + return self._GlobalSHVars[Name] +end \ No newline at end of file diff --git a/gamemode/sh_var/shvar.lua b/gamemode/sh_var/shvar.lua new file mode 100644 index 0000000..11e299e --- /dev/null +++ b/gamemode/sh_var/shvar.lua @@ -0,0 +1,84 @@ +local EPT = FindMetaTable("Entity") +local SHNonTemp = {} + + + +if (CLIENT) then + net.Receive("_ReceiveSHVar",function(size) + local Dat = net.ReadTable() + local Ent = Dat.Ent + + if (!IsValid(Ent)) then return end + if (!Ent._SHVarDat) then Ent._SHVarDat = {} end + Ent._SHVarDat[Dat.Name] = Dat.Value + end) +else + hook.Add("PlayerAuthed","_AddSHVar",function(pl,sid,uid) + for k,v in pairs( SHNonTemp ) do + local Ent = ents.GetByIndex(k) + if (IsValid(Ent)) then + for a,b in pairs( v ) do + Ent:SetSHVar(a,b,pl) + end + else + SHNonTemp[k] = nil + end + end + end) + + util.AddNetworkString("_ReceiveSHVar") +end + +function EPT:GetSHVarTable() + return self._SHVarDat +end + +function EPT:SearchSHVarTable(Name) + local DAT = {} + + if (!self._SHVarDat) then return {} end + for k,v in pairs(self._SHVarDat) do + if (k:find(Name) and v != nil) then + DAT[k] = v + end + end + + return DAT +end + +function EPT:AddNonTempSH(bKey,Value) + local ID = self:EntIndex() + + if (!SHNonTemp[ID]) then SHNonTemp[ID] = {} end + SHNonTemp[ID][bKey] = Value + + self:SetSHVar(bKey,Value) +end + +function EPT:SetSHVar(Name,Var,ply) --Third argument should only be defined if it is send specificly only for this player. + if (!self._SHVarDat) then self._SHVarDat = {} end + self._SHVarDat[Name] = Var + + if (CLIENT) then return end + + local Dat = { + Name = Name, + Ent = self, + Value = Var, + } + + net.Start( "_ReceiveSHVar" ) + net.WriteTable( Dat ) + + if (IsValid(ply)) then + net.Send(ply) + else + net.Broadcast() + end +end + +function EPT:GetSHVar(Name,Var) + local ID = self:EntIndex() + if (!self._SHVarDat or self._SHVarDat[Name] == nil) then return Var or nil end + return self._SHVarDat[Name] +end \ No newline at end of file diff --git a/gamemode/sh_various/hooks.lua b/gamemode/sh_various/hooks.lua new file mode 100644 index 0000000..8983152 --- /dev/null +++ b/gamemode/sh_various/hooks.lua @@ -0,0 +1,14 @@ + +// :O + + +hook.Add( "PhysgunPickup", "CanPickupPlayer_MB", function(ply,ent) + GM = GM or GAMEMODE + + if (ent:IsPlayer() and GM:GetGlobalSHVar("PlayerPickup",false)) then + if (GM:GetGlobalSHVar("PlayerPickupAdmin",false)) then return (ply:IsAdmin()) end + return true + end +end) + +hook.Remove( "PostDrawEffects", "RenderHalos" ) diff --git a/gamemode/sh_various/math_ext.lua b/gamemode/sh_various/math_ext.lua new file mode 100644 index 0000000..f789306 --- /dev/null +++ b/gamemode/sh_various/math_ext.lua @@ -0,0 +1,57 @@ +local Ints = {1000, 900, 500, 400, 100,90, 50, 40, 10, 9, 5, 4, 1} +local Nums = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"} + +function math.IntToRoman(int) + if (int == 0) then return "N" end + + local Txt = "" + + if (int < 0) then Txt = "-" int = math.abs(int) end + + for i = 1, 13 do + while (int >= Ints[i]) do + int = int-Ints[i] + Txt = Txt..Nums[i] + end + end + + return Txt +end + +function math.IsFloat(num) + return (math.floor(num) != math.ceil(num)) +end + +function math.AngleNormalize(ang) + return Angle(math.NormalizeAngle(ang.p),math.NormalizeAngle(ang.y),math.NormalizeAngle(ang.r)) +end + +function math.Distance2Points(x1,y1,x2,y2) + return math.sqrt((x2-x1)^2+(y2-y1)^2) +end + +function math.Increment2Points(x1,y1,x2,y2) + return (y2-y1)/(x2-x1) +end + +function math.LinearAngle(x1,y1,x2,y2) + return math.atan2(y2-y1,x2-x1) * 180 / math.pi +end + +function math.SecondsToTime(secs) + secs = math.floor(secs) + + local Txt = "" + + for i = 0,2 do + local It = 60^(2-i) + local T = math.floor(secs/It) + + if (T<10) then Txt = Txt..":0"..T + else Txt = Txt..":"..T end + + secs = secs - T*It + end + + return Txt:sub(2) +end \ No newline at end of file diff --git a/gamemode/sh_various/note.lua b/gamemode/sh_various/note.lua new file mode 100644 index 0000000..d2597c7 --- /dev/null +++ b/gamemode/sh_various/note.lua @@ -0,0 +1,62 @@ + +local meta = FindMetaTable("Player") +local Dat = {} + +function meta:AddNote(Msg) + if (CLIENT) then + local DAT = {} + DAT.Time = CurTime() + DAT.Msg = Msg + table.insert(Dat,DAT) + else + net.Start("_GFGetMessage") + net.WriteString(Msg) + net.Send(self) + end +end + +if (CLIENT) then + net.Receive("_GFGetMessage",function(size) + local DAT = {} + DAT.Time = CurTime() + DAT.Msg = net.ReadString() + table.insert(Dat,DAT) + end) + + hook.Add("HUDPaint","GearFoxDrawNotes",function() + local N = CurTime()-5 + local C = 0 + local x = ScrW() + local y = ScrH()/2 + + surface.SetFont("Trebuchet18") --This is for the GetTextSize function. To get the correct size of a text. + + for k,v in pairs( Dat ) do + if (v.Time < N) then + table.remove(Dat,k) + else + local T = math.Clamp(v.Time-N,0,1) + local T2 = math.Clamp(N+5-v.Time,0,1) + C = C+1 + + local W,H = surface.GetTextSize(v.Msg) + local D = y+21*C + local X = x-(W+10)*T2 + local B = MAIN_COLOR.a*1 + local K = MAIN_TEXTCOLOR.a*1 + + MAIN_COLOR.a = B*T + MAIN_TEXTCOLOR.a = K*T + + DrawRect(X,D,W+8,20,MAIN_COLOR) + DrawText(v.Msg,"Trebuchet18",X+2,D+1,MAIN_TEXTCOLOR) + + MAIN_COLOR.a = B + MAIN_TEXTCOLOR.a = K + end + end + end) +else util.AddNetworkString( "_GFGetMessage" ) +end + + diff --git a/gamemode/sh_various/perlins_noise.lua b/gamemode/sh_various/perlins_noise.lua new file mode 100644 index 0000000..d23ef18 --- /dev/null +++ b/gamemode/sh_various/perlins_noise.lua @@ -0,0 +1,2 @@ +--Not entirely my own code... + diff --git a/gamemode/shared.lua b/gamemode/shared.lua new file mode 100644 index 0000000..6002ddc --- /dev/null +++ b/gamemode/shared.lua @@ -0,0 +1,23 @@ +include("autolua.lua") + +AddLuaCSFolder("cl_various") +AddLuaCSFolder("cl_hud/vgui") +AddLuaCSFolder("cl_hud/menus") +AddLuaCSFolder("cl_hud") + +AddLuaSHFolder("sh_various") +AddLuaSHFolder("sh_var") +AddLuaSHFolder("sh_gamemodes") + +AddLuaSVFolder("sv_various") +AddLuaSVFolder("sv_com") + +GM.Name = "GearFox Beta" +GM.Author = "The Maw" +GM.Email = "cjbremer@gmail.com" +GM.Website = "www.devinity2.eu" + + +function GM:PlayerNoClip( pl ) + return (pl:IsAdmin() or self:GetGlobalSHVar("GlobalNoclip",false)) +end diff --git a/gamemode/sv_various/globalsettings.lua b/gamemode/sv_various/globalsettings.lua new file mode 100644 index 0000000..fe1b197 --- /dev/null +++ b/gamemode/sv_various/globalsettings.lua @@ -0,0 +1,20 @@ + +util.AddNetworkString( "GlobalNoclip" ) +util.AddNetworkString( "PlayerCollision" ) +util.AddNetworkString( "PlayerPickup" ) +util.AddNetworkString( "PlayerPickupAdmin" ) + + + +function GM:SetEnableGlobalNoclip(boolean) + self:SetGlobalSHVar("GlobalNoclip",util.tobool(boolean)) +end + +function GM:SetEnablePlayerCollision(boolean) + self:SetGlobalSHVar("PlayerCollision",!util.tobool(boolean)) +end + +function GM:SetEnablePlayerPickup(boolean,boolean2) + self:SetGlobalSHVar("PlayerPickup",util.tobool(boolean)) + self:SetGlobalSHVar("PlayerPickupAdmin",util.tobool(boolean2)) +end diff --git a/gamemode/sv_various/hooks.lua b/gamemode/sv_various/hooks.lua new file mode 100644 index 0000000..58bfcb4 --- /dev/null +++ b/gamemode/sv_various/hooks.lua @@ -0,0 +1,29 @@ + +// :O + +util.AddNetworkString( "SunPos" ) + + +hook.Add("Initialize","LoadGearFox",function() + resource.AddDir("materials/gearfox") + resource.AddDir("materials/mawbase") + resource.AddDir("models/gearfox") + resource.AddDir("sound/mawbase") +end) + + +hook.Add("InitPostEntity","LoadGearFoxSunPos",function() + local Sun = ents.FindByClass("env_sun")[1] + + if (!IsValid(Sun)) then return end + + GM = GM or GAMEMODE + + local Ang = Sun:GetAngles() + Ang.p = Sun:GetKeyValues().pitch + Ang.y = Ang.y+180 + + local Pos = Ang:Forward()*10 + + GM:SetGlobalSHVar("SunPos",Pos) +end) \ No newline at end of file diff --git a/gamemode/sv_various/mysql.lua b/gamemode/sv_various/mysql.lua new file mode 100644 index 0000000..4e51e6c --- /dev/null +++ b/gamemode/sv_various/mysql.lua @@ -0,0 +1,38 @@ +pcall(require,"mysqloo") + +if (!mysqloo) then Msg("--- MySQL functions disabled. MySQLoo Module not found! ---\n") return end + +mysql = {} + +local Retries = 0 + +function mysql:Start(Host,User,Pass,Database) + local db = mysqloo.connect(Host,User,Pass,Database) + function db.onConnectionFailed(self,er) Msg( "Connection failed: "..er.."\n" ) end + function db.onConnected(self) Msg( "Connection has been established.\n" ) end + db:connect() + return db +end + +function mysql:Query(DAT,DB) + local db = DB or nil + if (!db) then Msg( "Database does not exist. Call mysql:Start()\n" ) return end + if (db:status() == mysqloo.DATABASE_NOT_CONNECTED) then + if (Retries < 4) then + Msg( "Reconnecting...\n" ) + db:connect() + timer.Simple(5,function() self:Query(DAT,DB) end) + + Retries = Retries+1 + else Retries = 0 end + return + end + + local DATABASE = db:query(DAT) + if (DATABASE) then + DATABASE:start() + function DATABASE.onError(s,er) Msg( er.."\n" ) end + function DATABASE.onFailure(s,er) Msg( er.."\n" ) end + end + return DATABASE +end diff --git a/gamemode/sv_various/resource.lua b/gamemode/sv_various/resource.lua new file mode 100644 index 0000000..6a32632 --- /dev/null +++ b/gamemode/sv_various/resource.lua @@ -0,0 +1,6 @@ + +function resource.AddDir(DIR) + local GAMEFIL,GAMEDIR = file.Find(DIR.."/*","GAME") + for k,v in pairs( GAMEDIR ) do resource.AddDir(DIR.."/"..v) end + for k,v in pairs( GAMEFIL ) do resource.AddFile(DIR.."/"..v) end +end -- cgit v1.2.3-70-g09d2