Add a factor for gained points

This commit is contained in:
David Vogel 2018-07-24 18:15:35 +02:00
parent 21a6637c63
commit 01f917091d
2 changed files with 13 additions and 8 deletions

View File

@ -20,7 +20,7 @@ end
local function savePoints(ply)
if PointSaving_shouldIgnoreMap(game.GetMap()) then return end
if not ply.PointSaving_Loaded then return end
if not ply.PointSaving_StartPoints then return end
if ply:Team() == TEAM_HUMAN then
ply:SetSavedPoints(ply:GetPoints())
@ -50,8 +50,9 @@ local function loadPoints(ply)
timer.Simple(0, function()
if IsValid(ply) and ply:Team() == TEAM_HUMAN then
ply:SetPoints(ply:GetSavedPoints())
ply.PointSaving_Loaded = true
local savedPoints = ply:GetSavedPoints()
ply:SetPoints(savedPoints)
ply.PointSaving_StartPoints = savedPoints
end
end)

View File

@ -6,9 +6,10 @@ local settings = {
JackpotMax = 2500,
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.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
EndroundPoints = 50, -- Points to give at the end of the round to winners (Jackpot gets added to the points the players get)
ZombiePointsFactor = 0.00, -- Factor of points zombies get of the EndroundPoints after round end
LosePointReduction = 0.00, -- Factor of the total saved points, which get taken away from players who lost
LosePointDifferenceReduction = 0.85 -- Factor of the players gained points, which get taken away from players who lost
}
-- Grab the data from the file about the map.
@ -147,12 +148,15 @@ hook.Add("PostEndRound", "pointsave_givedapoints", function(winner)
for k, ply in pairs(player.GetAll()) do
local pointsToGivePly
local points = math.Round(ply:GetSavedPoints())
local gainedPoints = points - (ply.PointSaving_StartPoints or 0)
print("GAINED: "..gainedPoints)
if gainedPoints < 0 then gainedPoints = 0 end
-- Calculate points to give for each player (Depending on if the round was lost or won)
if ply:Team() == TEAM_HUMAN then
points = math.Round(ply:GetPoints())
pointsToGivePly = math.Round(pointsToGive + jackpot)
else
pointsToGivePly = math.Round(pointsToGive * settings.ZombiePointsFactor - points * settings.LosePointReduction)
pointsToGivePly = math.Round(pointsToGive * settings.ZombiePointsFactor - points * settings.LosePointReduction - gainedPoints * settings.LosePointDifferenceReduction)
end
-- Limit pointsToGivePly
if points + pointsToGivePly < 0 then pointsToGivePly = -points end
@ -161,7 +165,7 @@ hook.Add("PostEndRound", "pointsave_givedapoints", function(winner)
ply:SetSavedPoints(points + pointsToGivePly)
-- Display message
if pointsToGivePly > 0 then
ply:PrintMessage(HUD_PRINTTALK, "You gained "..(pointsToGivePly).." this round for playing to the end!")
ply:PrintMessage(HUD_PRINTTALK, "In the end, you gained additional "..(pointsToGivePly).." points!")
elseif pointsToGivePly < 0 then
ply:PrintMessage(HUD_PRINTTALK, "You lost "..(-pointsToGivePly).." points this round!")
end