2018-07-15 10:07:37 +00:00
2018-07-15 10:15:12 +00:00
if engine.ActiveGamemode ( ) ~= " zombiesurvival " then return end
2018-07-15 10:07:37 +00:00
2018-07-16 14:57:47 +00:00
local settings = {
JackpotStart = 25 ,
JackpotMax = 2500 ,
JackpotMultiplier = 1.1 ,
MinimumRounds = 5 ,
2018-07-23 22:08:55 +00:00
EndroundPoints = 50 , -- Points to give at the end of the round (Jackpot gets added to the points the players get)
ZombiePointsFactor = 0.15 , -- Factor of points zombies get of the points payout after round end
LosePointReduction = 0.0 -- Factor of points that gets taken away from players who lost
2018-07-16 14:57:47 +00:00
}
-- Grab the data from the file about the map.
local function getMapParams ( mapName )
local data = { }
if file.Exists ( " zsmapinfo/ " .. mapName .. " .txt " , " DATA " ) then
data = util.JSONToTable ( file.Read ( " zsmapinfo/ " .. mapName .. " .txt " , " DATA " ) ) or { }
end
-- Get map params or default values
local mapParams = { }
mapParams.Name = mapName
mapParams.TimesWon = data.TimesWon or 0
mapParams.TimesLost = data.TimesLost or 0
mapParams.Boost = data.Boost or 1
mapParams.Jackpot = data.Jackpot or settings.JackpotStart
return mapParams
end
local mapParams = getMapParams ( string.lower ( game.GetMap ( ) ) )
local function saveMapParams ( mapParams )
2018-07-15 10:15:12 +00:00
if not file.Exists ( " zsmapinfo " , " DATA " ) then
file.CreateDir ( " zsmapinfo " )
end
2018-07-16 14:57:47 +00:00
file.Write ( " zsmapinfo/ " .. mapParams.Name .. " .txt " , util.TableToJSON ( mapParams ) )
end
2018-07-15 10:07:37 +00:00
2018-07-16 14:57:47 +00:00
-- This hook checks to make sure there are zombies on the server. TODO: Check for AFK zombies
local zombieIntervalCounter , totalIntervalCounter = 0 , 0
hook.Add ( " WaveStateChanged " , " pointsave_zombieintervalactivator " , function ( )
if not timer.Exists ( " pointsave_zombieintervalcounter " ) then
timer.Create ( " pointsave_zombieintervalcounter " , 10 , 0 , function ( )
if # ( team.GetPlayers ( TEAM_UNDEAD ) ) > 0 then
zombieIntervalCounter = zombieIntervalCounter + 1
end
totalIntervalCounter = totalIntervalCounter + 1
2018-07-15 10:15:12 +00:00
end )
2018-07-15 10:07:37 +00:00
end
2018-07-15 10:15:12 +00:00
end )
2018-07-15 10:07:37 +00:00
2018-07-16 15:08:36 +00:00
local function resetVariables ( )
zombieIntervalCounter , totalIntervalCounter = 0 , 0
end
2018-07-16 15:02:46 +00:00
2018-07-16 14:57:47 +00:00
local function postStatistics ( mapParams , timesPlayed , freqMult , zombiePercentCalcMap )
2018-07-17 17:24:31 +00:00
PrintMessage ( HUD_PRINTTALK , " This map has been played " .. timesPlayed .. " times with humans winning " .. ( mapParams.TimesWon ) .. " times.( " .. ( math.Round ( ( mapParams.TimesWon / timesPlayed ) * 100 ) ) .. " %) " )
PrintMessage ( HUD_PRINTTALK , " Zombies were playing this map for " .. math.Round ( zombiePercentCalcMap * 100 ) .. " % of the time. " )
2018-07-22 19:22:29 +00:00
PrintMessage ( HUD_PRINTTALK , " frequency multiplier for this map is " .. math.Round ( freqMult , 2 ) .. " . Play maps infrequently for a higher value! " )
2018-07-17 17:24:31 +00:00
PrintMessage ( HUD_PRINTTALK , " Special boost for this map is " .. ( mapParams.Boost ) .. " . Tell an admin if you think it should be changed! " )
PrintMessage ( HUD_PRINTTALK , " Map jackpot is now " .. ( mapParams.Jackpot ) .. " . " )
2018-07-16 14:57:47 +00:00
end
2018-07-16 15:48:34 +00:00
-- TODO: When round is lost, take away points from human players that were there at the beginning of the game (All Human players that were there at the end of round 1, when late joiners join as zombies)
2018-07-16 16:21:24 +00:00
--[[
Cases :
- When round is lost :
- Only players from the end of Wave 1 ( online or disconnected ) get the 85 % reduction of points . But online players get some additional points
- When round is won :
- All humans get points + jackpot
- Zombies get a few points ( but a reduction of 85 % if they were there since the end of wave 1 )
] ] --
2018-07-16 15:21:13 +00:00
2018-07-16 14:57:47 +00:00
hook.Add ( " PostEndRound " , " pointsave_givedapoints " , function ( winner )
timer.Destroy ( " pointsave_zombieintervalcounter " )
2018-07-15 10:07:37 +00:00
2018-07-16 15:02:46 +00:00
if PointSaving_shouldIgnoreMap ( game.GetMap ( ) ) then return end
2018-07-16 14:57:47 +00:00
timer.Simple ( 0 , function ( )
2018-07-15 10:15:12 +00:00
print ( " point bonus hook " )
2018-07-22 19:22:29 +00:00
local zombiePercentCalcMap = 1
if totalIntervalCounter > 0 then
zombiePercentCalcMap = ( zombieIntervalCounter / totalIntervalCounter )
end
2018-07-16 14:57:47 +00:00
local timesPlayed = mapParams.TimesWon + mapParams.TimesLost
2018-07-16 16:50:05 +00:00
local freqMult = 1 / math.pow ( math.Max ( timesPlayed , 10 ) / 10 , 0.2 ) + 1
2018-07-16 14:57:47 +00:00
-- Check if zombies did even play most of the map
if zombiePercentCalcMap <= .5 then
PrintMessage ( HUD_PRINTTALK , " No end of game points because zombies were not even playing half the time! " )
postStatistics ( mapParams , timesPlayed , freqMult , zombiePercentCalcMap )
saveMapParams ( mapParams )
2018-07-16 15:08:36 +00:00
resetVariables ( )
2018-07-16 14:57:47 +00:00
return
end
-- Increase counters
if winner == TEAM_UNDEAD then
mapParams.TimesLost = mapParams.TimesLost + 1
elseif winner == TEAM_HUMAN then
mapParams.TimesWon = mapParams.TimesWon + 1
2018-07-15 10:15:12 +00:00
else
2018-07-16 14:57:47 +00:00
print ( " Wow you fucked up! No seriously how do you not have a winner? " )
end
-- Increase jackpot
if winner == TEAM_UNDEAD then
mapParams.Jackpot = mapParams.Jackpot * settings.JackpotMultiplier
if mapParams.Jackpot > settings.JackpotMax then
mapParams.Jackpot = settings.JackpotMax
2018-07-15 10:15:12 +00:00
end
2018-07-15 10:07:37 +00:00
end
2018-07-16 14:57:47 +00:00
2018-07-16 16:02:01 +00:00
-- Again, as the counter changed
timesPlayed = mapParams.TimesWon + mapParams.TimesLost
2018-07-16 16:50:05 +00:00
local freqMult = 1 / math.pow ( math.Max ( timesPlayed , 10 ) / 10 , 0.2 ) + 1
2018-07-16 16:02:01 +00:00
2018-07-16 14:57:47 +00:00
-- Check if map was played enough times
if timesPlayed < settings.MinimumRounds then
2018-07-17 17:24:31 +00:00
PrintMessage ( HUD_PRINTTALK , " Sorry, this map needs to be played at least " .. ( settings.MinimumRounds - timesPlayed ) .. " more times, before you can get points for winning. " )
2018-07-16 14:57:47 +00:00
postStatistics ( mapParams , timesPlayed , freqMult , zombiePercentCalcMap )
saveMapParams ( mapParams )
2018-07-16 15:08:36 +00:00
resetVariables ( )
2018-07-16 14:57:47 +00:00
return
end
-- Calculate points to give
local pointsToGive
2018-07-22 19:22:29 +00:00
local jackpot = 0
2018-07-16 14:57:47 +00:00
if winner == TEAM_HUMAN then
local finalMultiply = ( mapParams.Boost * freqMult * ( mapParams.TimesLost / timesPlayed ) * zombiePercentCalcMap )
2018-07-22 19:22:29 +00:00
PrintMessage ( HUD_PRINTTALK , " Congratulations, every survivor won the jackpot of " .. mapParams.Jackpot .. " for winning this round " )
pointsToGive = math.Round ( ( settings.EndroundPoints * finalMultiply ) )
jackpot = mapParams.Jackpot
2018-07-16 14:57:47 +00:00
mapParams.Jackpot = settings.JackpotStart
else
local finalMultiply = ( mapParams.Boost * ( mapParams.TimesWon / timesPlayed ) * zombiePercentCalcMap )
pointsToGive = math.Round ( settings.EndroundPoints * finalMultiply )
end
saveMapParams ( mapParams )
-- Give or take points, and output messages for each player
for k , ply in pairs ( player.GetAll ( ) ) do
local pointsToGivePly
2018-07-22 19:22:29 +00:00
local points = math.Round ( ply : GetSavedPoints ( ) )
2018-07-16 14:57:47 +00:00
-- Calculate points to give for each player (Depending on if the round was lost or won)
if ply : Team ( ) == TEAM_HUMAN then
2018-07-22 19:22:29 +00:00
points = math.Round ( ply : GetPoints ( ) )
pointsToGivePly = math.Round ( pointsToGive + jackpot )
2018-07-15 10:07:37 +00:00
else
2018-07-22 19:22:29 +00:00
pointsToGivePly = math.Round ( pointsToGive * settings.ZombiePointsFactor - points * settings.LosePointReduction )
2018-07-16 14:57:47 +00:00
end
-- Limit pointsToGivePly
if points + pointsToGivePly < 0 then pointsToGivePly = - points end
-- Set points
ply : SetPoints ( points + pointsToGivePly )
ply : SetSavedPoints ( points + pointsToGivePly )
-- Display message
if pointsToGivePly > 0 then
2018-07-17 17:24:31 +00:00
ply : PrintMessage ( HUD_PRINTTALK , " You gained " .. ( pointsToGivePly ) .. " this round for playing to the end! " )
2018-07-16 14:57:47 +00:00
elseif pointsToGivePly < 0 then
2018-07-17 17:24:31 +00:00
ply : PrintMessage ( HUD_PRINTTALK , " You lost " .. ( - pointsToGivePly ) .. " points this round! " )
2018-07-15 10:07:37 +00:00
end
end
2018-07-16 14:57:47 +00:00
-- Output general stats about this map
postStatistics ( mapParams , timesPlayed , freqMult , zombiePercentCalcMap )
2018-07-16 15:08:36 +00:00
resetVariables ( )
2018-07-16 14:57:47 +00:00
2018-07-15 10:15:12 +00:00
end )
end )