Amount of xp to incress level by one

ok guys i made this but i dont know why its not working so if you can help me thanks!



function levelup()
local range = 500
local sound = 200
if ply:GetNWInt("xp") >== 50 then	
ply:SetNWInt( "level", 2 )
ply:EmitSound("ambient/atmosphere/thunder1.wav",range,sound)
elseif ply:GetNWInt("xp") >== 100  then
	ply:SetNWInt( "level", 3 )
	ply:EmitSound("ambient/atmosphere/thunder1.wav",range,sound)
elseif ply:GetNWInt("xp") >== 350  then
	ply:SetNWInt( "level", 4 )
	ply:EmitSound("ambient/atmosphere/thunder1.wav",range,sound)
elseif ply:GetNWInt("xp") >== 500  then
	ply:SetNWInt( "level", 5 )
	ply:EmitSound("ambient/atmosphere/thunder1.wav",range,sound)
elseif ply:GetNWInt("xp") >== 850 then
	ply:SetNWInt( "level", 6 )
	ply:EmitSound("ambient/atmosphere/thunder1.wav",range,sound)
elseif ply:GetNWInt("xp") >== 1060 then
	ply:SetNWInt( "level", 7 )
	ply:EmitSound("ambient/atmosphere/thunder1.wav",range,sound)
elseif ply:GetNWInt("xp") >== 1475 then
	ply:SetNWInt( "level", 8 )
	ply:EmitSound("ambient/atmosphere/thunder1.wav",range,sound)
elseif ply:GetNWInt("xp") >== 1655 then
	ply:SetNWInt( "level", 9 )
	ply:EmitSound("ambient/atmosphere/thunder1.wav",range,sound)
elseif ply:GetNWInt("xp") >== 2235 then
	ply:SetNWInt( "level", 10 )
	ply:EmitSound("ambient/atmosphere/thunder1.wav",500,sound)
ply:PrintMessage(HUD_PRINTTALK, "You've hit the limit for leveling max: 10 levels!")
if ply:GetNWInt("xp", 3000) then
ply:SetNWInt("xp", 2235)
end
end
end


>== should be >=

it didnt work but it fixed the lua errors but still i need it to say i leveled or you think its my cl.init hud?
let me put the code.
is it not updating the


	draw.RoundedBox(3, xpx, xpy, math.Clamp( client:GetNWInt("xp"), 0, 300)*2, 50, Color(0, 255, 0, 255)) //Xp Bar




function myhud()
//main hud
local hudx = ScrW() - 1150
local hudy = ScrH() - 100
local healthx = ScrW() - 1150
local healthy = ScrH() - 90
local pingx = ScrW() - 1150
local pingy = ScrH() - 80
local mlevelx = ScrW() - 1150
local mlevely = ScrH() - 60
local mxpx = ScrW() - 1150
local mxpy = ScrH() - 40
//xp bar
local xpx = ScrW() - 850
local xpy = ScrH() - 150
local levelx = ScrW() - 560
local levely = ScrH() - 200

	local client = LocalPlayer()
	if !client:Alive() then return end
	if(client:GetActiveWeapon() == NULL or client:GetActiveWeapon() == "Camera") then return end
	draw.RoundedBox(3, hudx, hudy, 200, 100, Color(51, 58, 51, 255)) // Main Hud BackGround
	draw.RoundedBox(3, xpx, xpy, 600, 50, Color(51, 58, 51, 255)) // Bar background
	draw.RoundedBox(3, xpx, xpy, math.Clamp( client:GetNWInt("xp"), 0, 300)*2, 50, Color(0, 255, 0, 255)) //Xp Bar
	draw.SimpleText("Health: " .. client:Health(), "Default", healthx, healthy, Color(255, 0, 0, 255), 0, 0) //health
	draw.SimpleText(client:GetNWInt("level"), "DermaLarge", levelx, levely, Color(0, 0, 255, 255), 0, 0) // level
	draw.SimpleText("Ping: ".. client:Ping(), "Default", pingx, pingy, Color(255, 255, 255, 255), 0, 0) // ping
	draw.SimpleText("Level: ".. client:GetNWInt("level"), "Default", mlevelx, mlevely, Color(0, 0, 255, 200), 0, 0) // level
	draw.SimpleText("XP: ".. client:GetNWInt("xp"), "Default", mxpx, mxpy, Color(21, 21, 255, 200), 0, 0) // xp
	local mag_left = client:GetActiveWeapon():Clip1() // How much ammunition you have inside the current magazine
	local mag_extra = client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType()) // How much ammunition you have outside the current magazine
	local secondary_ammo = client:GetAmmoCount(client:GetActiveWeapon():GetSecondaryAmmoType())// How much ammunition you have for your secondary fire, such as the MP7's grenade launcher
end
hook.Add("HUDPaint", "myhud", myhud)
 
local tohide = { -- This is a table where the keys are the HUD items to hide
	["CHudHealth"] = true,
	["CHudBattery"] = true,
	["CHudAmmo"] = true,
	["CHudSecondaryAmmo"] = true
}
local function HUDShouldDraw(name) -- This is a local function because all functions should be local unless another file needs to run it
	if (tohide[name]) then     -- If the HUD name is a key in the table
		return false;      -- Return false.
	end
end
hook.Add("HUDShouldDraw", "How to: HUD Example HUD hider", HUDShouldDraw)


Why not just increase every lvl automatic

what?? how would automatically increase the level?

Make an level-dependant Maximum XP, something like:
[lua]
local xp = ply:GetNWInt( “xp” )
local level = ply:GetNWInt( “level” )
local MaxXP = level * 3 * 1.2
if xp >= MaxXP and level < 10 then // If the player is ready to level up, and not over level 9:
ply:SetNWInt( “level”, level + 1 ) // Raise their level by one
ply:SetNWInt( “xp”, xp - MaxXP ) // Set their XP to the default amount, keeping the excess
ply:EmitSound(“ambient/atmosphere/thunder1.wav”,range,sound) // Play the level-up sound
elseif xp >= MaxXP and level == 10 then // Warn the player they are the maximum level
ply:ChatPrint( “You have hit the level limit!”, COLOR_WHITE )
end
[/lua]
The maximum xp before someone levels up is equal to their level, multiplied by 3, and an extra 20% added on top.

[editline]9th October 2013[/editline]

I would also suggest that you refrain from rating people “dumb” before you give anyone a chance to explain.

i got my xp to 8060 but it still does not level me a bit! Help

When are you calling the function?

i put



function levelup()
local range = 500
local sound = 200
local xp = ply:GetNWInt( "xp" )
local level = ply:GetNWInt( "level" )
local MaxXP = level * 2 * 1.2
local MaxLevel = 100
if xp >= MaxXP and level < MaxLevel then // If the player is ready to level up, and not over level 9:
	ply:SetNWInt( "level", GetNWInt( "level" ) + 1 ) // Raise their level by one
	ply:SetNWInt( "xp", xp - MaxXP ) // Set their XP to the default amount, keeping the excess
	ply:EmitSound("ambient/atmosphere/thunder1.wav",range,sound) // Play the level-up sound
elseif xp >= MaxXP and level == MaxLevel then // Warn the player they are the maximum level
	ply:ChatPrint( "You have hit the level limit!", COLOR_WHITE )
end
end


seriously? five threads in one day?

cmon, man. c’mon.

projects plus im learning more learning how to code in lua the better you get

hay guys its still bugged i hit about 10400 xp it did nothen



local xp = ply:GetNWInt( "xp" )
local level = ply:GetNWInt( "level" )
local MaxXP = level * 3 * 1.2
if xp >= MaxXP and level < 10 then // If the player is ready to level up, and not over level 9:
	ply:SetNWInt( "level", level + 1 ) // Raise their level by one
	ply:SetNWInt( "xp", xp - MaxXP ) // Set their XP to the default amount, keeping the excess
	ply:EmitSound("ambient/atmosphere/thunder1.wav",range,sound) // Play the level-up sound
elseif xp >= MaxXP and level == 10 then // Warn the player they are the maximum level
	ply:ChatPrint( "You have hit the level limit!", COLOR_WHITE )
end


any one got any ideas?

http://coderhire.com/

You are not having the function run, you should add a hook to it, I’m not the best at lua, so I don’t know what hook you would add, I say a think hook but that may lag the server,
[lua]
function levelup()
local range = 500
local sound = 200
local xp = ply:GetNWInt( “xp” )
local level = ply:GetNWInt( “level” )
local MaxXP = level * 2 * 1.2
local MaxLevel = 100
if xp >= MaxXP and level < MaxLevel then // If the player is ready to level up, and not over level 9:
ply:SetNWInt( “level”, GetNWInt( “level” ) + 1 ) // Raise their level by one
ply:SetNWInt( “xp”, xp - MaxXP ) // Set their XP to the default amount, keeping the excess
ply:EmitSound(“ambient/atmosphere/thunder1.wav”,range,sound) // Play the level-up sound
elseif xp >= MaxXP and level == MaxLevel then // Warn the player they are the maximum level
ply:ChatPrint( “You have hit the level limit!”, COLOR_WHITE )
end
end
hook.Add( “Think”, “levelup”, levelup )
[/lua]

use that for now, until someone who is decent at coding can help you a little more
The problem with think hook, is that it is called every second, so it can cause a bit of lag, you should practically never use think, but that’s the only hook i can think off to use, you should be able to make a hook for when you earn xp though

I used death as the hook in my XP System. XRayhunter add,me at steam I can help you with this

Yeah, but it depends what gamemode he is making, death seems like a good hook to add in TTT, but in DarkRP it wouldn’t work as well, or in GM Stranded

In my experience, it’s always best to avoid using Think as much as possible due to its massive resource consumption. Even just ticking a timer every second would be much more efficient than this.

Yes, I know, i mentioned that in my post, but, I am not very good at lua, I was suggesting to use think for now just to test it and see if it works, then he can makes his own hook for when a player gets xp after,

Oh yes, in fact you were very explicit. My bad.

Why not just call it when someone’s XP is changed.