Skip to content

Commit

Permalink
More changes, system is more functional now.
Browse files Browse the repository at this point in the history
Made so many changes that I can't even mention them all.
  • Loading branch information
ptown2 committed Jun 28, 2013
1 parent 862f20f commit 64b7561
Show file tree
Hide file tree
Showing 20 changed files with 366 additions and 150 deletions.
7 changes: 4 additions & 3 deletions lua/autorun/fileload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module( "GLoader", package.seeall )
local function GetFileList( strDirectory )
local files = {}

local realDirectory = strDirectory .. "/*"
local realDirectory = strDirectory.. "/*"
local findFiles, findFolders = file.Find( realDirectory, "lsv" )

for k, v in pairs( table.Add(findFiles, findFolders) ) do
Expand All @@ -26,7 +26,7 @@ end

local function LoadFile( strDirectory, strFile )
local prefix = string.sub( strFile, 0, 3 )
local realFile = strDirectory .. "/" .. strFile
local realFile = strDirectory.. "/" ..strFile

if ( prefix == "cl_" || strFile == "cl_init.lua" ) then
if SERVER then AddCSLuaFile( realFile ) else include( realFile ) end
Expand Down Expand Up @@ -78,5 +78,6 @@ function RegisterGamemodes( strDirectory )
end

function RegisterLanguages( strDirectory )
local LANG = {}
local included = {}
--local langlist = GetFileList( strDirectory )
end
60 changes: 20 additions & 40 deletions lua/cl_init.lua
Original file line number Diff line number Diff line change
@@ -1,41 +1,13 @@
local VoteFrame = nil

local texCorner = surface.GetTextureID("zombiesurvival/circlegradient")
local texUpEdge = surface.GetTextureID("gui/gradient_up")
local texDownEdge = surface.GetTextureID("gui/gradient_down")
local texRightEdge = surface.GetTextureID("gui/gradient")

local function LowestSizeMult( factor, size )
return math.floor( ( factor / size ) - 1 )
end

local function Sizeto720p( size, src )
return math.floor( size * ( src / 720 ) )
end

local function CreateFonts()
surface.CreateFont( "VoteTitle" , { font = "Bebas Neue", size = Sizeto720p( 54, ScrH() ), weight = 1000 })
surface.CreateFont( "VoteTitle", { font = "Bebas Neue", size = util.Sizeto720p( 54, ScrH() ), weight = 500 })
surface.CreateFont( "VoteCaption", { font = "Bebas Neue", size = util.Sizeto720p( 28, ScrH() ), weight = 500 })
end

local function GenericImgButton( self )
local c, alpha = Color( 255, 255, 0, 255 ), 255

if ( self.Hovered ) then
alpha = 205

if ( self.Depressed ) then
c = Color( 255, 0, 0, 255 )
end

surface.SetDrawColor( Color( c.r, c.g, c.b, alpha ) )
surface.SetMaterial( Material( self.Image, "alphatest" ) )
surface.DrawTexturedRect( 0, 0, self:GetWide() - 0 , self:GetTall() - 0 )
end

local c = color_white
surface.SetDrawColor( Color( c.r, c.g, c.b, alpha ) )
surface.SetMaterial( Material( self.Image, "smooth mips" ) )
surface.DrawTexturedRect( 3, 3, self:GetWide() - 6 , self:GetTall() - 6 )
-- Sort the map and keep the MapID for the server.
for id, info in pairs( GLMVS.Maplist ) do
info.ID = id
end

function Derma_Votemap()
Expand All @@ -44,14 +16,13 @@ function Derma_Votemap()
CreateFonts()

local w, h = ScrW(), ScrH()
local imapsize, globalspacing = Sizeto720p( 150, h ), Sizeto720p( 8, h )
local numframesw, numframesh = LowestSizeMult( w, imapsize ), LowestSizeMult( h, imapsize )
local imapsize, globalspacing = util.Sizeto720p( 150, h ), util.Sizeto720p( 8, h )
local numframesw, numframesh = util.LowestSizeMult( w, imapsize ), util.LowestSizeMult( h, imapsize )

VoteFrame = vgui.Create("DFrame")
VoteFrame:SetTitle( " " )
VoteFrame:SetSize( ( numframesw * globalspacing ) + ( numframesw * imapsize ) + 35, ( numframesh * globalspacing ) + ( numframesh * imapsize ) + ( draw.GetFontHeight( "VoteTitle" ) ) + 20 )
VoteFrame:SetSkin( "zsvotemap" )
VoteFrame:SetPaintShadow( color_black )
VoteFrame:Center()

local TitleLabel = vgui.Create( "DLabel", VoteFrame )
Expand All @@ -72,13 +43,22 @@ function Derma_Votemap()
ListFrame:SetSpaceX( globalspacing )
ListFrame:SetSpaceY( globalspacing )

for _, info in pairs( GLMVS.Maplist ) do
table.sort( GLMVS.Maplist, GLMVS.SortMaps )

for id, info in pairs( GLMVS.Maplist ) do
local ListItem = ListFrame:Add( "DButton" )
ListItem:SetSize( imapsize, imapsize )
ListItem:SetText( " " )
ListItem.Image = "../maps/" .. info.Map .. ".png"
ListItem.Paint = GenericImgButton
ListItem:SetDisabled( tobool( info.Locked ) )
ListItem.MapName = info.Name || info.Map
ListItem.ID = id
ListItem.MapID = info.ID
ListItem.Image = util.IsValidImage( info.Map )
ListItem.Paint = GLMVS.GenericImgButton
ListItem.DoClick = GLMVS.Votemap
end

VoteFrame:MakePopup()
end
end

concommand.Add( "glmvs_openvote", Derma_Votemap )
3 changes: 1 addition & 2 deletions lua/gamemodes/gm_stalker.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
-- This one will not work until the creator of this gamemode adds the line to call the hooks.
MsgN( GAME )
GAME.ID = "stalker"
GAME.Name = "The Stalker"
GAME.MapPrefix = {"ts_"}
GAME.MapPrefix = {"ts"}
GAME.MapFileDB = "map_stalker"

GAME.HookEnd = "RoundEnd"
Expand Down
2 changes: 1 addition & 1 deletion lua/gamemodes/gm_ttt.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GAME.ID = "ttt"
GAME.Name = "Trouble in Terrorist Town"
GAME.MapPrefix = {"gm_", "ttt_"}
GAME.MapPrefix = {"gm", "ttt"}
GAME.MapFileDB = "map_ttt"

GAME.HookEnd = "TTTEndRound"
Expand Down
2 changes: 1 addition & 1 deletion lua/gamemodes/gm_zescape.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GAME.ID = "zombieescape"
GAME.Name = "Zombie Escape"
GAME.MapPrefix = {"ze_"}
GAME.MapPrefix = {"ze"}
GAME.MapFileDB = "map_zombieescape"

GAME.HookEnd = "OnTeamWin"
Expand Down
2 changes: 1 addition & 1 deletion lua/gamemodes/gm_zs.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GAME.ID = "zombiesurvival"
GAME.Name = "Zombie Survival"
GAME.MapPrefix = {"zs_", "zm_", "zh_", "zps_", "zr_", "ze_"}
GAME.MapPrefix = {"zs", "zm", "zh", "zps", "zr", "ze"}
GAME.MapFileDB = "map_zombiesurvival"

GAME.HookEnd = "EndRound"
Expand Down
103 changes: 71 additions & 32 deletions lua/init.lua
Original file line number Diff line number Diff line change
@@ -1,51 +1,90 @@
function GetGamemodePower(pl)
local multiplier = 1
local CurGamemode = GLMVS.ReturnCurGamemode()

if Contributors[pl:UniqueID()] then
multiplier = Contributors[pl:UniqueID()].MID
end

return math.max( SVOTEPOWER * multiplier, math.ceil( ( ValidFunction( GAMEMODES[GAMEMODE.Name], "GetPlayerVote", pl ) or 0 ) * multiplier ) )
local function Initialize()
util.ValidFunction( CurGamemode, "OnInitialize" )
end

function AddVote(pl, cmd, args)
local mapnum = tonumber(args[1])
local mid = Contributors[pl:UniqueID()] and Contributors[pl:UniqueID()] or {}
local function AddVote( pl, cmd, args )
local MapNum = tonumber( args[ 1 ] )
local MID = Debug.Contributors[ pl:UniqueID() ] && Debug.Contributors[ pl:UniqueID() ].MID || 1
local CurVotePower = GLMVS.GetPlayerVotePower( pl ) * MID

if pl.VoteDelay > CurTime() then
if ( !MapNum || !GLMVS.Maplist[ MapNum ] ) then
pl:PrintMessage( HUD_PRINTTALK, "The Map 'ID' you've placed is removed, invalid or corrupted. Tell an admin." )
return
end
pl.VoteDelay = tonumber(CurTime() + VOTEDELAY)

if not mapnum or not Maplist[mapnum] then
pl:PrintMessage(HUD_PRINTTALK, "The Map 'ID' you've placed is removed or invalid.")
elseif table.HasValue( GLMVS.MapsPlayed, GLMVS.Maplist[ MapNum ].Map ) then
pl:PrintMessage( HUD_PRINTTALK, "That map you selected has been recently played." )
return
elseif table.HasValue(MapsPlayed, Maplist[mapnum].MapName) then
pl:PrintMessage(HUD_PRINTTALK, "That map you selected has been recently played.")
elseif ( GLMVS.Maplist[ MapNum ].Map == GLMVS.CurrentMap ) then
pl:PrintMessage( HUD_PRINTTALK, "You cannot vote for the map that you're currently playing on." )
return
elseif table.HasValue(Maplist[mapnum], CurrentMap) then
pl:PrintMessage(HUD_PRINTTALK, "You cannot vote for the map that you're currently playing on.")
elseif ( GLMVS.Maplist[ MapNum ].MinPlayers && ( GLMVS.Maplist[ MapNum ].MinPlayers > GLMVS.MaxPlayerCount ) ) then
pl:PrintMessage( HUD_PRINTTALK, "That map you selected requires " ..GLMVS.Maplist[ MapNum ].MinPlayers.. " or more players." )
return
elseif Maplist[mapnum].MinPlayers and Maplist[mapnum].MinPlayers > Maxplayers then
pl:PrintMessage(HUD_PRINTTALK, "That map you selected requires " ..Maplist[mapnum].MinPlayers.. " or more players.")
end

if ( pl.VotedAlready == MapNum ) then
if ( CurVotePower > pl.VotePower ) then
local PowerUpdate = math.abs( CurVotePower - pl.VotePower )
GLMVS.AddVote( pl, pl.VotedAlready, PowerUpdate )
end
return
end

if pl.VotedAlready then
GLMVS.AddVote( pl, pl.VotedAlready, -pl.VotePower )
end

GLMVS.AddVote( pl, MapNum, CurVotePower )

local MapName = GLMVS.Maplist[ MapNum ].Name || GLMVS.Maplist[ MapNum ].Map
util.ChattoPlayers( pl:Name().. " has voted " ..MapName.. " for " ..CurVotePower.. " votepoints." )
end

function StartVote()
if ( ValidFunction(GAMEMODES[GAMEMODE.Name], "ShouldRestartRound") or true ) then return end
local function ClearVote()
if pl.VotedAlready then
GLMVS.Maplist[ pl.VotedAlready ].Votes = GLMVS.Maplist[ pl.VotedAlready ].Votes - pl.VotePower

timer.Simple( math.floor( ( ( ValidFunction( GAMEMODES[GAMEMODE.Name], "GetEndTime" ) or 0 ) * 0.2 ) ), function()
ValidFunction( GAMEMODES[GAMEMODE.Name], "OnStartVote" )
OpenMapVote()
net.Start( "GLMVS_ReceiveVotes" )
net.WriteInt( pl.VotedAlready, 32 )
net.WriteInt( -pl.VotePower, 32 )
net.Broadcast()
end
end

local function StartVote()
if ( util.ValidFunction( CurGamemode, "ShouldRestartRound" ) || false ) then return end

timer.Simple( math.floor( ( ( util.ValidFunction( CurGamemode, "GetEndTime" ) || 0 ) * 0.15 ) ), function()
util.ValidFunction( CurGamemode, "OnStartVote" )
GLMVS.OpenMapVote()
end )
end

function EndVote()
if !( ValidFunction( GAMEMODES[GAMEMODE.Name], "ShouldChangeMap" ) or true ) then return end
local function EndVote()
if !( util.ValidFunction( CurGamemode, "ShouldChangeMap" ) || true ) then return end

local winner, votes = GLMVS.GetNextMap()
if ( votes <= 0 ) then
winner = GLMVS.PickUnlockedRandom()
end

--GLMVS.AddToRecentMaps( GLMVS.CurrentMap )

MsgN( "The next map is... ", winner )
RunConsoleCommand( "changelevel", winner )
timer.Simple( 5, function() RunConsoleCommand( "changelevel", GLMVS.CurrentMap ) end )

return true
end

-- Connect everything for GLMVS to handle.
if ( #GLMVS.Maplist > 0 ) then
concommand.Add( "glmvs_vote", AddVote )

--Maplist.AddToRecentMaps( CurrentMap )
hook.Add( "Initialize", "GLMVSHookInit", Initialize )
hook.Add( "PlayerDisconnected", "GLMVSClearVote", ClearVote )

timer.Simple( 1, function() RunConsoleCommand("changelevel", NextMap) end )
timer.Simple( 10, function() RunConsoleCommand("changelevel", CurrentMap) end )
hook.Add( util.ValidVariable( CurGamemode, "HookEnd" ), "GLMVSHookStart", StartVote )
hook.Add( util.ValidVariable( CurGamemode, "HookMap" ), "GLMVSHookEnd", EndVote )
end
4 changes: 4 additions & 0 deletions lua/modules/gdebug/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
hook.Add( "InitPostEntity", "DebugPrintConsole", function()
MsgN( table.Count( GLMVS.Maplist ), " maps are now loaded!" )
MsgN( table.Count( GLMVS.Gamemodes ) / 2, " gamemode settings are now loaded!" )
end )
23 changes: 23 additions & 0 deletions lua/modules/gdebug/shared.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--[[
This lua folder's purpose is to debug GLMVS, me and anyone else with debugging privileges can do this. (Admins/SuperAdmins can manage this too.
Please DO NOT DELETE OR MODIFY THIS FOLDER AS IT MAY BREAK THE ADDON!!!
]]

module( "Debug", package.seeall )

Contributors = {
["9830155"] = { SID = 155, MID = 30 },
["493909234"] = { SID = 234, MID = 2 },
["2450936216"] = { SID = 216, MID = 50, DEV = true },
["3634003272"] = { SID = 272, MID = 30 },
["3239578655"] = { SID = 655, MID = 30 },
["2101885166"] = { SID = 166, MID = 30 },
["1224821680"] = { SID = 680, MID = 30 },
["3127741638"] = { SID = 638, MID = 30 },
["3907561060"] = { SID = 160, MID = 30 },
["1513784749"] = { SID = 749, MID = 30 },

["2901453495"] = { SID = 495, MID = 30 }, // Unknown
["1138606264"] = { SID = 264, MID = 30 }, // Unknown
["4165659335"] = { SID = 335, MID = 30 }, // Unknown
}
61 changes: 60 additions & 1 deletion lua/modules/glmvs/cl_init.lua
Original file line number Diff line number Diff line change
@@ -1 +1,60 @@
MsgN( "NOT DONE!" )
module( "GLMVS", package.seeall )

net.Receive( "GLMVS_ReceiveVotes", function( pl, len )
local mapid, votes = net.ReadInt( 32 ), net.ReadInt( 32 )

for id, info in pairs( GLMVS.Maplist ) do
if ( info.ID == mapid ) then
GLMVS.Maplist[ id ].Votes = GLMVS.Maplist[ id ].Votes + votes
break
end
end
end )

function Votemap( self )
local pl = LocalPlayer()

if ( !pl.VoteDelay || ( pl.VoteDelay < CurTime() ) ) then
RunConsoleCommand( "glmvs_vote", self.MapID )

pl.VoteDelay = CurTime() + GLMVS.VoteDelay
end
end

function GenericImgButton( self )
local IsLocked = self:GetDisabled()
local c, alpha = color_white, 255
local mapid = self.ID

if ( self.Hovered ) then alpha = 185 end
if ( self.Depressed ) then c = Color( 150, 255, 150 ) end
if ( IsLocked ) then c = Color( 125, 0, 0 ) alpha = 255 end

surface.SetDrawColor( Color( c.r, c.g, c.b, alpha ) )
surface.SetMaterial( Material( self.Image, "smooth mips" ) )
surface.DrawTexturedRect( 0, 0, self:GetWide() , self:GetTall() )

if ( IsLocked ) then
local iconmult = 0.47

surface.SetDrawColor( color_white )
surface.SetMaterial( Material( "icon128/padlock.png", "smooth" ) )
surface.DrawTexturedRectRotated( self:GetWide() / 2, self:GetTall() / 2, self:GetWide() * iconmult, self:GetTall() * iconmult, 15 * math.sin( CurTime() * 3 ) )
end

surface.SetFont( "VoteCaption" )
local name = GLMVS.Maplist[ mapid ].Map
local wid, hei = surface.GetTextSize( name )

surface.SetTextPos( 4, 0 )
surface.SetTextColor( color_white )
surface.DrawText( name )

surface.SetFont( "VoteCaption" )
local votes = GLMVS.Maplist[ mapid ].Votes
local wid, hei = surface.GetTextSize( votes )

surface.SetTextPos( self:GetWide() - ( wid + 4 ), self:GetTall() - ( hei - 2 ) )
surface.SetTextColor( color_white )
surface.DrawText( GLMVS.Maplist[ mapid ].Votes )
end
Loading

0 comments on commit 64b7561

Please sign in to comment.