Cleanup and refactoring
This commit is contained in:
parent
bf2f1bc502
commit
21416551f0
@ -1,186 +1,148 @@
|
|||||||
|
|
||||||
if engine.ActiveGamemode() ~= "zombiesurvival" then return end
|
if engine.ActiveGamemode() ~= "zombiesurvival" then return end
|
||||||
|
|
||||||
-- this code grabs the data from the file about the map. if none exists it makes a default.
|
local settings = {
|
||||||
timer.Simple(25, function()
|
JackpotStart = 25,
|
||||||
mapwins = 0
|
JackpotMax = 2500,
|
||||||
maploss = 0
|
JackpotMultiplier = 1.1,
|
||||||
|
MinimumRounds = 5,
|
||||||
|
EndroundPoints = 50, -- Points to give at the end of the round (Jackpot gets added to the points the players get)
|
||||||
|
ZombiePointsFactor = 0.5, -- Factor of points zombies get of the points payout after round end
|
||||||
|
LosePointReduction = 0.85 -- Factor of points that gets taken away from players who lost
|
||||||
|
}
|
||||||
|
|
||||||
|
-- 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)
|
||||||
if not file.Exists("zsmapinfo", "DATA") then
|
if not file.Exists("zsmapinfo", "DATA") then
|
||||||
file.CreateDir("zsmapinfo")
|
file.CreateDir("zsmapinfo")
|
||||||
end
|
end
|
||||||
local mapname = string.lower(game.GetMap())
|
|
||||||
if file.Exists("zsmapinfo/"..mapname..".txt", "DATA") then
|
file.Write("zsmapinfo/"..mapParams.Name..".txt", util.TableToJSON(mapParams))
|
||||||
local data = util.JSONToTable(file.Read("zsmapinfo/"..mapname..".txt", "DATA"))
|
end
|
||||||
mapwins = data.mapwins
|
|
||||||
maploss = data.maploss
|
-- This hook checks to make sure there are zombies on the server. TODO: Check for AFK zombies
|
||||||
mapboost = data.mapboost
|
local zombieIntervalCounter, totalIntervalCounter = 0, 0
|
||||||
mapjackpot = data.mapjackpot
|
hook.Add("WaveStateChanged", "pointsave_zombieintervalactivator", function()
|
||||||
else
|
if not timer.Exists("pointsave_zombieintervalcounter") then
|
||||||
local main = {}
|
timer.Create("pointsave_zombieintervalcounter", 10, 0, function()
|
||||||
main["mapwins"] = 0
|
if #(team.GetPlayers(TEAM_UNDEAD)) > 0 then
|
||||||
main["maploss"] = 0
|
zombieIntervalCounter = zombieIntervalCounter + 1
|
||||||
main["mapboost"] = 1-- use a scale from 1 to 5
|
|
||||||
main["mapjackpot"] = 25
|
|
||||||
file.Write( "zsmapinfo/"..mapname..".txt", util.TableToJSON( main ) )
|
|
||||||
print("map win file not found. created one.")
|
|
||||||
end
|
end
|
||||||
zombpercentcountmap = 0
|
totalIntervalCounter = totalIntervalCounter + 1
|
||||||
totpercentcountmap = 1
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- this hook checks to make sure there are zombies on the server. later it should check to see if any are afk.
|
|
||||||
roundtime = 0
|
|
||||||
prereqcount = false
|
|
||||||
hook.Add("WaveStateChanged", "zombpercentcalc", function()
|
|
||||||
roundtime = CurTime()
|
|
||||||
|
|
||||||
if !timer.Exists("zombiepercentcalc") then
|
|
||||||
timer.Create("zombiepercentcalc", 10, 0, function()
|
|
||||||
if #(team.GetPlayers(TEAM_UNDEAD)) >0 then
|
|
||||||
zombpercentcountmap =zombpercentcountmap + 1
|
|
||||||
end
|
|
||||||
totpercentcountmap = totpercentcountmap + 1
|
|
||||||
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
hook.Add("EndRound", "givedapoints", function(winner)
|
local function postStatistics(mapParams, timesPlayed, freqMult, zombiePercentCalcMap)
|
||||||
timer.Destroy("zombiepercentcalc")
|
PrintMessage(HUD_PRINTTALK,"<c=0,255,255>This map has been played "..timesPlayed.." times with humans winning "..(mapParams.TimesWon).." times.("..(math.Round((mapParams.TimesWon/timesPlayed)*100)).."%)</c>")
|
||||||
|
PrintMessage(HUD_PRINTTALK,"<c=0,255,255>Zombies were only playing for "..math.Round(zombiePercentCalcMap * 100).."% of the time.</c>")
|
||||||
|
PrintMessage(HUD_PRINTTALK,"<c=0,255,255>frequency multiplier for this map is: "..freqMult..". play maps infrequently for a higher value!</c>")
|
||||||
|
PrintMessage(HUD_PRINTTALK,"<c=0,255,255>Special boost for this map is:"..(mapParams.Boost)..". tell an admin if you think it should be changed!</c>")
|
||||||
|
PrintMessage(HUD_PRINTTALK,"<c=204,204,0>Map jackpot is now "..(mapParams.Jackpot)..".</c>")
|
||||||
|
end
|
||||||
|
|
||||||
timer.Simple(0,function()
|
hook.Add("PostEndRound", "pointsave_givedapoints", function(winner)
|
||||||
|
timer.Destroy("pointsave_zombieintervalcounter")
|
||||||
|
|
||||||
|
-- TODO: Check if map should be ignored
|
||||||
|
|
||||||
|
timer.Simple(0, function()
|
||||||
print("point bonus hook")
|
print("point bonus hook")
|
||||||
local mapname = string.lower(game.GetMap())
|
local zombiePercentCalcMap = (zombieIntervalCounter / totalIntervalCounter) or .01
|
||||||
local zombiepercentcalcmap = (zombpercentcountmap/totpercentcountmap) or .01
|
local timesPlayed = mapParams.TimesWon + mapParams.TimesLost
|
||||||
local mapplaytotal = mapwins + maploss
|
|
||||||
local pointstogive = 10
|
-- Check if zombies did even play most of the map
|
||||||
zombiepercentcalcmap = zombiepercentcalcmap or .01
|
if zombiePercentCalcMap <= .5 then
|
||||||
-- we need to make sure that zombies were on the server for more than half the game.
|
PrintMessage(HUD_PRINTTALK, "No end of game points because zombies were not even playing half the time!")
|
||||||
if zombiepercentcalcmap <=.5 then
|
postStatistics(mapParams, timesPlayed, freqMult, zombiePercentCalcMap)
|
||||||
PrintMessage(HUD_PRINTTALK,"No end of game points because zombies were not even playing half the time!")
|
saveMapParams(mapParams)
|
||||||
elseif mapplaytotal <= 5 then
|
return
|
||||||
--print(mapplaytotal)
|
end
|
||||||
PrintMessage(HUD_PRINTTALK,"sorry but this map needs to be played at least "..(5-mapplaytotal).." more times before you can get points for winning.")
|
|
||||||
|
-- Increase counters
|
||||||
if winner == TEAM_UNDEAD then
|
if winner == TEAM_UNDEAD then
|
||||||
maploss = maploss + 1
|
mapParams.TimesLost = mapParams.TimesLost + 1
|
||||||
elseif winner == TEAM_HUMAN then
|
elseif winner == TEAM_HUMAN then
|
||||||
mapwins = mapwins +1
|
mapParams.TimesWon = mapParams.TimesWon + 1
|
||||||
else
|
else
|
||||||
print("wow you fucked up! no seriously how do you not have a winner?")
|
print("Wow you fucked up! No seriously how do you not have a winner?")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Increase jackpot
|
||||||
if winner == TEAM_UNDEAD then
|
if winner == TEAM_UNDEAD then
|
||||||
if mapjackpot <= 2500 then
|
mapParams.Jackpot = mapParams.Jackpot * settings.JackpotMultiplier
|
||||||
mapjackpot = mapjackpot*1.1
|
if mapParams.Jackpot > settings.JackpotMax then
|
||||||
|
mapParams.Jackpot = settings.JackpotMax
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local main = {}
|
|
||||||
main["mapwins"] = mapwins
|
|
||||||
main["maploss"] = maploss
|
|
||||||
main["mapboost"] = mapboost
|
|
||||||
main["mapjackpot"] = mapjackpot
|
|
||||||
file.Write( "zsmapinfo/"..mapname..".txt", util.TableToJSON( main ) )
|
|
||||||
else
|
|
||||||
if winner == TEAM_UNDEAD then
|
|
||||||
if mapjackpot <= 2500 then
|
|
||||||
mapjackpot = math.Round(mapjackpot*1.1)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
mapjackpot = 25
|
|
||||||
end
|
|
||||||
local multiplywin = 2
|
|
||||||
if mapplaytotal <10 then
|
|
||||||
multiplywin = 2
|
|
||||||
elseif mapplaytotal<25 then
|
|
||||||
multiplywin = 1.9
|
|
||||||
elseif mapplaytotal <50 then
|
|
||||||
multiplywin = 1.8
|
|
||||||
elseif mapplaytotal<100 then
|
|
||||||
multiplywin = 1.7
|
|
||||||
elseif mapplaytotal < 250 then
|
|
||||||
multiplywin = 1.6
|
|
||||||
elseif mapplaytotal < 500 then
|
|
||||||
multiplywin = 1.4
|
|
||||||
elseif mapplaytotal < 1000 then
|
|
||||||
multiplywin = 1.2
|
|
||||||
else
|
|
||||||
multiplywin = 1
|
|
||||||
end
|
|
||||||
|
|
||||||
if winner == TEAM_UNDEAD then
|
-- Check if map was played enough times
|
||||||
maploss = maploss + 1
|
if timesPlayed < settings.MinimumRounds then
|
||||||
elseif winner == TEAM_HUMAN then
|
PrintMessage(HUD_PRINTTALK,"Sorry, this map needs to be played at least "..(settings.MinimumRounds - timesPlayed).." more times, before you can get points for winning.")
|
||||||
mapwins = mapwins +1
|
postStatistics(mapParams, timesPlayed, freqMult, zombiePercentCalcMap)
|
||||||
else
|
saveMapParams(mapParams)
|
||||||
print("wow you fucked up!")
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local main = {}
|
-- Calculate points to give
|
||||||
main["mapwins"] = mapwins
|
local freqMult = 1 / math.pow(timesPlayed / 10, 0.2) + 1
|
||||||
main["maploss"] = maploss
|
local pointsToGive
|
||||||
main["mapboost"] = mapboost
|
|
||||||
main["mapjackpot"] = mapjackpot
|
|
||||||
file.Write( "zsmapinfo/"..mapname..".txt", util.TableToJSON( main ) )
|
|
||||||
|
|
||||||
local finalmultiply = 1
|
|
||||||
if winner == TEAM_UNDEAD then
|
|
||||||
finalmultiply = (mapboost * (mapwins/mapplaytotal) * zombiepercentcalcmap) or .01
|
|
||||||
pointstogive = math.Round(50 * finalmultiply) or 1
|
|
||||||
elseif winner == TEAM_HUMAN then
|
|
||||||
finalmultiply = (mapboost * multiplywin * (maploss/mapplaytotal) *zombiepercentcalcmap) or .01
|
|
||||||
pointstogive = math.Round((50 * finalmultiply) + mapjackpot) or 1
|
|
||||||
end
|
|
||||||
|
|
||||||
PrintMessage(HUD_PRINTTALK,"<c=0,255,255>This map has been played "..mapplaytotal.." times with humans winning "..(mapwins).." times.("..(math.Round((mapwins/mapplaytotal)*100)).."%)</c>")
|
|
||||||
PrintMessage(HUD_PRINTTALK,"<c=0,255,255>Zombies were only playing for "..(zombiepercentcalcmap*100).."% of the time.</c>")
|
|
||||||
PrintMessage(HUD_PRINTTALK,"<c=0,255,255>frequency multiplier for this map is:"..multiplywin..". play maps infrequently for a higher value!</c>")
|
|
||||||
PrintMessage(HUD_PRINTTALK,"<c=0,255,255>Special boost for this map is:"..(mapboost)..". tell an admin if you think it should be changed!</c>")
|
|
||||||
PrintMessage(HUD_PRINTTALK,"<c=204,204,0>Map jackpot is now "..(mapjackpot)..".</c>")
|
|
||||||
|
|
||||||
--regular points ZS points
|
|
||||||
--[[if (game.GetMap() ~= "zs_obj_gauntlet_v3" and game.GetMap() ~="zs_gauntlet_reborn_b6") and gmod.GetGamemode().Name == "Zombie Survival" then
|
|
||||||
for k,v in pairs(team.GetPlayers(TEAM_HUMAN)) do
|
|
||||||
v:SetSavedPoints((v:GetDTInt(1) + pointstogive) )
|
|
||||||
--WriteData(v:SteamID64(), v:GetPoints())
|
|
||||||
v:PrintMessage(HUD_PRINTTALK,"<c=255,0,0>You gained "..(pointstogive).." this round for playing to the end!</c>")
|
|
||||||
end
|
|
||||||
for k,v in pairs(team.GetPlayers(TEAM_UNDEAD)) do
|
|
||||||
v:SetSavedPoints(math.Round((v:GetSavedPoints() + (pointstogive/5)) ))
|
|
||||||
--WriteData(v:SteamID64(), v:GetPoints())
|
|
||||||
v:PrintMessage(HUD_PRINTTALK,"<c=255,0,0>You gained "..(math.Round(pointstogive/2)).." points this round for playing to the end!</c>")
|
|
||||||
end
|
|
||||||
end]]
|
|
||||||
|
|
||||||
end
|
|
||||||
if (game.GetMap() ~= "zs_obj_gauntlet_v3" and game.GetMap() ~="zs_gauntlet_reborn_b6") and gmod.GetGamemode().Name == "Zombie Survival" then
|
|
||||||
if winner == TEAM_HUMAN then
|
if winner == TEAM_HUMAN then
|
||||||
for k,ply in pairs(player.GetAll()) do
|
local finalMultiply = (mapParams.Boost * freqMult * (mapParams.TimesLost / timesPlayed) * zombiePercentCalcMap)
|
||||||
|
PrintMessage(HUD_PRINTTALK,"<c=0,255,255>Congratulations, you won the jackpot of "..mapParams.Jackpot.." for winning this round</c>")
|
||||||
|
pointsToGive = math.Round((settings.EndroundPoints * finalMultiply) + mapParams.Jackpot)
|
||||||
|
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
|
||||||
|
local points = ply:GetPoints()
|
||||||
|
-- Calculate points to give for each player (Depending on if the round was lost or won)
|
||||||
if ply:Team() == TEAM_HUMAN then
|
if ply:Team() == TEAM_HUMAN then
|
||||||
if ply:GetPoints()- ply:GetSavedPoints()> 0 then
|
pointsToGivePly = math.Round(pointsToGive)
|
||||||
ply:SetSavedPoints(ply:GetPoints()+((ply:GetPoints()- ply:GetSavedPoints()))+pointstogive)
|
|
||||||
ply:PrintMessage(HUD_PRINTTALK,"<c=255,0,0>You gained "..(pointstogive).." this round for playing to the end!</c>")
|
|
||||||
else
|
else
|
||||||
ply:SetSavedPoints(ply:GetPoints()+pointstogive)
|
pointsToGivePly = math.Round(pointsToGive * settings.ZombiePointsFactor) - points * settings.LosePointReduction
|
||||||
ply:PrintMessage(HUD_PRINTTALK,"<c=255,0,0>You gained "..(pointstogive).." this round for playing to the end!</c>")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if ply:GetPoints()- ply:GetSavedPoints()> 0 then
|
|
||||||
ply:SetSavedPoints(ply:GetPoints()+((ply:GetPoints()- ply:GetSavedPoints())*.15)+(pointstogive/2))
|
|
||||||
ply:PrintMessage(HUD_PRINTTALK,"<c=255,0,0>You gained "..(pointstogive/2).." this round for playing to the end!</c>")
|
|
||||||
else
|
|
||||||
ply:SetSavedPoints(ply:GetPoints()+(pointstogive/2))
|
|
||||||
ply:PrintMessage(HUD_PRINTTALK,"<c=255,0,0>You gained "..(pointstogive/2).." this round for playing to the end!</c>")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
for k,ply in pairs(player.GetAll()) do
|
|
||||||
if ply:GetPoints()- ply:GetSavedPoints()> 0 then
|
|
||||||
ply:SetSavedPoints(ply:GetPoints()+((ply:GetPoints()- ply:GetSavedPoints())*.15)+(pointstogive/2))
|
|
||||||
else
|
|
||||||
ply:SetSavedPoints(ply:GetPoints()+(pointstogive/2))
|
|
||||||
end
|
|
||||||
end
|
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
|
||||||
|
ply:PrintMessage(HUD_PRINTTALK,"<c=255,0,0>You gained "..(pointsToGivePly).." this round for playing to the end!</c>")
|
||||||
|
elseif pointsToGivePly < 0 then
|
||||||
|
ply:PrintMessage(HUD_PRINTTALK,"<c=255,0,0>You lost "..(-pointsToGivePly).." points this round!</c>")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Output general stats about this map
|
||||||
|
postStatistics(mapParams, timesPlayed, freqMult, zombiePercentCalcMap)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
Loading…
Reference in New Issue
Block a user