Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Version = "1.0.7"
- --[[
- THIS IS NOT A CONFIGURATION FILE, USE config.lua!
- You shouldn't need to edit this file unless you know what you are doing, or have contacted me.
- Changing something in here could break the entire Skill Point system.
- Avaliable Functions:
- ST_ValidateAmt(amt) -- Validates the given points are valid.
- Player:ST_GetLevel() -- returns the players number.
- Player:ST_SetSkills() --Sets the clients skills (e.g setting their jump height on spawn), currently called with PlayerSpawn hook.
- -- Player Networking --
- Player:ST_GetSkills() --Syncs the client with the server for their Levels/XP and Skill Points
- -- Player XP Functions --
- Player:ST_GiveXP(amt) --Give Set amount of XP
- Player:ST_TakeXP(amt) --Take Set amount of XP
- Player:ST_CheckXP() --Checks if the players XP is enough to gain the next level
- -- Player Skill Point Functions --
- Player:ST_GiveSkillPoints(amt) --Give set amount of Skill Points
- Player:ST_TakeSkillPoints(amt) --Take set amount of Skill Points
- ]]--
- include("config.lua")
- local Player = FindMetaTable('Player')
- local MenuKey = {}
- MenuKey["F1"] = "ShowHelp"
- MenuKey["F2"] = "ShowTeam"
- MenuKey["F3"] = "ShowSpare1"
- MenuKey["F4"] = "ShowSpare2"
- local Skills = {
- { Name = "Jump", Value = 0, Icon = "materials/jump2.png" },
- { Name = "Speed", Value = 0, Icon = "materials/speed2.png"},
- { Name = "Health", Value = 0, Icon = "materials/health2.png"},
- { Name = "Armor", Value = 0, Icon = "materials/defense2.png"},
- }
- Level = {}
- for i=0, 100 do Level[i] = math.Round(30*math.pow(i,ST_DifMul)) end
- --[[ Network Strings, needed and shouldn't be touched ]]--
- util.AddNetworkString('ST_Menu')
- util.AddNetworkString('ST_SkillPoints')
- util.AddNetworkString('ST_Skills')
- util.AddNetworkString('ST_SpentPoint')
- util.AddNetworkString('ST_RemovePoint')
- util.AddNetworkString('ST_SendAll')
- util.AddNetworkString('ST_Notification')
- util.AddNetworkString('ST_Ding')
- hook.Add("PlayerInitialSpawn", "STInitialSpawn", function(ply)
- PlayerJumpHeight = ply:GetJumpPower()
- PlayerRunSpeed = ply:GetRunSpeed()
- ply:ST_GetSkills()
- ply:ST_GiveXPTime()
- SendAllLevels()
- end)
- hook.Add("PlayerConnect", "UpdateLevels", function() SendAllLevels() end)
- hook.Add(MenuKey[ST_MenuKey], "ST_Menu", function(ply) ply:ST_Menu() end)
- hook.Add("ST_LevelUp", "UpdateLevels", function(ply, level) print(ply, level) end)
- hook.Add("PlayerSpawn", "SetSkills", function(ply) ply:ST_SetSkills() end)
- if ST_TAKED then
- hook.Add("PlayerDeath", "TakeXPOnDeath", function(ply,inflictor,attacker) ply:ST_TakeXP(ST_DAMT) end)
- end
- --if ST_NPCK then
- -- hook.Add("OnNPCKilled", "TakeXPOnDeath", function(npc,ply,inflictor) ply:ST_GiveXP(ST_NPCKAMT) end)
- --end
- net.Receive('ST_SpentPoint', function(length, ply)
- ply:ST_TakeSkillPoints(net.ReadInt(2))
- ply:ST_UpdateSkillTable(net.ReadInt(5), net.ReadInt(5))
- end)
- net.Receive('ST_RemovePoint', function(length, ply)
- ply:ST_GiveSkillPoints(net.ReadInt(2))
- ply:ST_UpdateSkillTable(net.ReadInt(5), net.ReadInt(5))
- end)
- function Player:ST_Notification(msg, type, time)
- net.Start('ST_Notification')
- net.WriteString(msg)
- net.WriteString(type)
- net.WriteInt(time, 32)
- net.Send(self)
- end
- --[[ Starts the net message to open the menu ]]--
- function Player:ST_Menu()
- net.Start('ST_Menu')
- net.Send(self)
- end
- --[[ Validates that the given points is a valid number, should be used anywhere when setting points ]]--
- function ST_ValidateAmt(amt)
- if (tonumber(amt) == nil or amt < 0) then --We want to make sure it's a valid number and is not below 0
- amt = 0 --If it's invalid or below 0, we will just set the points to 0
- end
- return math.floor(amt) --Stops us having decimal numbers
- end
- function Player:ST_GetLevel()
- return self.ST_Level
- end
- --[[
- XP System
- ]]--
- function Player:ST_GiveXP(amt)
- self.ST_XPAmt = self.ST_XPAmt + ST_ValidateAmt(amt)
- self:SetPData("ST_XPAmt", self.ST_XPAmt) --Save the players skill points on the server db
- self:ST_UpdatePoints() --Update client with his new amount of skill points
- self:ST_CheckXP()
- self:ST_Notification("Gained "..amt.." XP!", "general", 3)
- end
- function Player:ST_TakeXP(amt)
- self.ST_XPAmt = self.ST_XPAmt - ST_ValidateAmt(amt)
- self:SetPData("ST_XPAmt", self.ST_XPAmt) --Save the players skill points on the server db
- self:ST_UpdatePoints() --Update client with his new amount of skill points
- self:ST_CheckXP()
- self:ST_Notification("Lost "..amt.." XP!", "general", 3)
- end
- function Player:ST_SetXP(amt)
- self.ST_XPAmt = ST_ValidateAmt(amt)
- self:SetPData("ST_XPAmt", self.ST_XPAmt) --Save the players skill points on the server db
- self:ST_UpdatePoints() --Update client with his new amount of skill points
- self:ST_CheckXP()
- end
- function Player:ST_CheckXP()
- if self.ST_XPAmt >= Level[tonumber(self.ST_Level)] then
- self:ST_GiveSkillPoints(1)
- if self.ST_XPAmt > Level[tonumber(self.ST_Level)] then
- self:ST_SetXP(self.ST_XPAmt - Level[tonumber(self.ST_Level)])
- else
- self:ST_SetXP(0)
- end
- self.ST_Level = self.ST_Level + 1
- self:SetPData("ST_Level", self.ST_Level + 1) --Save the players skill points on the server db
- self.ST_XPNeed = Level[tonumber(self.ST_Level)]
- net.Start('ST_Ding')
- net.Send(self)
- self:ST_UpdatePoints() --Update client with his new amount of skill points
- self:ST_Notification("Leveled Up!", "general", 3)
- hook.Call( "ST_LevelUp", nil, self:Nick(), self.ST_Level)
- elseif self.ST_XPAmt < 0 then
- if tonumber(self.ST_SkillPoints) > 0 then
- self:ST_TakeSkillPoints(1)
- end
- if tonumber(self.ST_Level) > 2 then
- self.ST_Level = self.ST_Level - 1
- self:SetPData("ST_Level", self.ST_Level - 1)
- self:ST_Notification("Lost A Level!", "general", 3)
- end
- self.ST_XPNeed = Level[tonumber(self.ST_Level)]
- self:ST_SetXP(self.ST_XPNeed + self.ST_XPAmt)
- hook.Call( "ST_LevelUp", nil, self:Nick(), self.ST_Level)
- end
- end
- --[[
- Skill Points
- ]]--
- function Player:ST_GiveSkillPoints(amt)
- self.ST_SkillPoints = self.ST_SkillPoints + ST_ValidateAmt(amt)
- self:SetPData("ST_SkillPoints", self.ST_SkillPoints) --Save the players skill points on the server db
- self:ST_UpdatePoints() --Update client with his new amount of skill points
- self:ST_Notification("Gained "..amt.." Skill Point(s)!", "general", 3)
- end
- function Player:ST_TakeSkillPoints(amt)
- self.ST_SkillPoints = self.ST_SkillPoints - ST_ValidateAmt(amt)
- self:SetPData("ST_SkillPoints", self.ST_SkillPoints)
- self:ST_UpdatePoints()
- self:ST_Notification("Spent "..amt.." Skill Point(s)!", "general", 3)
- end
- --[[
- Networking for Skill Points, Levels and skills.
- ]]--
- function Player:ST_UpdateSkillTable(skill, value)
- self.ST_Skills[skill].Value = value
- self:SetPData("ST_Skills", util.TableToJSON(self.ST_Skills))
- end
- function Player:ST_UpdatePoints()
- net.Start('ST_SkillPoints')
- net.WriteEntity(self)
- net.WriteInt(self.ST_SkillPoints, 32)
- net.WriteInt(self.ST_XPAmt, 32)
- net.WriteInt(self.ST_Level, 32)
- net.WriteInt(self.ST_XPNeed or 0, 32)
- net.Send(self)
- SendAllLevels()
- end
- function Player:ST_UpdateSkills()
- net.Start('ST_Skills')
- net.WriteEntity(self)
- net.WriteTable(self.ST_Skills)
- net.Send(self)
- end
- function SendAllLevels()
- for k,ply in pairs(player.GetAll()) do
- ST_SendAll(ply)
- end
- end
- function ST_SendAll(ply)
- net.Start('ST_SendAll')
- net.WriteEntity(ply)
- net.WriteInt(ply.ST_Level, 32)
- net.Broadcast()
- end
- function Player:ST_GiveXPTime()
- if ST_XPOnPlay then
- timer.Create(self:UniqueID(), ST_XPPlayTime * 60, 0, function() self:ST_GiveXP(ST_XPPlayAmt) end)
- local function RemoveTimer(ply)
- timer.Remove(ply:UniqueID())
- end
- hook.Add("PlayerDisconnected", "RemoveTimerOnLeave", RemoveTimer)
- end
- end
- function Player:ST_GetSkills()
- if self:GetPData("ST_Skills", "nil") == "nil" then
- self:SetPData("ST_Skills", util.TableToJSON(Skills))
- end
- self.ST_SkillPoints = self:GetPData("ST_SkillPoints", 1)
- self.ST_Skills = util.JSONToTable(self:GetPData("ST_Skills"))
- self.ST_XPAmt = self:GetPData("ST_XPAmt", 0)
- self.ST_Level = self:GetPData("ST_Level", 1)
- self.ST_XPNeed = Level[tonumber(self.ST_Level)]
- self:ST_UpdatePoints()
- self:ST_UpdateSkills()
- SendAllLevels()
- end
- local NPC_XPGain = {}
- NPC_XPGain["npc_dwarven_spider"] = 25
- NPC_XPGain["npc_draugr"] = 35
- NPC_XPGain["npc_mudcrab"] = 5
- NPC_XPGain["npc_dragon_paarthurnax"] = 100
- NPC_XPGain["npc_dwarven_centurion"] = 250
- NPC_XPGain["npc_dwarven_sphere"] = 105
- NPC_XPGain["npc_mudcrab_legendary"] = 75
- NPC_XPGain["npc_draugr_deathlord"] = 75
- --NPC_XPGain["npc_headcrab_black"] = 9
- NPC_XPGain["npc_zombie"] = 7000
- --NPC_XPGain["npc_antlionguard"] = 1500
- NPC_XPGain["default"] = 5
- -- Start Killing NPC Exp Gain
- function EXPGainNpc(npc, killer, weapon)
- if killer:IsPlayer() and npc:IsNPC() then
- local NPCExpGained = NPC_XPGain[npc:GetClass()] or NPC_XPGain["default"] or 5
- killer:ST_GiveXP(NPCExpGained)
- -- Exp Gain Complete
- end
- end
- hook.Add( "OnNPCKilled", "NpcExpGain", EXPGainNpc )
- -- End Killing NPC Exp Gain
- function Player:ST_SetSkills()
- timer.Simple( 1,
- function()
- self:SetHealth(self:Health() + self.ST_Skills[3].Value * 2)
- self:SetRunSpeed(PlayerRunSpeed + self.ST_Skills[2].Value * 2)
- self:SetArmor(self:Armor() + self.ST_Skills[4].Value * 2)
- self:SetJumpPower(PlayerJumpHeight + self.ST_Skills[1].Value * 5)
- end)
- end
- function XPOnKill( victim, killer, weapon )
- if ST_XPOnKill and killer:IsPlayer() and killer != victim then
- killer:ST_GiveXP(ST_XPAmtOnKill)
- end
- end
- hook.Add( "PlayerDeath", "GiveXPOnKill", XPOnKill )
- local function CheckForGamemodes()
- if engine.ActiveGamemode() == "terrortown" then
- print("ST Detected Trouble in Terrorist Town!")
- hook.Add("TTTBeginRound", "SetSkills", function() for _,ply in pairs(player.GetAll()) do ply:ST_SetSkills() end end)
- function TTTXPOnWin(result)
- if ST_TTTWin then
- if result == WIN_TRAITOR then
- for k,ply in pairs(player.GetAll()) do
- if ply:IsTraitor() and ply:Alive() then
- ply:ST_GiveXP(ST_TTTAmt)
- end
- end
- elseif result == WIN_TIMELIMIT or result == WIN_INNOCENT then
- for k,ply in pairs(player.GetAll()) do
- if !(ply:IsTraitor() and ply:Alive()) then
- ply:ST_GiveXP(ST_TTTAmt)
- end
- end
- end
- end
- end
- hook.Add("TTTEndRound", "GiveXPOnWin", TTTXPOnWin)
- elseif engine.ActiveGamemode() == "zombiesurvival" then
- print("ST Detected Zombie Survival!")
- local function GetWinner(winner)
- for _,ply in pairs(team.GetPlayers(winner)) do
- if ply:Alive() and ST_ZMWAMT != 0 then
- ply:ST_GiveXP(ST_ZMWAMT)
- end
- end
- end
- hook.Add( "PostEndRound", "GetWinner", GetWinner )
- local function HumanKilledZombie(victim, attacker, dmginfo, assister, assistfrags, headshot)
- if ST_ZMHAMT != 0 then
- attacker:ST_GiveXP(ST_ZMHAMT)
- end
- end
- hook.Add( "PostHumanKilledZombie", "Human Killed a Zombie", HumanKilledZombie )
- local function ZombieKilledHuman(victim, attacker, dmginfo, headshot, wassuicide)
- if ST_ZMZAMT != 0 then
- attacker:ST_GiveXP(ST_ZMZAMT)
- end
- end
- hook.Add( "PostZombieKilledHuman", "Zombie Killed a Human", ZombieKilledHuman )
- local function PlayerRedeemed(ply)
- if ST_ZMRAMT != 0 then
- ply:ST_GiveXP(ST_ZMRAMT)
- end
- end
- hook.Add( "PlayerRedeemed", "Player Redeemed", PlayerRedeemed )
- elseif engine.ActiveGamemode() == "deathrun" then
- function GetWinner()
- if round == ROUND_ENDING then
- if winner != 123 then
- for _,ply in pairs(team.GetPlayers(winner)) do
- if ply:Alive() then
- ply:ST_GiveXP(ST_DRWAMT)
- end
- end
- end
- end
- end
- hook.Add( "OnRoundSet", "GetRoundWinner", GetWinner)
- end
- timer.Simple(5, function() ST_CheckVersion() end)
- end
- hook.Add( "Initialize", "Check for gamemodes", CheckForGamemodes )
- --[[
- This should only be ran to clear ALL saved stats, irriversable unless you have backed up sv.db
- This also only clears current connected players stats.
- ]]--
- function ClearSkills(pl,command,args)
- if pl:IsAdmin() then
- for k,ply in pairs(player.GetAll()) do
- ply:RemovePData("ST_SkillPoints")
- ply:RemovePData("ST_Skills")
- ply:RemovePData("ST_XPAmt")
- ply:RemovePData("ST_Level")
- ply:ST_GetSkills()
- end
- pl:SendLua( "MsgC( Color( 0, 255, 0 ), \"Cleared All Player Skills\\n\" )")
- MsgC(Color(255,0,0,255),pl:Nick() .. "("..pl:SteamID()..") Cleared ALL Player Skills")
- end
- end
- concommand.Add("ST_ResetServerSkills",ClearSkills)
- function ST_ResetPlayer(pl,command,args)
- if pl:IsAdmin() then
- if args[1] then
- for k,ply in pairs(player.GetAll()) do
- if args[1] == tostring(ply:SteamID()) then
- ply:RemovePData("ST_SkillPoints")
- ply:RemovePData("ST_Skills")
- ply:RemovePData("ST_XPAmt")
- ply:RemovePData("ST_Level")
- ply:ST_GetSkills()
- pl:SendLua( "MsgC( Color( 0, 255, 0 ), \"Cleared Players Skills\\n\" )")
- MsgC(Color(255,0,0,255), ply:Nick() .. "("..ply:SteamID()..") had his skills cleared by admin ".. pl:Nick() .. "("..pl:SteamID()..")")
- end
- end
- else
- pl:SendLua( "MsgC( Color( 255, 0, 0 ), \"SteamID Required!\\n\" )")
- end
- end
- end
- concommand.Add("ST_ResetPlayerSkills",ST_ResetPlayer)
- function GiveXP(pl,command,args)
- if pl:IsAdmin() then
- for k,ply in pairs(player.GetAll()) do
- if args[1] == tostring(ply:SteamID()) then
- ply:ST_GiveXP(tonumber(args[2]))
- pl:ChatPrint("Gave " .. args[2] .. " XP to " .. ply:Nick())
- end
- end
- end
- end
- concommand.Add("ST_GiveXP",GiveXP)
- function TakeXP(pl,command,args)
- if pl:IsAdmin() then
- for k,ply in pairs(player.GetAll()) do
- if args[1] == tostring(ply:SteamID()) then
- ply:ST_TakeXP(tonumber(args[2]))
- pl:ChatPrint("Took " .. args[2] .. " XP to " .. ply:Nick())
- end
- end
- end
- end
- concommand.Add("ST_TakeXP",TakeXP)
- function ST_GETGAMEMODE(ply,command,args)
- ply:ChatPrint(engine.ActiveGamemode())
- end
- concommand.Add("ST_Getgamemode",ST_GETGAMEMODE)
- --Check for version of SkillTree
- function ST_CheckVersion()
- http.Fetch( "https://dl.dropboxusercontent.com/u/4331988/STVersion.html",
- function( body, len, headers, code )
- if body != Version then
- MsgC( Color( 255, 0, 0 ), "SkillTree Outdated! Newest Version is " .. body .."\n" )
- else
- MsgC( Color( 0, 255, 0 ), "SkillTree Up To Date!\n" )
- end
- end,
- function( error )
- print("Unable to fetch SkillTree Version!")
- end
- )
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement