Getting EXP For Killing Dif. NPC's


-- 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,"Congradulations, you just leveled up!")
killer:SendLua("surface.PlaySound(\""..EXP_SOUNDPATH.."\")")
end
end
end
hook.Add( "OnNPCKilled", "NpcExpGain", EXPGainNpc )
-- End Killing NPC Exp Gain


I have this script from a Leveling addon. I was wondering if someone could show and explain how to make different EXP gains for different types of NPCs, for example :

ents.FindByClass(“npc_zombie”)
ents.FindByClass(“npc_headcrab”)

I would like zombie to be 20 exp and the headcrab 5 exp.

[lua]
local ExpGained = {}
ExpGained[ “npc_zombie” ] = 20
ExpGained[ “npc_headcrab” ] = 5

function EXPGainNpc(npc, killer, weapon)
if killer:IsPlayer() and npc:IsNPC() then
killer:SetNWInt(“EXP”,killer:GetNWInt(“EXP”) + ExpGained[ npc:GetClass() ])
– Exp Gain Complete
if killer:GetNWInt(“EXP”) >= (UpKeep4(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,“Congradulations, you just leveled up!”)
killer:SendLua(“surface.PlaySound(”"…EXP_SOUNDPATH…"")")
end
end
end
hook.Add( “OnNPCKilled”, “NpcExpGain”, EXPGainNpc )[/lua]

Thank you so much :smiley: I wish I had thought of a table…
I really wanted to create an exp table since this exp code derives off of a constant multiplier which times your level. It’s wierd but would that be easy? I’m not sure how to add SQL files for the table if thats necessary. But heres the code, it would be so generous if you could help me again.
[lua]
AddCSLuaFile(“autorun/client/exp_pointsmenu.lua”)

– Start System Vars.
local UpKeep = 75 – How much added exp is added each level.
local PointsGained = 1 – How many skill points players get each level up.
local ExpGained_Player = 0 – 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.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.
local JumpPowerVar = 25 – How much extra power is added to the players jump, Try not to exceed 50 for this.
EXP_SOUNDPATH = “achievements/achievement_earned.mp3”

– Start Spawn Functions
function EXPSetVarsOnSpawn(pl)
if pl:GetNWInt(“Skill_HP”) >= 1 then
pl:SetMaxHealth(100 + MaxHpGainpl: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 + MaxArmorGainpl: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 = (RegArmTimeVarpl: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( “skillbuy1”, 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( “skillbuy2”,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( “skillbuy3”, 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( “skillbuy4”, 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( “skillbuy5”, 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( “skillbuy6”, 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”) >= (UpKeep4(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
local ExpGained = {}
ExpGained[ “npc_fastzombie”] = 10
ExpGained[ “npc_zombie” ] = 20
ExpGained[ “npc_headcrab” ] = 5

function EXPGainNpc(npc, killer, weapon)
if killer:IsPlayer() and npc:IsNPC() then
killer:SetNWInt(“EXP”,killer:GetNWInt(“EXP”) + ExpGained[ npc:GetClass() ])
– Exp Gain Complete
if killer:GetNWInt(“EXP”) >= (UpKeep4(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,“Congradulations, you just leveled up!”)
killer:SendLua(“surface.PlaySound(”"…EXP_SOUNDPATH…"")")
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[/lua]

Sorry I don’t understand? What are you asking me to do?

Create a table instead of having it calculate up by this :
[lua]
if killer:GetNWInt(“EXP”) >= (UpKeep4(killer:GetNWInt(“Level”) + 1) + killer:GetNWInt(“Level”)*UpKeep) then
killer:SetNWInt(“Level”,killer:GetNWInt(“Level”) + 1)
killer:SetNWInt(“SkillPoints”,killer:GetNWInt(“SkillPoints”) + PointsGained)[/lua]
The experience isn’t in a table its in a calculated value timed by my own level making experience harder and harder to get.
What I would like is a table such as this :
Levelups = {}
Level1
Level2
Level3
so on and so on :stuck_out_tongue:

You don’t need a table? What’s wrong with it at the moment?

I cant make it so DarkRp can be Level Base as in You must be level 2 to buy this weapon. Or can I? Could you show me an example of buying an entity or shipment when you would have to be a required level?

[lua]
– Entity
AddEntity(“Gun lab”, “gunlab”, “models/props_c17/TrapPropeller_Engine.mdl”, 500, 1, “/buygunlab”, TEAM_GUN, function( ply ) return ply:GetNWInt( “Level” ) >= 2 end )

– Shipment
AddCustomShipment(“AK47”, “models/weapons/w_rif_ak47.mdl”, “weapon_ak472”, 2450, 10, false, nil, false, {TEAM_GUN}, nil, function( ply ) return ply:GetNWInt( “Level” ) >= 2 end )[/lua]

I tried the first AddEntity one and it doesn’t show the entity until I reach that level. How would I make it so it shows it no matter what, but I would still have to be that level?

Solved.

[editline]27th January 2012[/editline]

Nevermind I still need help!
[lua]
local Levels = {}
Levels[“models/props_c17/consolebox01a.mdl”] = {30}
local EntCat = vgui.Create(“DCollapsibleCategory”)
EntCat:SetLabel(“Entities”)
local EntPanel = vgui.Create(“DPanelList”)
EntPanel:SetSize(470, 200)
EntPanel:SetAutoSize(true)
EntPanel:SetSpacing(1)
EntPanel:EnableHorizontal(true)
EntPanel:EnableVerticalScrollbar(true)
local function AddEntIcon(Model, description, command)
local icon = vgui.Create(“SpawnIcon”)
icon:InvalidateLayout( true )
icon:SetModel(Model)
icon:SetIconSize(64)
icon:SetToolTip(description)
icon.DoClick = function() for k,v in pairs(Levels) do if //SOMTHING//
and LocalPlayer():GetNWInt(“Level”) >= v then LocalPlayer():ConCommand("say "…command) else LocalPlayer():PrintMessage(HUD_PRINTTALK, “You cant”) end end end
EntPanel:AddItem(icon)
end
[/lua]
How would I get it to recognize what icon it is for that specific level?

Fixed