Refactoring and cleanup
- sv_pointsaving got basically completely rewritten - Rename money to SavedPoints
This commit is contained in:
parent
8dc476fa69
commit
37661dfa68
@ -139,17 +139,13 @@ hook.Add("EndRound", "givedapoints", function(winner)
|
||||
--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) )
|
||||
v:SetSavedPoints((v:GetDTInt(1) + pointstogive) )
|
||||
--WriteData(v:SteamID64(), v:GetPoints())
|
||||
v:SaveMoney()
|
||||
v:SaveMoneyTXT()
|
||||
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:SetMoney(math.Round((v:GetMoney() + (pointstogive/5)) ))
|
||||
v:SetSavedPoints(math.Round((v:GetSavedPoints() + (pointstogive/5)) ))
|
||||
--WriteData(v:SteamID64(), v:GetPoints())
|
||||
v:SaveMoney()
|
||||
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>")
|
||||
end
|
||||
end]]
|
||||
@ -159,37 +155,29 @@ hook.Add("EndRound", "givedapoints", function(winner)
|
||||
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()
|
||||
if ply:GetPoints()- ply:GetSavedPoints()> 0 then
|
||||
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
|
||||
ply:SetMoney(ply:GetPoints()+pointstogive)
|
||||
ply:SaveMoney()
|
||||
ply:SaveMoneyTXT()
|
||||
ply:SetSavedPoints(ply:GetPoints()+pointstogive)
|
||||
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:GetMoney()> 0 then
|
||||
ply:SetMoney(ply:GetPoints()+((ply:GetPoints()- ply:GetMoney())*.15)+(pointstogive/2))
|
||||
ply:SaveMoney()
|
||||
ply:SaveMoneyTXT()
|
||||
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:SetMoney(ply:GetPoints()+(pointstogive/2))
|
||||
ply:SaveMoney()
|
||||
ply:SaveMoneyTXT()
|
||||
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:GetMoney()> 0 then
|
||||
ply:SetMoney(ply:GetPoints()+((ply:GetPoints()- ply:GetMoney())*.15)+(pointstogive/2))
|
||||
if ply:GetPoints()- ply:GetSavedPoints()> 0 then
|
||||
ply:SetSavedPoints(ply:GetPoints()+((ply:GetPoints()- ply:GetSavedPoints())*.15)+(pointstogive/2))
|
||||
else
|
||||
ply:SetMoney(ply:GetPoints()+(pointstogive/2))
|
||||
ply:SetSavedPoints(ply:GetPoints()+(pointstogive/2))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,155 +1,75 @@
|
||||
--[[
|
||||
JAXJAXK LICENSE
|
||||
VERSION 1.0
|
||||
Copyright 9/24/2015
|
||||
|
||||
copy, upload or distribution of this license is allowed however no one is to change the original text with exception of jaxjaxk ( the creator).
|
||||
|
||||
the contents of this addon are strictly off limits to hells gamers or anyone affiliated with hells gamers.
|
||||
legal action will be taken against anyone who does not comply with the terms and conditions of this addon
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
1) this addon is not permitted on any servers that are hells gamers or a affiliated with hells gamers.
|
||||
2) you are free to us the code as a reference as to how to solve problems however you are not permitted to copy the code without the permission of jaxjaxk ( the creator). further more hells gamers is not permited to even look at the code.
|
||||
3) modification to the code is permitted by anyone that is not affiliated with hells gamers.
|
||||
4) you will not modify the code in any way that directly or indirectly generates revenue/money without the express permission of jaxjaxk ( the creator)
|
||||
5) jaxjaxk ( the creator)has the right to have this addon removed from your server at any time for any reason. you are useing his addon, do not abuse it.
|
||||
6) if you do not agree to any of the above conditions you must delete the addon and any files affiliated with the addon in its entirety as well of any dirivitives of the files or content.
|
||||
|
||||
tl;dr - don't screw with me and I won't screw with you. it brings joy when people use my addon, don't abuse it.
|
||||
|
||||
INFORMATION
|
||||
jaxjaxk ( present username) created this addon.
|
||||
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 )
|
||||
local settings = {
|
||||
StartingSavedPoints = 100,
|
||||
IgnoredMaps = { -- Use $ at the end if you want to define exact map names with versions. (Otherwise it will match with all maps beginning with the given name)
|
||||
"zs_obj_gauntlet",
|
||||
"zs_gauntlet_reborn"
|
||||
}
|
||||
}
|
||||
|
||||
local function shouldIgnoreMap(mapName)
|
||||
for k, v in ipairs(settings.IgnoredMaps) do
|
||||
if string.match(mapName, "^"..v) then return true end
|
||||
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") 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)
|
||||
local function savePoints(ply)
|
||||
if shouldIgnoreMap(game.GetMap()) then return 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") 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
|
||||
ply:SetMoney(ply:GetPoints())
|
||||
print("### PS Saved: "..ply:GetPoints())
|
||||
ply:SetSavedPoints(ply:GetPoints())
|
||||
end
|
||||
end
|
||||
hook.Add("PlayerDeath", "pointsave_death", savePoints)
|
||||
hook.Add("PlayerDisconnected", "pointsave_disconnect", savePoints)
|
||||
|
||||
local function loadPoints(ply)
|
||||
if shouldIgnoreMap(game.GetMap()) then return end
|
||||
|
||||
timer.Simple(0, function()
|
||||
if IsValid(ply) and ply:Team() == TEAM_HUMAN then
|
||||
print("### Loaded: "..ply:GetSavedPoints())
|
||||
ply:SetPoints(ply:GetSavedPoints())
|
||||
end
|
||||
end)
|
||||
|
||||
end
|
||||
hook.Add("PlayerSpawn", "pointsave_spawn", loadPoints)
|
||||
hook.Add("PlayerReadyRound", "pointsave_readyround", loadPoints) -- Fix for ZS:R. Problem: It can be called from client!
|
||||
|
||||
-- #### Player meta ####
|
||||
|
||||
local meta = FindMetaTable("Player") -- Get the meta table of player
|
||||
|
||||
-- Shared methods
|
||||
|
||||
function meta:GetSavedPoints()
|
||||
if SERVER then
|
||||
local points = self:GetPData("zs_savedpoints", settings.StartingSavedPoints)
|
||||
self:SetNWInt("zs_savedpoints", points)
|
||||
return points
|
||||
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") then
|
||||
-- WriteData(ply:SteamID64(), ply:GetPoints())
|
||||
ply:SetMoney(ply:GetPoints())
|
||||
ply:SaveMoney()
|
||||
ply:SaveMoneyTXT()
|
||||
|
||||
end
|
||||
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") then
|
||||
ply:SetPoints(ply:GetMoney())
|
||||
end
|
||||
end)
|
||||
|
||||
--[[concommand.Add("admin_set_points_save", function(ply, cmd, args, argsS)
|
||||
if args and args[1] and args[2] and tonumber(args[2]) then
|
||||
local foundply
|
||||
for k, v in pairs(player.GetAll()) do
|
||||
if string.find(string.lower(v:Name()), args[1]) then
|
||||
foundply = v
|
||||
end
|
||||
end
|
||||
|
||||
if foundply then
|
||||
foundply:SetPoints(tonumber(args[2]))
|
||||
end
|
||||
end
|
||||
end)]]
|
||||
|
||||
-- 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") then
|
||||
pl:SetPoints(pl:GetMoney())
|
||||
-- pl:SetBegPoints(pl:GetDTInt(1))
|
||||
end
|
||||
end)
|
||||
--/////////////////////////////////////////////////////////////////////
|
||||
local meta = FindMetaTable("Player") --Get the meta table of player
|
||||
|
||||
function meta:AddMoney(amount)
|
||||
local current_cash = self:GetMoney()
|
||||
self:SetMoney( current_cash + amount )
|
||||
return self:GetNWInt("zs_savedpoints", settings.StartingSavedPoints)
|
||||
end
|
||||
|
||||
function meta:SetMoney(amount)
|
||||
self:SetNetworkedInt( "Money", amount )
|
||||
self:SaveMoney()
|
||||
if not SERVER then return end
|
||||
|
||||
-- Server side methods
|
||||
|
||||
function meta:SetSavedPoints(amount)
|
||||
self:SetNWInt("zs_savedpoints", amount)
|
||||
self:SetPData("zs_savedpoints", amount)
|
||||
end
|
||||
|
||||
function meta:SaveMoney()
|
||||
local cash = self:GetMoney()
|
||||
self:SetPData("money", cash)
|
||||
function meta:AddSavedPoints(amount)
|
||||
local points = self:GetSavedPoints()
|
||||
self:SetSavedPoints(points + amount)
|
||||
end
|
||||
|
||||
function meta:SaveMoneyTXT()
|
||||
file.Write(gmod.GetGamemode().Name .."/Money/".. string.gsub(self:SteamID(), ":", "_") ..".txt", self:GetMoney())
|
||||
end
|
||||
|
||||
function meta:TakeMoney(amount)
|
||||
-- Add money function here
|
||||
self:AddMoney(-amount)
|
||||
end
|
||||
|
||||
function meta:GetMoney()
|
||||
return self:GetNetworkedInt( "Money" )
|
||||
function meta:TakeSavedPoints(amount)
|
||||
self:AddSavedPoints(-amount)
|
||||
end
|
Loading…
Reference in New Issue
Block a user