Benny/gamemodes/benny/gamemode/gamestate.lua

149 lines
3.5 KiB
Lua

BennyGame = BennyGame or {}
BG_GTYPE_CAMPAIGN = 0
BG_GTYPE_MP = 1
local cGametype = CreateConVar("b-gametype", 1, nil, "0 for Campaign, 1 for MP")
local cGamemode = CreateConVar("b-gamemode", 2, nil, "MP:\n0 - TDM\n1 - FFA\n2 - Domination\n3 - CTF\n4 - Bomb\n5 - Hardpoint\n6 - Demolition")
function BennyGame:GetType()
return cGametype:GetBool() and BG_GTYPE_MP or BG_GTYPE_CAMPAIGN
end
BennyGame.TeamsInPlay = {
[4] = 1,
[3] = 2,
}
BennyGame.TeamToFaction = table.Flip( BennyGame.TeamsInPlay )
BennyGame.TeamCount = table.Count(BennyGame.TeamsInPlay)
BG_GMODE_TDM = 0
BG_GMODE_FFA = 1
BG_GMODE_DOMINATION = 2
BG_GMODE_CTF = 3
BG_GMODE_BOMB = 4
BG_GMODE_HARDPOINT = 5
BG_GMODE_DEMOLITION = 6
function BennyGame:GetMode()
return BG_GMODE_TDM
end
hook.Add("Initialize", "Benny_Initialize", function()
-- local mapscript = "benny_maps/" .. game.GetMap() .. "_init.lua"
-- AddCSLuaFile(mapscript)
-- include(mapscript)
end)
hook.Add("InitPostEntity", "Benny_InitPostEntity", function()
-- local mapscript = "benny_maps/" .. game.GetMap() .. "_initpostentity.lua"
-- AddCSLuaFile(mapscript)
-- include(mapscript)
end)
local thetypes = {
"Float",
"Int",
"Bool",
"Entity",
}
function BennyGame:Accessor( name, typey, default )
local World = game.GetWorld()
if typey == "Float" then
BennyGame["Get" .. name] = function( self )
return World:GetNW2Float( name, default )
end
BennyGame["Set" .. name] = function( self, val )
World:SetNW2Float( name, val )
end
return
end
if typey == "Int" then
BennyGame["Get" .. name] = function( self )
return World:GetNW2Int( name, default )
end
BennyGame["Set" .. name] = function( self, val )
World:SetNW2Int( name, val )
end
return
end
if typey == "Bool" then
BennyGame["Get" .. name] = function( self )
return World:GetNW2Bool( name, default )
end
BennyGame["Set" .. name] = function( self, val )
World:SetNW2Bool( name, val )
end
return
end
if typey == "Entity" then
BennyGame["Get" .. name] = function( self )
return World:GetNW2Entity( name, default )
end
BennyGame["Set" .. name] = function( self, val )
World:SetNW2Entity( name, val )
end
return
end
end
BG_STATE_WAITINGFORPLAYERS = 0
BG_STATE_PRE = 1
BG_STATE_ACTIVE = 2
BG_STATE_POST = 3
hook.Add("InitPostEntity", "Benny_Gamestate_InitPostEntity", function()
BennyGame:Accessor( "RoundStartedAt", "Float", 0 )
BennyGame:Accessor( "PregameStartedAt", "Float", 0 )
BennyGame:Accessor( "RoundFinishedAt", "Float", 0 )
BennyGame:Accessor( "State", "Int", 0 )
BennyGame:Accessor( "Round", "Int", 1 )
BennyGame:Accessor( "SwappedAtRound", "Int", 1 )
BennyGame:Accessor( "TeamsSwapped", "Bool", false )
end)
hook.Add("Think", "Benny_Gamestate_Think", function()
if SERVER then
local World = Entity(0)
if BennyGame:GetType() == BG_GTYPE_MP then
local roundstate = BennyGame:GetState()
if roundstate == BG_STATE_WAITINGFORPLAYERS then
-- Waiting for players
local count = 0
for index, ply in player.Iterator() do
if ply:Team() == TEAM_CONNECTING then continue end
if ply:Team() == TEAM_UNASSIGNED then continue end
if ply:Team() == TEAM_SPECTATOR then continue end
count = count + 1
end
end
if roundstate == BG_STATE_PRE then
-- Pregame
elseif roundstate == BG_STATE_POST then
-- Postgame
elseif roundstate == BG_STATE_ACTIVE then
-- Active round
if (BennyGame:GetRoundStartedAt()) <= CurTime() then
-- Round time expired
end
end
end
end
end)