EXP Code Problem?

So basicly im using this code

function GiveEXP( victim, weapon, killer) – function with args
local RandomNumber = math.random(50,90)
local XPRandom = math.random(10,15)
ExpThing = RandomNumber
CFG_EXPOnKill = XPRandom
CFG_EXPNEEDED = RandomNumber – How much XP is needed * level.
killer:AddNonTempSH(“SkillPoints”, killer:GetSHVar(“SkillPoints”) + CFG_SkillPoints)
killer:AddNonTempSH(“exp”, killer:GetSHVar(“exp”) + CFG_EXPOnKill) – Add 20 EXP.
killer:AddNonTempSH(“ExpThing”, killer:GetSHVar(“exp”) )
if killer:GetSHVar(“exp”) >= CFG_EXPNEEDED * (killer:GetSHVar(“CurLevel”) + 1) then – if the killers exp is over the xp needed * next level number.
for k, v in pairs(player.GetAll()) do – loop, check the wiki for more info on these.
if v != killer then – check if v is not the killer, as we don’t want to show that message to the killer, he has his own.
v:ChatPrint("[XP] … … has reached level “… killer:GetSHVar(“CurLevel”) + 1 …” from killing “… victim:Nick() …”.") – The message.
killer:SendLua(“surface.PlaySound(“achievements/achievement_earned.mp3”)”)
end
end
killer:ChatPrint("Now You Are Level “… killer:GetSHVar(“CurLevel”) + 1 …” Congratulations “) – tell the killer they reached a new level.
killer:SetSHVar(“CurLevel”, killer:GetSHVar(“CurLevel”) + 1) – Set there new level.
killer:SetSHVar(“SkillPoints”, killer:GetSHVar(“SkillPoints”) + 1) – add a skill point every time player level up
killer:ChatPrint(”[XP] Now You Have "…killer:GetSHVar(“SkillPoints”) …"Skill Points ")
end
end

hook.Add(“OnNPCKilled”, “GiveEXP”, GiveEXP) – hook to PlayerDeath.

But after getting some exp actually after i have 50 exp and then kill a npc again to get more exp it prints

Hook ‘GiveEXP’ Failed: [gamemodes\somegamemode\gamemode\init.lua:405] attempt to perform arithmetic on a nil value

so i tried this code before and it had never give me any problems before so i got no idea why it stopped of work right now

Use lua tags… it’s really hard to read it without lua tags

badly my keyboard doesnt have the key to put the tags

then copy and paste ] [ lua /

What is “EXP”?
What is line 405?
What have you already tried in an attempt to fix this?

What keyboard’ve you got?

BENQ keyboard and nvm about the problem i alredy fixed it

That code made my eyes bleed.

Lua is an uncompiled language, it may be fast but gawd!

Exp = ExpToLevel
ExpToLevel = Trololol
Trololol = Exp

I mean, really your code is a lot like that, it is not needed.

Let him do what he wants with his code. Hes not asking us to tell him about those stupid stuffs, but about us helping him…

And as I see, he still haven’t added it to the lua tags so here it goes:

[lua]
function GiveEXP( victim, weapon, killer) – function with args
local RandomNumber = math.random(50,90)
local XPRandom = math.random(10,15)
ExpThing = RandomNumber
CFG_EXPOnKill = XPRandom
CFG_EXPNEEDED = RandomNumber – How much XP is needed * level.
killer:AddNonTempSH(“SkillPoints”, killer:GetSHVar(“SkillPoints”) + CFG_SkillPoints)
killer:AddNonTempSH(“exp”, killer:GetSHVar(“exp”) + CFG_EXPOnKill) – Add 20 EXP.
killer:AddNonTempSH(“ExpThing”, killer:GetSHVar(“exp”) )
if killer:GetSHVar(“exp”) >= CFG_EXPNEEDED * (killer:GetSHVar(“CurLevel”) + 1) then – if the killers exp is over the xp needed * next level number.
for k, v in pairs(player.GetAll()) do – loop, check the wiki for more info on these.
if v != killer then – check if v is not the killer, as we don’t want to show that message to the killer, he has his own.
v:ChatPrint("[XP] … … has reached level “… killer:GetSHVar(“CurLevel”) + 1 …” from killing “… victim:Nick() …”.") – The message.
killer:SendLua(“surface.PlaySound(“achievements/achievement_earned.mp3”)”)
end
end
killer:ChatPrint("Now You Are Level “… killer:GetSHVar(“CurLevel”) + 1 …” Congratulations “) – tell the killer they reached a new level.
killer:SetSHVar(“CurLevel”, killer:GetSHVar(“CurLevel”) + 1) – Set there new level.
killer:SetSHVar(“SkillPoints”, killer:GetSHVar(“SkillPoints”) + 1) – add a skill point every time player level up
killer:ChatPrint(”[XP] Now You Have "…killer:GetSHVar(“SkillPoints”) …"Skill Points ")
end
end

hook.Add(“OnNPCKilled”, “GiveEXP”, GiveEXP) – hook to PlayerDeath.
[/lua]

Wtf? All keyboards have the same keys you idiot lol… the tags go like this: [.lua] [./lua] remove the .

not if you use spanish keyboards idiot

http://www.wesleyan.edu/CTWMellon/graphics/spankey.jpg

Looks the same.

I’m 99% sure that all keyboards have special characters, and if they don’t, cheap keyboards go for around 20 bucks wow I’m way off topic mods have mercy

[editline]22nd March 2011[/editline]

BTW, EXPthing = CFG_EXPneeded

[editline]22nd March 2011[/editline]

sorry caps are incorrect, on my phone

[editline]22nd March 2011[/editline]

Which line is 405

what the shit is “ShVar”

Yeah, saw it right now. What is it?

Its a better version of NWInts thats inside MawBase 2.0 in oter words a awesome thing that you can use if you use the maw gamemode framework(with permision of him)

informative…

Your SHVar’s could be nil, I would do (killer:GetSHVar(“CurLevel”) or 0) + 1 whenever adding to a variable that isnt defined directly.

Your SHVars might be messed up, can you paste the code of that function here?

SetSHVar:

[lua]
function EPT:SetSHVar(Name,Var,ply) --Third argument should only be defined if it is send specificly only for this player.
if (!self.SHVars) then self.SHVars = {} end
self.SHVars[Name] = Var

if (SERVER) then
	SHQTab 							= SHQTab + 1
	local ID 						= self:EntIndex()
	local Delay 					= SHQTab/50
	timer.Simple(Delay,function() --Delaying each every single umsg
		local RP = RecipientFilter()
		if (ValidEntity(ply)) then
			RP:AddPlayer(ply)
		else
			RP:AddAllPlayers()
		end
		umsg.Start("_SetSHVar",RP)
			umsg.String(type(Var).."æ"..Name.."æ"..tostring(ID))

			if (type(Var) == "string") then
				umsg.String(Var)
			elseif (type(Var) == "number") then
				umsg.Long(Var)
			elseif (type(Var) == "boolean") then
				umsg.Bool(Var)
			elseif (type(Var) == "entity") then
				umsg.Short(Var:EntIndex())
			elseif (type(Var) == "Entity") then
				umsg.Short(Var:EntIndex())
			elseif (type(Var) == "Player") then
				umsg.Short(Var:EntIndex())
			elseif (type(Var) == "Angle") then
				umsg.Angle(Var)
			elseif (type(Var) == "Vector") then
				umsg.Vector(Var)
			end
		umsg.End()
		
		SHQTab = SHQTab - 1
	end)
end

end
[/lua]

GetSHVar:

[lua]
function EPT:GetSHVar(Name,Var)
if (!self.SHVars or self.SHVars[Name] == nil) then return Var or nil end
if (self.SHVars) then return self.SHVars[Name] end
end
[/lua]

Edited, whatever.

If I’m correct, this guy said he’s using v2.0.
Well, that’s the code for 2.0 (outdated!), and I recently took a look through the updated, and SHVar has been modified since then.