diff --git a/lua/autorun/server/mapcalc.lua b/lua/autorun/server/mapcalc.lua index a8fdc6e..8ec3437 100644 --- a/lua/autorun/server/mapcalc.lua +++ b/lua/autorun/server/mapcalc.lua @@ -1,15 +1,13 @@ - - -if engine.ActiveGamemode() == "zombiesurvival" then +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. -timer.Simple(25,function() -mapwins = 0 -maploss = 0 - if not file.Exists( "zsmapinfo", "DATA") then - file.CreateDir( "zsmapinfo" ) - end +timer.Simple(25, function() + mapwins = 0 + maploss = 0 + if not file.Exists("zsmapinfo", "DATA") then + file.CreateDir("zsmapinfo") + end local mapname = string.lower(game.GetMap()) if file.Exists("zsmapinfo/"..mapname..".txt", "DATA") then local data = util.JSONToTable(file.Read("zsmapinfo/"..mapname..".txt", "DATA")) @@ -26,186 +24,175 @@ maploss = 0 file.Write( "zsmapinfo/"..mapname..".txt", util.TableToJSON( main ) ) print("map win file not found. created one.") end -zombpercentcountmap = 0 -totpercentcountmap = 1 + zombpercentcountmap = 0 + 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() +hook.Add("WaveStateChanged", "zombpercentcalc", function() + roundtime = CurTime() -if !timer.Exists( "zombiepercentcalc" ) then - timer.Create( "zombiepercentcalc", 10, 0, function() + if !timer.Exists("zombiepercentcalc") then + timer.Create("zombiepercentcalc", 10, 0, function() if #(team.GetPlayers(TEAM_UNDEAD)) >0 then - zombpercentcountmap =zombpercentcountmap +1 - + zombpercentcountmap =zombpercentcountmap + 1 end - totpercentcountmap = totpercentcountmap +1 - - - - end) -end -end) - -hook.Add("EndRound","givedapoints",function(winner) -timer.Destroy("zombiepercentcalc" ) - - -timer.Simple(0,function() -print("point bonus hook") -local mapname = string.lower(game.GetMap()) -local zombiepercentcalcmap = (zombpercentcountmap/totpercentcountmap) or .01 -local mapplaytotal = mapwins + maploss -local pointstogive = 10 -zombiepercentcalcmap = zombiepercentcalcmap or .01 --- we need to make sure that zombies were on the server for more than half the game. -if zombiepercentcalcmap <=.5 then -PrintMessage(HUD_PRINTTALK,"No end of game points because zombies were not even playing half the time!") -elseif mapplaytotal <= 5 then ---print(mapplaytotal) - PrintMessage(HUD_PRINTTALK,"sorry but this map needs to be played at least "..(5-mapplaytotal).." more times before you can get points for winning.") - if winner == TEAM_UNDEAD then - maploss = maploss + 1 - elseif winner == TEAM_HUMAN then - mapwins = mapwins +1 - else - print("wow you fucked up! no seriously how do you not have a winner?") - end - if winner == TEAM_UNDEAD then - if mapjackpot <= 2500 then - mapjackpot = mapjackpot*1.1 - 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 - maploss = maploss + 1 - elseif winner == TEAM_HUMAN then - mapwins = mapwins +1 - else - print("wow you fucked up!") - end - local main = {} - main["mapwins"] = mapwins - main["maploss"] = maploss - 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 + totpercentcountmap = totpercentcountmap + 1 + + end) end +end) - PrintMessage(HUD_PRINTTALK,"This map has been played "..mapplaytotal.." times with humans winning "..(mapwins).." times.("..(math.Round((mapwins/mapplaytotal)*100)).."%)") - PrintMessage(HUD_PRINTTALK,"Zombies were only playing for "..(zombiepercentcalcmap*100).."% of the time.") - PrintMessage(HUD_PRINTTALK,"frequency multiplier for this map is:"..multiplywin..". play maps infrequently for a higher value!") - PrintMessage(HUD_PRINTTALK,"Special boost for this map is:"..(mapboost)..". tell an admin if you think it should be changed!") - PrintMessage(HUD_PRINTTALK,"Map jackpot is now "..(mapjackpot)..".") +hook.Add("EndRound", "givedapoints", function(winner) + timer.Destroy("zombiepercentcalc") - --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:SetMoney((v:GetDTInt(1) + pointstogive) ) - --WriteData(v:SteamID64(), v:GetPoints()) - v:SaveMoney() - v:SaveMoneyTXT() - v:PrintMessage(HUD_PRINTTALK,"You gained "..(pointstogive).." this round for playing to the end!") - end - for k,v in pairs(team.GetPlayers(TEAM_UNDEAD)) do - v:SetMoney(math.Round((v:GetMoney() + (pointstogive/5)) )) - --WriteData(v:SteamID64(), v:GetPoints()) - v:SaveMoney() - v:SaveMoneyTXT() - v:PrintMessage(HUD_PRINTTALK,"You gained "..(math.Round(pointstogive/2)).." points this round for playing to the end!") - 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 - for k,ply in pairs(player.GetAll()) do - if ply:Team() == TEAM_HUMAN then - if ply:GetPoints()- ply:GetMoney()> 0 then - ply:SetMoney(ply:GetPoints()+((ply:GetPoints()- ply:GetMoney()))+pointstogive) - ply:SaveMoney() - ply:SaveMoneyTXT() - ply:PrintMessage(HUD_PRINTTALK,"You gained "..(pointstogive).." this round for playing to the end!") - else - ply:SetMoney(ply:GetPoints()+pointstogive) - ply:SaveMoney() - ply:SaveMoneyTXT() - ply:PrintMessage(HUD_PRINTTALK,"You gained "..(pointstogive).." this round for playing to the end!") - end - + timer.Simple(0,function() + print("point bonus hook") + local mapname = string.lower(game.GetMap()) + local zombiepercentcalcmap = (zombpercentcountmap/totpercentcountmap) or .01 + local mapplaytotal = mapwins + maploss + local pointstogive = 10 + zombiepercentcalcmap = zombiepercentcalcmap or .01 + -- we need to make sure that zombies were on the server for more than half the game. + if zombiepercentcalcmap <=.5 then + PrintMessage(HUD_PRINTTALK,"No end of game points because zombies were not even playing half the time!") + elseif mapplaytotal <= 5 then + --print(mapplaytotal) + PrintMessage(HUD_PRINTTALK,"sorry but this map needs to be played at least "..(5-mapplaytotal).." more times before you can get points for winning.") + if winner == TEAM_UNDEAD then + maploss = maploss + 1 + elseif winner == TEAM_HUMAN then + mapwins = mapwins +1 else - if ply:GetPoints()- ply:GetMoney()> 0 then - ply:SetMoney(ply:GetPoints()+((ply:GetPoints()- ply:GetMoney())*.15)+(pointstogive/2)) - ply:SaveMoney() - ply:SaveMoneyTXT() - ply:PrintMessage(HUD_PRINTTALK,"You gained "..(pointstogive/2).." this round for playing to the end!") - else - ply:SetMoney(ply:GetPoints()+(pointstogive/2)) - ply:SaveMoney() - ply:SaveMoneyTXT() - ply:PrintMessage(HUD_PRINTTALK,"You gained "..(pointstogive/2).." this round for playing to the end!") + print("wow you fucked up! no seriously how do you not have a winner?") + end + if winner == TEAM_UNDEAD then + if mapjackpot <= 2500 then + mapjackpot = mapjackpot*1.1 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 + maploss = maploss + 1 + elseif winner == TEAM_HUMAN then + mapwins = mapwins +1 + else + print("wow you fucked up!") + end + + local main = {} + main["mapwins"] = mapwins + main["maploss"] = maploss + 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,"This map has been played "..mapplaytotal.." times with humans winning "..(mapwins).." times.("..(math.Round((mapwins/mapplaytotal)*100)).."%)") + PrintMessage(HUD_PRINTTALK,"Zombies were only playing for "..(zombiepercentcalcmap*100).."% of the time.") + PrintMessage(HUD_PRINTTALK,"frequency multiplier for this map is:"..multiplywin..". play maps infrequently for a higher value!") + PrintMessage(HUD_PRINTTALK,"Special boost for this map is:"..(mapboost)..". tell an admin if you think it should be changed!") + PrintMessage(HUD_PRINTTALK,"Map jackpot is now "..(mapjackpot)..".") + + --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:SetMoney((v:GetDTInt(1) + pointstogive) ) + --WriteData(v:SteamID64(), v:GetPoints()) + v:SaveMoney() + v:SaveMoneyTXT() + v:PrintMessage(HUD_PRINTTALK,"You gained "..(pointstogive).." this round for playing to the end!") + end + for k,v in pairs(team.GetPlayers(TEAM_UNDEAD)) do + v:SetMoney(math.Round((v:GetMoney() + (pointstogive/5)) )) + --WriteData(v:SteamID64(), v:GetPoints()) + v:SaveMoney() + v:SaveMoneyTXT() + v:PrintMessage(HUD_PRINTTALK,"You gained "..(math.Round(pointstogive/2)).." points this round for playing to the end!") + end + end]] + end - else - for k,ply in pairs(player.GetAll()) do - if ply:GetPoints()- ply:GetMoney()> 0 then - ply:SetMoney(ply:GetPoints()+((ply:GetPoints()- ply:GetMoney())*.15)+(pointstogive/2)) + 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 + for k,ply in pairs(player.GetAll()) do + if ply:Team() == TEAM_HUMAN then + if ply:GetPoints()- ply:GetMoney()> 0 then + ply:SetMoney(ply:GetPoints()+((ply:GetPoints()- ply:GetMoney()))+pointstogive) + ply:SaveMoney() + ply:SaveMoneyTXT() + ply:PrintMessage(HUD_PRINTTALK,"You gained "..(pointstogive).." this round for playing to the end!") + else + ply:SetMoney(ply:GetPoints()+pointstogive) + ply:SaveMoney() + ply:SaveMoneyTXT() + ply:PrintMessage(HUD_PRINTTALK,"You gained "..(pointstogive).." this round for playing to the end!") + end + else + if ply:GetPoints()- ply:GetMoney()> 0 then + ply:SetMoney(ply:GetPoints()+((ply:GetPoints()- ply:GetMoney())*.15)+(pointstogive/2)) + ply:SaveMoney() + ply:SaveMoneyTXT() + ply:PrintMessage(HUD_PRINTTALK,"You gained "..(pointstogive/2).." this round for playing to the end!") + else + ply:SetMoney(ply:GetPoints()+(pointstogive/2)) + ply:SaveMoney() + ply:SaveMoneyTXT() + ply:PrintMessage(HUD_PRINTTALK,"You gained "..(pointstogive/2).." this round for playing to the end!") + end + end + end else - ply:SetMoney(ply:GetPoints()+(pointstogive/2)) + for k,ply in pairs(player.GetAll()) do + if ply:GetPoints()- ply:GetMoney()> 0 then + ply:SetMoney(ply:GetPoints()+((ply:GetPoints()- ply:GetMoney())*.15)+(pointstogive/2)) + else + ply:SetMoney(ply:GetPoints()+(pointstogive/2)) + end + end end end - end -end -end) -end) -end \ No newline at end of file + end) +end) \ No newline at end of file diff --git a/lua/autorun/server/sv_pointsaving.lua b/lua/autorun/server/sv_pointsaving.lua index 98e9600..db83c01 100644 --- a/lua/autorun/server/sv_pointsaving.lua +++ b/lua/autorun/server/sv_pointsaving.lua @@ -27,42 +27,50 @@ his email is jaxschellhorn@gmail.com ------------------------------------------------------------------- - +if engine.ActiveGamemode() ~= "zombiesurvival" then return end hook.Add("PlayerInitialSpawnRound", "ps_set", function(ply) -if gmod.GetGamemode().Name == "Zombie Survival" then -local cash = ply:GetPData("money") --Get the saved money amount - if cash == nil then --If it doesn't exist supply the player with the starting money amount - ply:SetPData("money", 100) --Save it - ply:SetMoney( 100 ) --Set it to the networked ints that can be called from the client too - --ply:SetDTInt(1,ply:GetMoney()) - else - ply:SetMoney( cash ) - + if gmod.GetGamemode().Name == "Zombie Survival" then + local cash = ply:GetPData("money") --Get the saved money amount + if cash == nil then -- If it doesn't exist supply the player with the starting money amount + ply:SetPData("money", 100) -- Save it + ply:SetMoney( 100 ) -- Set it to the networked ints that can be called from the client too + -- ply:SetDTInt(1,ply:GetMoney()) + else + ply:SetMoney( cash ) + + end end -end end) hook.Add("PlayerDeath", "ps_catch", function(ply) - -if (ply:Team() == TEAM_HUMAN and game.GetMap() ~= "zs_obj_gauntlet_v3" and game.GetMap() ~="zs_gauntlet_reborn_b6") and gmod.GetGamemode().Name == "Zombie Survival" then - ply:SetMoney(ply:GetPoints()) - --WriteData(ply:SteamID64(), ply:GetPoints()) - --PrintMessage(HUD_PRINTTALK,ply:GetDTInt(1)) - --PrintMessage(HUD_PRINTTALK,ply:GetMoney()) - ply:SaveMoney() - ply:SaveMoneyTXT() + if (ply:Team() == TEAM_HUMAN and game.GetMap() ~= "zs_obj_gauntlet_v3" and game.GetMap() ~="zs_gauntlet_reborn_b6") then + ply:SetMoney(ply:GetPoints()) + -- WriteData(ply:SteamID64(), ply:GetPoints()) + -- PrintMessage(HUD_PRINTTALK,ply:GetDTInt(1)) + -- PrintMessage(HUD_PRINTTALK,ply:GetMoney()) + ply:SaveMoney() + ply:SaveMoneyTXT() end end) --[[hook.Add("EndRound", "ps_save", function(winner) -print("end round hook") -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 - for k,ply in pairs(player.GetAll()) do - if ply:Team() == TEAM_HUMAN then - ply:SetMoney(ply:GetPoints()) - else + print("end round hook") + if (game.GetMap() ~= "zs_obj_gauntlet_v3" and game.GetMap() ~="zs_gauntlet_reborn_b6") then + if winner == TEAM_HUMAN then + for k,ply in pairs(player.GetAll()) do + if ply:Team() == TEAM_HUMAN then + ply:SetMoney(ply:GetPoints()) + else + if ply:GetPoints()- ply:GetMoney()> 0 then + ply:SetMoney(ply:GetPoints()+((ply:GetPoints()- ply:GetMoney())*.15)) + else + ply:SetMoney(ply:GetPoints()) + end + end + end + else + for k,ply in pairs(player.GetAll()) do if ply:GetPoints()- ply:GetMoney()> 0 then ply:SetMoney(ply:GetPoints()+((ply:GetPoints()- ply:GetMoney())*.15)) else @@ -70,22 +78,13 @@ if (game.GetMap() ~= "zs_obj_gauntlet_v3" and game.GetMap() ~="zs_gauntlet_rebor end end end - else - for k,ply in pairs(player.GetAll()) do - if ply:GetPoints()- ply:GetMoney()> 0 then - ply:SetMoney(ply:GetPoints()+((ply:GetPoints()- ply:GetMoney())*.15)) - else - ply:SetMoney(ply:GetPoints()) - end - end + end - -end end)]] hook.Add("PlayerDisconnected", "ps_disc", function(ply) - if (ply:Team() == TEAM_HUMAN and game.GetMap() ~= "zs_obj_gauntlet_v3" and game.GetMap() ~="zs_gauntlet_reborn_b6") and gmod.GetGamemode().Name == "Zombie Survival" then - --WriteData(ply:SteamID64(), ply:GetPoints()) + if (ply:Team() == TEAM_HUMAN and game.GetMap() ~= "zs_obj_gauntlet_v3" and game.GetMap() ~="zs_gauntlet_reborn_b6") then + -- WriteData(ply:SteamID64(), ply:GetPoints()) ply:SetMoney(ply:GetPoints()) ply:SaveMoney() ply:SaveMoneyTXT() @@ -94,9 +93,9 @@ hook.Add("PlayerDisconnected", "ps_disc", function(ply) end) hook.Add("PlayerRedeemed", "ps_redeem", function(ply) - --ply:SetPoints(ReadData(ply:SteamID64())) - --ply:SetMoney(ply:GetMoney()) - if (game.GetMap() ~= "zs_obj_gauntlet_v3" and game.GetMap() ~="zs_gauntlet_reborn_b6") and gmod.GetGamemode().Name == "Zombie Survival" then + -- ply:SetPoints(ReadData(ply:SteamID64())) + -- ply:SetMoney(ply:GetMoney()) + if (game.GetMap() ~= "zs_obj_gauntlet_v3" and game.GetMap() ~="zs_gauntlet_reborn_b6") then ply:SetPoints(ply:GetMoney()) end end) @@ -116,14 +115,12 @@ end) end end)]] ---ZSPS_Opt = CreateConVar("ZSPS_nosend", "0", FCVAR_ARCHIVE, "Opt out of the ZSPS server list"):GetBool() - - +-- ZSPS_Opt = CreateConVar("ZSPS_nosend", "0", FCVAR_ARCHIVE, "Opt out of the ZSPS server list"):GetBool() hook.Add("PlayerSpawn" , "spawnplayerpoints" ,function(pl) - if (pl:Team() == TEAM_HUMAN and game.GetMap() ~= "zs_obj_gauntlet_v3" and game.GetMap() ~="zs_gauntlet_reborn_b6") and gmod.GetGamemode().Name == "Zombie Survival" then + if (pl:Team() == TEAM_HUMAN and game.GetMap() ~= "zs_obj_gauntlet_v3" and game.GetMap() ~="zs_gauntlet_reborn_b6") then pl:SetPoints(pl:GetMoney()) - --pl:SetBegPoints(pl:GetDTInt(1)) + -- pl:SetBegPoints(pl:GetDTInt(1)) end end) --///////////////////////////////////////////////////////////////////// @@ -149,7 +146,7 @@ function meta:SaveMoneyTXT() end function meta:TakeMoney(amount) - --Add money function here + -- Add money function here self:AddMoney(-amount) end