Cleanup and change of gamemode detection

master
David Vogel 6 years ago
parent f305d28544
commit 8dc476fa69

@ -1,14 +1,12 @@
if engine.ActiveGamemode() ~= "zombiesurvival" then return end
if engine.ActiveGamemode() == "zombiesurvival" then
-- this code grabs the data from the file about the map. if none exists it makes a default. -- this code grabs the data from the file about the map. if none exists it makes a default.
timer.Simple(25,function() timer.Simple(25, function()
mapwins = 0 mapwins = 0
maploss = 0 maploss = 0
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()) local mapname = string.lower(game.GetMap())
if file.Exists("zsmapinfo/"..mapname..".txt", "DATA") then if file.Exists("zsmapinfo/"..mapname..".txt", "DATA") then
@ -26,46 +24,42 @@ maploss = 0
file.Write( "zsmapinfo/"..mapname..".txt", util.TableToJSON( main ) ) file.Write( "zsmapinfo/"..mapname..".txt", util.TableToJSON( main ) )
print("map win file not found. created one.") print("map win file not found. created one.")
end end
zombpercentcountmap = 0 zombpercentcountmap = 0
totpercentcountmap = 1 totpercentcountmap = 1
end) end)
-- this hook checks to make sure there are zombies on the server. later it should check to see if any are afk. -- this hook checks to make sure there are zombies on the server. later it should check to see if any are afk.
roundtime = 0 roundtime = 0
prereqcount = false prereqcount = false
hook.Add( "WaveStateChanged", "zombpercentcalc", function() hook.Add("WaveStateChanged", "zombpercentcalc", function()
roundtime = CurTime() roundtime = CurTime()
if !timer.Exists( "zombiepercentcalc" ) then if !timer.Exists("zombiepercentcalc") then
timer.Create( "zombiepercentcalc", 10, 0, function() timer.Create("zombiepercentcalc", 10, 0, function()
if #(team.GetPlayers(TEAM_UNDEAD)) >0 then if #(team.GetPlayers(TEAM_UNDEAD)) >0 then
zombpercentcountmap =zombpercentcountmap +1 zombpercentcountmap =zombpercentcountmap + 1
end end
totpercentcountmap = totpercentcountmap +1 totpercentcountmap = totpercentcountmap + 1
end) end)
end end
end) end)
hook.Add("EndRound","givedapoints",function(winner) hook.Add("EndRound", "givedapoints", function(winner)
timer.Destroy("zombiepercentcalc" ) timer.Destroy("zombiepercentcalc")
timer.Simple(0,function()
timer.Simple(0,function() print("point bonus hook")
print("point bonus hook") local mapname = string.lower(game.GetMap())
local mapname = string.lower(game.GetMap()) local zombiepercentcalcmap = (zombpercentcountmap/totpercentcountmap) or .01
local zombiepercentcalcmap = (zombpercentcountmap/totpercentcountmap) or .01 local mapplaytotal = mapwins + maploss
local mapplaytotal = mapwins + maploss local pointstogive = 10
local pointstogive = 10 zombiepercentcalcmap = zombiepercentcalcmap or .01
zombiepercentcalcmap = zombiepercentcalcmap or .01 -- we need to make sure that zombies were on the server for more than half the game.
-- we need to make sure that zombies were on the server for more than half the game. if zombiepercentcalcmap <=.5 then
if zombiepercentcalcmap <=.5 then PrintMessage(HUD_PRINTTALK,"No end of game points because zombies were not even playing half the time!")
PrintMessage(HUD_PRINTTALK,"No end of game points because zombies were not even playing half the time!") elseif mapplaytotal <= 5 then
elseif mapplaytotal <= 5 then --print(mapplaytotal)
--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.") 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 if winner == TEAM_UNDEAD then
maploss = maploss + 1 maploss = maploss + 1
@ -85,12 +79,7 @@ elseif mapplaytotal <= 5 then
main["mapboost"] = mapboost main["mapboost"] = mapboost
main["mapjackpot"] = mapjackpot main["mapjackpot"] = mapjackpot
file.Write( "zsmapinfo/"..mapname..".txt", util.TableToJSON( main ) ) file.Write( "zsmapinfo/"..mapname..".txt", util.TableToJSON( main ) )
else
else
if winner == TEAM_UNDEAD then if winner == TEAM_UNDEAD then
if mapjackpot <= 2500 then if mapjackpot <= 2500 then
mapjackpot = math.Round(mapjackpot*1.1) mapjackpot = math.Round(mapjackpot*1.1)
@ -124,6 +113,7 @@ else
else else
print("wow you fucked up!") print("wow you fucked up!")
end end
local main = {} local main = {}
main["mapwins"] = mapwins main["mapwins"] = mapwins
main["maploss"] = maploss main["maploss"] = maploss
@ -147,7 +137,7 @@ else
PrintMessage(HUD_PRINTTALK,"<c=204,204,0>Map jackpot is now "..(mapjackpot)..".</c>") PrintMessage(HUD_PRINTTALK,"<c=204,204,0>Map jackpot is now "..(mapjackpot)..".</c>")
--regular points ZS points --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 --[[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 for k,v in pairs(team.GetPlayers(TEAM_HUMAN)) do
v:SetMoney((v:GetDTInt(1) + pointstogive) ) v:SetMoney((v:GetDTInt(1) + pointstogive) )
--WriteData(v:SteamID64(), v:GetPoints()) --WriteData(v:SteamID64(), v:GetPoints())
@ -162,11 +152,10 @@ else
v:SaveMoneyTXT() v:SaveMoneyTXT()
v:PrintMessage(HUD_PRINTTALK,"<c=255,0,0>You gained "..(math.Round(pointstogive/2)).." points this round for playing to the end!</c>") 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]] 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 (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 for k,ply in pairs(player.GetAll()) do
if ply:Team() == TEAM_HUMAN then if ply:Team() == TEAM_HUMAN then
@ -181,7 +170,6 @@ if (game.GetMap() ~= "zs_obj_gauntlet_v3" and game.GetMap() ~="zs_gauntlet_rebor
ply:SaveMoneyTXT() ply:SaveMoneyTXT()
ply:PrintMessage(HUD_PRINTTALK,"<c=255,0,0>You gained "..(pointstogive).." this round for playing to the end!</c>") ply:PrintMessage(HUD_PRINTTALK,"<c=255,0,0>You gained "..(pointstogive).." this round for playing to the end!</c>")
end end
else else
if ply:GetPoints()- ply:GetMoney()> 0 then if ply:GetPoints()- ply:GetMoney()> 0 then
ply:SetMoney(ply:GetPoints()+((ply:GetPoints()- ply:GetMoney())*.15)+(pointstogive/2)) ply:SetMoney(ply:GetPoints()+((ply:GetPoints()- ply:GetMoney())*.15)+(pointstogive/2))
@ -205,7 +193,6 @@ if (game.GetMap() ~= "zs_obj_gauntlet_v3" and game.GetMap() ~="zs_gauntlet_rebor
end end
end end
end end
end end
end) end)
end) end)
end

@ -27,37 +27,36 @@ his email is jaxschellhorn@gmail.com
------------------------------------------------------------------- -------------------------------------------------------------------
if engine.ActiveGamemode() ~= "zombiesurvival" then return end
hook.Add("PlayerInitialSpawnRound", "ps_set", function(ply) hook.Add("PlayerInitialSpawnRound", "ps_set", function(ply)
if gmod.GetGamemode().Name == "Zombie Survival" then if gmod.GetGamemode().Name == "Zombie Survival" then
local cash = ply:GetPData("money") --Get the saved money amount 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 if cash == nil then -- If it doesn't exist supply the player with the starting money amount
ply:SetPData("money", 100) --Save it ply:SetPData("money", 100) -- Save it
ply:SetMoney( 100 ) --Set it to the networked ints that can be called from the client too ply:SetMoney( 100 ) -- Set it to the networked ints that can be called from the client too
--ply:SetDTInt(1,ply:GetMoney()) -- ply:SetDTInt(1,ply:GetMoney())
else else
ply:SetMoney( cash ) ply:SetMoney( cash )
end end
end end
end) end)
hook.Add("PlayerDeath", "ps_catch", function(ply) 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") then
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()) ply:SetMoney(ply:GetPoints())
--WriteData(ply:SteamID64(), ply:GetPoints()) -- WriteData(ply:SteamID64(), ply:GetPoints())
--PrintMessage(HUD_PRINTTALK,ply:GetDTInt(1)) -- PrintMessage(HUD_PRINTTALK,ply:GetDTInt(1))
--PrintMessage(HUD_PRINTTALK,ply:GetMoney()) -- PrintMessage(HUD_PRINTTALK,ply:GetMoney())
ply:SaveMoney() ply:SaveMoney()
ply:SaveMoneyTXT() ply:SaveMoneyTXT()
end end
end) end)
--[[hook.Add("EndRound", "ps_save", function(winner) --[[hook.Add("EndRound", "ps_save", function(winner)
print("end round hook") 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 (game.GetMap() ~= "zs_obj_gauntlet_v3" and game.GetMap() ~="zs_gauntlet_reborn_b6") then
if winner == TEAM_HUMAN then if winner == TEAM_HUMAN then
for k,ply in pairs(player.GetAll()) do for k,ply in pairs(player.GetAll()) do
if ply:Team() == TEAM_HUMAN then if ply:Team() == TEAM_HUMAN then
@ -80,12 +79,12 @@ if (game.GetMap() ~= "zs_obj_gauntlet_v3" and game.GetMap() ~="zs_gauntlet_rebor
end end
end end
end end
end)]] end)]]
hook.Add("PlayerDisconnected", "ps_disc", function(ply) 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 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()) -- WriteData(ply:SteamID64(), ply:GetPoints())
ply:SetMoney(ply:GetPoints()) ply:SetMoney(ply:GetPoints())
ply:SaveMoney() ply:SaveMoney()
ply:SaveMoneyTXT() ply:SaveMoneyTXT()
@ -94,9 +93,9 @@ hook.Add("PlayerDisconnected", "ps_disc", function(ply)
end) end)
hook.Add("PlayerRedeemed", "ps_redeem", function(ply) hook.Add("PlayerRedeemed", "ps_redeem", function(ply)
--ply:SetPoints(ReadData(ply:SteamID64())) -- ply:SetPoints(ReadData(ply:SteamID64()))
--ply:SetMoney(ply:GetMoney()) -- 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 if (game.GetMap() ~= "zs_obj_gauntlet_v3" and game.GetMap() ~="zs_gauntlet_reborn_b6") then
ply:SetPoints(ply:GetMoney()) ply:SetPoints(ply:GetMoney())
end end
end) end)
@ -116,14 +115,12 @@ end)
end 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) 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:SetPoints(pl:GetMoney())
--pl:SetBegPoints(pl:GetDTInt(1)) -- pl:SetBegPoints(pl:GetDTInt(1))
end end
end) end)
--///////////////////////////////////////////////////////////////////// --/////////////////////////////////////////////////////////////////////
@ -149,7 +146,7 @@ function meta:SaveMoneyTXT()
end end
function meta:TakeMoney(amount) function meta:TakeMoney(amount)
--Add money function here -- Add money function here
self:AddMoney(-amount) self:AddMoney(-amount)
end end

Loading…
Cancel
Save