AddCSLuaFile("client/exp_pointsmenu.lua")
AddCSLuaFile("client/exp_hud.lua")
-- Start System Vars.
local UpKeep = 50 -- How much added exp is added each level.
local PointsGained = 3 -- How many skill points players get each level up.
local ExpGained = 10 -- How much exp you get for killing an npc.
local ExpGained_Player = 25 -- How much exp you get for killing an fellow player.
-- End System Vars.
-- Start Skill Vars.
local MaxHpGain = 5 -- How much health is added onto players max hp when they buy 1 point of Max Hp Skill.
local MaxArmorGain = 5 -- How much armor is added onto players max armor when they buy 1 point of Max Armor Skill.
local RegTimeVar = 0.08 -- How fast the player regens hp, How much is given each buy of the skill, Higher = Faster, Lower = slower.
local RegArmTimeVar = 0.05 -- How fast the player regens armor, How much is given each buy of the skill, Higher = Faster, Lower = slower.
local ResistanceVar = 0.2 -- How much damage X is taken off the player for each resistance skill he/she has, dont set this higher than 0.09 or else players will be invincible at level 10 of this skill.
local JumpPowerVar = 25 -- How much extra power is added to the players jump, Try not to exceed 50 for this.
-- Start Spawn Functions
function EXPSetVarsOnSpawn(pl)
if pl:GetNWInt("Skill_HP") >= 1 then
pl:SetMaxHealth(100 + MaxHpGain*pl:GetNWInt("Skill_HP"))
pl:SetHealth(pl:GetMaxHealth())
end
if pl:GetNWInt("Skill_ARMOR") >= 1 then
pl:SetArmor(0 + MaxArmorGain*pl:GetNWInt("Skill_ARMOR"))
pl.MaxArmor = (100 + MaxArmorGain*pl:GetNWInt("Skill_ARMOR"))
else
pl.MaxArmor = 100
end
if pl:GetNWInt("Skill_REGEN") >= 1 then
pl.RegTime = (RegTimeVar*pl:GetNWInt("Skill_REGEN"))
else
pl.RegTime = 0
end
if pl:GetNWInt("Skill_ARMREGEN") >= 1 then
pl.RegArmTime = (RegArmTimeVar*pl:GetNWInt("Skill_ARMREGEN"))
else
pl.RegArmTime = 0
end
if pl:GetNWInt("Skill_JUMP") >= 1 then
pl:SetJumpPower(160 + JumpPowerVar*pl:GetNWInt("Skill_JUMP"))
end
if pl:GetNWInt("Skill_RESISTANCE") >= 1 then
pl.Resistance = (1 - ResistanceVar*pl:GetNWInt("Skill_RESIST"))
else
pl.Resistance = 1
end
end
hook.Add( "PlayerSpawn", "Set Vars On Spawn", EXPSetVarsOnSpawn )
-- End Spawn Functions
-- Start Regen Function
function DoHPThink()
for k,v in pairs (player.GetAll()) do
if v.WaitTime == nil then v.WaitTime = 4 end
if v.lastHit == nil then v.lastHit = CurTime() end
if v.lastHeal == nil then v.lastHeal = CurTime() end
if CurTime() - v.lastHit > v.WaitTime then
if v:Health () != math.floor (math.ceil (v:Health () / v:GetMaxHealth()) * v:GetMaxHealth()) and CurTime() - v.lastHeal > 1/v.RegTime then
v:SetHealth (v:Health() + 1)
v.lastHeal = CurTime()
end
end
v.lastHealth = v:Health()
end
end
hook.Add ("Think", "hB.T", DoHPThink)
function MehFace (pl)
pl.lastHit = CurTime()
end
hook.Add ("PlayerHurt", "hB.PH", MehFace)
-- End Regen Function
-- Start Resistance Function
function ResistanceScale( ent, inflictor, attacker, amount, dmginfo )
if ent:IsPlayer() then
dmginfo:ScaleDamage( ent.Resistance )
end
end
hook.Add("EntityTakeDamage","ScaleResistanceDamage",ResistanceScale)
-- End Resistance Function
-- Start Armor Regen Function
function DoArmorThink()
for k,v in pairs (player.GetAll()) do
if v.WaitTimeA == nil then v.WaitTimeA = 4 end
if v.lastHitA == nil then v.lastHitA = CurTime() end
if v.lastHealA == nil then v.lastHealA = CurTime() end
if CurTime() - v.lastHitA > v.WaitTimeA then
if v:Armor() <= v.MaxArmor - 1 and CurTime() - v.lastHealA > 1/v.RegArmTime then
v:SetArmor (v:Armor() + 1)
v.lastHealA = CurTime()
end
end
v.lastArmor = v:Armor()
end
end
hook.Add ("Think", "AB.T", DoArmorThink)
function MehFace2(pl)
pl.lastHitA = CurTime()
end
hook.Add ("PlayerHurt", "AB.PH", MehFace2)
-- End Armor Regen Function
-- Start Buy Commands
function MaxHpBuy(pl)
if pl:GetNWInt("SkillPoints") <= 0 then return false end
if pl:GetNWInt("Skill_HP") >= 15 then return false end
pl:SetNWInt("Skill_HP",pl:GetNWInt("Skill_HP") + 1)
pl:SetMaxHealth(pl:GetMaxHealth() + MaxHpGain)
pl:SetHealth(pl:Health() + MaxHpGain)
pl:SetNWInt("SkillPoints",pl:GetNWInt("SkillPoints") - 1)
file.Write("exp/"..pl:UniqueID().."_skill_hp.txt", pl:GetNWInt("Skill_HP"))
file.Write("exp/"..pl:UniqueID().."_skillpoints.txt", pl:GetNWInt("SkillPoints"))
end
concommand.Add( "skill1buy",MaxHpBuy )
function MaxArmorBuy(pl)
if pl:GetNWInt("SkillPoints") <= 0 then return false end
pl:SetNWInt("Skill_ARMOR",pl:GetNWInt("Skill_ARMOR") + 1)
pl:SetArmor(pl:Armor() + MaxArmorGain)
pl.MaxArmor = pl.MaxArmor + MaxArmorGain
pl:SetNWInt("SkillPoints",pl:GetNWInt("SkillPoints") - 1)
file.Write("exp/"..pl:UniqueID().."_skill_armor.txt", pl:GetNWInt("Skill_ARMOR"))
file.Write("exp/"..pl:UniqueID().."_skillpoints.txt", pl:GetNWInt("SkillPoints"))
end
concommand.Add( "skill2buy",MaxArmorBuy )
function RegenBuy(pl)
if pl:GetNWInt("SkillPoints") <= 0 then return false end
pl:SetNWInt("Skill_REGEN",pl:GetNWInt("Skill_REGEN") + 1)
pl.RegTime = pl.RegTime + RegTimeVar
pl:SetNWInt("SkillPoints",pl:GetNWInt("SkillPoints") - 1)
file.Write("exp/"..pl:UniqueID().."_skill_regen.txt", pl:GetNWInt("Skill_REGEN"))
file.Write("exp/"..pl:UniqueID().."_skillpoints.txt", pl:GetNWInt("SkillPoints"))
end
concommand.Add( "skill3buy",RegenBuy )
function ArmRegenBuy(pl)
if pl:GetNWInt("SkillPoints") <= 0 then return false end
pl:SetNWInt("Skill_ARMREGEN",pl:GetNWInt("Skill_ARMREGEN") + 1)
pl.RegArmTime = pl.RegArmTime + RegArmTimeVar
pl:SetNWInt("SkillPoints",pl:GetNWInt("SkillPoints") - 1)
file.Write("exp/"..pl:UniqueID().."_skill_armregen.txt", pl:GetNWInt("Skill_ARMREGEN"))
file.Write("exp/"..pl:UniqueID().."_skillpoints.txt", pl:GetNWInt("SkillPoints"))
end
concommand.Add( "skill4buy",ArmRegenBuy )
function JumpBuy(pl)
if pl:GetNWInt("Skill_JUMP") >= 15 then return false end
if pl:GetNWInt("SkillPoints") <= 0 then return false end
pl:SetNWInt("Skill_JUMP",pl:GetNWInt("Skill_JUMP") + 1)
pl:SetJumpPower( pl:GetJumpPower() + JumpPowerVar )
pl:SetNWInt("SkillPoints",pl:GetNWInt("SkillPoints") - 1)
file.Write("exp/"..pl:UniqueID().."_skill_jump.txt", pl:GetNWInt("Skill_JUMP"))
file.Write("exp/"..pl:UniqueID().."_skillpoints.txt", pl:GetNWInt("SkillPoints"))
end
concommand.Add( "skill5buy",JumpBuy )
function ResistanceBuy(pl)
if pl:GetNWInt("Skill_RESIST") >= 15 then return false end
if pl:GetNWInt("SkillPoints") <= 0 then return false end
pl:SetNWInt("Skill_RESIST", pl:GetNWInt("Skill_RESIST") + 1)
pl:SetNWInt("SkillPoints",pl:GetNWInt("SkillPoints") - 1)
pl.Resistance = pl.Resistance - ResistanceVar
file.Write("exp/"..pl:UniqueID().."_skill_resist.txt", pl:GetNWInt("Skill_RESIST"))
file.Write("exp/"..pl:UniqueID().."_skillpoints.txt", pl:GetNWInt("SkillPoints"))
end
concommand.Add( "skill6buy",ResistanceBuy )
-- End Buy Commands
-- Start Killing Human EXP Gain
function EXPGainPlayer(victim, weapon, killer)
if killer:IsPlayer() and victim:IsPlayer() and GetConVarNumber("sbox_plpldamage") == 0 then
if killer == victim then return false end
killer:SetNWInt("EXP",killer:GetNWInt("EXP") + ExpGained_Player)
-- Exp Gain Complete
if killer:GetNWInt("EXP") >= (UpKeep*4*(killer:GetNWInt("Level") + 1) + killer:GetNWInt("Level")*UpKeep) then
killer:SetNWInt("Level",killer:GetNWInt("Level") + 1)
killer:SetNWInt("SkillPoints",killer:GetNWInt("SkillPoints") + PointsGained)
killer:PrintMessage(HUD_PRINTTALK,"Level Up!")
end
end
end
hook.Add( "PlayerDeath", "PlayerExpGain", EXPGainPlayer )
-- End Killing Human Exp Gain
-- Start Killing NPC Exp Gain
function EXPGainNpc(npc, killer, weapon)
if killer:IsPlayer() and npc:IsNPC() then
killer:SetNWInt("EXP",killer:GetNWInt("EXP") + ExpGained)
-- Exp Gain Complete
if killer:GetNWInt("EXP") >= (UpKeep*4*(killer:GetNWInt("Level") + 1) + killer:GetNWInt("Level")*UpKeep) then
killer:SetNWInt("Level",killer:GetNWInt("Level") + 1)
killer:SetNWInt("SkillPoints",killer:GetNWInt("SkillPoints") + PointsGained)
killer:PrintMessage(HUD_PRINTTALK,"Level Up!")
end
end
end
hook.Add( "OnNPCKilled", "NpcExpGain", EXPGainNpc )
-- End Killing NPC Exp Gain
-- Start Save
function SaveDataNPC(npc, killer, weapon)
if npc:IsNPC() and killer:IsPlayer() then
file.Write("exp/"..killer:UniqueID().."_exppoints.txt", killer:GetNWInt("EXP"))
file.Write("exp/"..killer:UniqueID().."_level.txt", killer:GetNWInt("Level"))
file.Write("exp/"..killer:UniqueID().."_skillpoints.txt", killer:GetNWInt("SkillPoints"))
end
end
hook.Add( "OnNPCKilled", "SaveDataNPC", SaveDataNPC )
function SaveDataPlayer(victim, weapon, killer)
if victim:IsPlayer() and killer:IsPlayer() then
file.Write("exp/"..killer:UniqueID().."_exppoints.txt", killer:GetNWInt("EXP"))
file.Write("exp/"..killer:UniqueID().."_level.txt", killer:GetNWInt("Level"))
file.Write("exp/"..killer:UniqueID().."_skillpoints.txt", killer:GetNWInt("SkillPoints"))
end
end
hook.Add( "PlayerDeath", "SaveDataPlayer", SaveDataPlayer )
-- End Save