So, I'm trying to use a Experience Mod for my MeRP server, and the mod is based on kills. I wanted to change it so, say every 30 minutes you'd get 30 experience points. In other words, change the script slightly. I'll post the script here..
[code]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 = 1 -- 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.05 -- 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.02 -- 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.
-- 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_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 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! Use your console, and type 'spendpoints' to use your skill points!")
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
[lua]hook.Add("Initialize","AddPoints",function()
timer.Create("PointsTimer",30*60,0,function
for k,v in pairs(player.GetAll()) do
v:SetNWInt("EXP",v:GetNWInt("EXP")+1)
end
end)
end)[/lua]
[editline]24th October 2010[/editline]
I think this is what you're looking for.
[editline]24th October 2010[/editline]
oh, and the lua tags are [noparse][lua][/lua][/noparse]
So I'd shove this where? Lol
Could you say, give me a very detailed explanation? I'd like to learn too.
ok, put this in a serverside file.
so when the game initializes, it starts the timer which goes on for infinity because the number of times it runs is set to 0. It runs the function every 30*60 seconds, or in other words, every 30 minutes. It get's all the players then sets their networked integer; "EXP" to their current value plus 1. So it gets everyone's EXP and adds one to it so they have 1 more EXP every 30 minutes.
.. What carmine is trying to say is put it in lua/autorun/server
[QUOTE=uberpwns;25617787].. What carmine is trying to say is put it in lua/autorun/server[/QUOTE]
Put it anywhere>?
[QUOTE=Jaastin;25619251]Put it anywhere>?[/QUOTE]
Anywhere in lua/autorun/server
Yes
:/ , does not work . Uhmm.. so here's my script.
[code]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 = 1 -- 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.05 -- 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.02 -- 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.
-- 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_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 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! Use your console, and type 'spendpoints' to use your skill points!")
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("ex
I don't know why, this didn't work for me.
Unless it's because I was running this in single player, so that didn't initialize.
I think though, it might be because it didn't go through the rest of the script.
Script : [url]http://www.facepunch.com/showthread.php?888952-Experiance-Mod[/url]
Sorry, you need to Log In to post a reply to this thread.