Files
Gmod-PropHuntExtended/source/gamemodes/prophuntextended/gamemode/server/states/state_seek.lua
T

109 lines
3.7 KiB
Lua
Raw Normal View History

2016-06-14 07:28:36 +02:00
--[[
The MIT License (MIT)
Copyright (c) 2015-2018 Xaymar
2016-06-14 07:28:36 +02:00
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--]]
include "base.lua"
2019-08-15 15:46:14 +02:00
local CLASS = state("Seek", GM.States.Seek)
2016-06-14 07:28:36 +02:00
2019-08-15 15:46:14 +02:00
function CLASS:OnEnter(OldState)
2017-11-19 21:12:58 +01:00
if GAMEMODE.Config:DebugLog() then print("StateSeek: OnEnter") end
2016-06-14 07:28:36 +02:00
GAMEMODE:SetRoundState(GAMEMODE.States.Seek)
-- Unfreeze Seekers
for i, ply in ipairs(team.GetPlayers(GAMEMODE.Teams.Seekers)) do
ply:Freeze(false)
ply:UnLock()
ply:ScreenFade(SCREENFADE.PURGE, color_black, 0, 0)
ply:ScreenFade(SCREENFADE.IN, color_black, 1, 0)
2016-06-14 07:28:36 +02:00
end
end
2019-08-15 15:46:14 +02:00
function CLASS:Tick()
2016-06-14 07:28:36 +02:00
-- Update Game Time
local deltaTime = (CurTime() - GAMEMODE.Data.RoundStartTime)
GAMEMODE.Data.RoundTime = GAMEMODE.Config.Round:Time() - deltaTime
GAMEMODE.Data.StateTime = GAMEMODE.Config.Round:Time() - deltaTime
GAMEMODE:SetRoundTime(GAMEMODE.Data.RoundTime)
GAMEMODE:SetRoundStateTime(GAMEMODE.Data.StateTime)
2016-06-14 07:28:36 +02:00
-- Victory Conditions
2016-06-14 07:28:36 +02:00
local hiders, seekers = team.GetPlayers(GAMEMODE.Teams.Hiders), team.GetPlayers(GAMEMODE.Teams.Seekers)
local hiderAlive, seekerAlive = false, false
if GAMEMODE.Config:Debug() then
hiderAlive = true;seekerAlive = true
end
2016-06-14 07:28:36 +02:00
for i,ply in ipairs(hiders) do
if (ply.Data.Alive) then
hiderAlive = true
end
end
for i,ply in ipairs(seekers) do
if (ply.Data.Alive) then
seekerAlive = truew
2016-06-14 07:28:36 +02:00
end
end
if (hiderAlive == false) then
if (seekerAlive == false) then -- Draw, both teams dead.
GAMEMODE:SetRoundWinner(GAMEMODE.Teams.Spectators)
2019-08-15 15:46:14 +02:00
RoundManager:SetState(StatePostRound)
else -- Seeker victory, Hiders dead
GAMEMODE:SetRoundWinner(GAMEMODE.Teams.Seekers)
2019-08-15 15:46:14 +02:00
RoundManager:SetState(StatePostRound)
2016-06-14 07:28:36 +02:00
end
else
if (seekerAlive == false) then -- Hider Victory, Seeker dead.
GAMEMODE:SetRoundWinner(GAMEMODE.Teams.Hiders)
2019-08-15 15:46:14 +02:00
RoundManager:SetState(StatePostRound)
else
if (GAMEMODE.Data.StateTime <= 0) then -- No Time remaining
2017-11-19 21:12:58 +01:00
GAMEMODE:SetRoundWinner(GAMEMODE.Teams.Hiders)
2019-08-15 15:46:14 +02:00
RoundManager:SetState(StatePostRound)
end
2016-06-14 07:28:36 +02:00
end
end
end
2019-08-15 15:46:14 +02:00
function CLASS:OnLeave(NewState)
2017-11-19 21:12:58 +01:00
if GAMEMODE.Config:DebugLog() then print("StateSeek: OnLeave") end
if GAMEMODE:GetRoundWinner() == GAMEMODE.Teams.Seekers then
2017-11-26 12:54:57 +01:00
-- Run external Hooks
2017-11-19 21:12:58 +01:00
hook.Run("RoundVictorySeeker")
2017-11-26 12:54:57 +01:00
-- Assign Team Points
team.SetScore(GAMEMODE.Teams.Seekers, team.GetScore(GAMEMODE.Teams.Seekers) + 1)
2017-11-19 21:12:58 +01:00
elseif GAMEMODE:GetRoundWinner() == GAMEMODE.Teams.Hiders then
2017-11-26 12:54:57 +01:00
-- Run external Hooks
2017-11-19 21:12:58 +01:00
hook.Run("RoundVictoryHider")
2017-11-26 12:54:57 +01:00
-- Assign Team Points
team.SetScore(GAMEMODE.Teams.Hiders, team.GetScore(GAMEMODE.Teams.Hiders) + 1)
2017-11-19 21:12:58 +01:00
else
2017-11-26 12:54:57 +01:00
-- Run external Hooks
2017-11-19 21:12:58 +01:00
hook.Run("RoundVictoryDraw")
end
2019-08-15 15:46:14 +02:00
end
_G["StateSeek"] = CLASS