Level system

local barpos = 1
local x,y,w,h

if barpos == 0 then x,y,w,h = 10,40,ScrW()-20,20
elseif barpos == 1 then x,y,w,h = 35,ScrH()-120,200,20
end

hook.Add(“HUDPaint”, “ExpHud”, function()

local exp = LocalPlayer():GetNWInt("Exp") 
local cur = LocalPlayer():GetNWInt("CurLevel")
local new = LocalPlayer():GetNWInt("NextLevel")
local lvl = LocalPlayer():GetNWInt("LevelNum")

if LocalPlayer():Alive() then
	
	surface.SetDrawColor(0,0,0,255)
	surface.DrawOutlinedRect(x,y,w,h)

	surface.SetDrawColor(200,0,0,255)
	surface.DrawRect(x+1.2,y+1.2,w*((exp-cur)/(new-cur))-2,h-2)

    
end

end)

http://img259.imageshack.us/img259/5841/gmflatgrass0000g.jpg

The hud isent working any 1 can help?

First of all network ints don’t save on map reload or change use ply:GetPData(“clevernamehere”) and to set it just replace Get with Set so it will save and maybe will fix it also put your code in [LUA] tags please

Maybe he sets the networked ints from a mysql database.

This is just code from expplus. He didn’t actually code any of it.
Your best bets would be to contact the original author or make a leveling system by yourself.

I dident even say i made it just tryna fixe some bugs from it and if u think its so easy to make a lvl system try

Bro it’s basic, just make some sort of exponential function for the xp number per level, have a max level, then just have a function that adds xp to someone. Store all this with mysql or sqllite or even flat file and then display dat shit on a hud.

[lua]
local level = 5 – change this
local xp = 0
for x = 1, level do
xp = xp + ( x + 300 * (2 ^ ( x / 7 ) ) )
end
xp = math.floor( xp / 4 )
[/lua]

Runescape’s xp formula

Simple but works good…

[LUA]
function CalcExpInc( level )
if(level < 1) then
exp = GetConVarNumber(“rlevel_startxp”)
return exp
else
exp = ((level*GetConVarNumber(“rlevel_startxp”))+GetConVarNumber(“rlevel_xpinc”))

return exp
end

end

function CalcLevelUp( pl )

local exp = pl:GetNWInt(“xp”)
local level = pl:GetNWInt(“level”)
exp_req = CalcExpInc(level)
if( exp >= exp_req ) then
level = level + 1
exp = exp - exp_req
pl:SetNWInt(“level”,level)
pl:SetNWInt(“xp”,exp)
end
end
[/LUA]

I would definitely not use any NW functions for something like this, it’s a lazy and inefficient way of doing things.

Why use NWInt for something you could do using net/umsg library.

you can’t send stuff like that to a HUD with net/umsg though? or am I mistaken?

You can, I’m just not sure how :v:

[lua]
if SERVER then
util.AddNetworkString(“messagename”)

function SendLevelToHUD(ply,lvl)
    net.Start()
        net.WriteInt(lvl)
    net.Send("message name",ply)
end

else
net.Receive(“messagename”, function()
print(net.ReadInt())
end)
end
[/lua]
I think

It’s
[lua]
if (SERVER) then
util.AddNetworkString(“blah”)
function SendLevelToPly(pl,lvl)
net.Start(“blah”)
net.WriteInt(lvl)
net.Send(pl)
end
else
net.Receive(“blah”, function()
local lvl = net.ReadInt()
–Do stuff
end)
end
[/lua]

You both should be using:


net.WriteInt(number integer, number bitCount)

Well, I would do everything table based as it would be easier to modify and keep track of.

I don’t see why people are rating him disagree. He’s right: http://wiki.garrysmod.com/page/Libraries/net/WriteInt