Hello,
I was wondering if someone can make me a level system, with comments that explain what the code is doing. I want it where for level 1, you need 100xp, level 2, 200xp, level 3, 300xp, level 4, 400xp and so on. I want the xp to be given to the player by killing other players. Each time the player kills a player, he/she gets 20xp. Also, I want to be able to make a bar in the HUD for this that displays how much more XP until next level. If someone can help me, thanks.
This is a lot of work, mySQL will need to be included =\
[QUOTE=c-unit;21336002]This is a lot of work, mySQL will need to be included =\[/QUOTE]
Not really, the only thing that can't be done fast is the hud..plus that setting up the SQL shit is uber easy.
[editline]01:36AM[/editline]
I did this in the 2nd gamemode I made but I scrapped it because there was a problem with buying weapons :/ hold on I'll show you what I did..if I can find it.
[editline]01:55AM[/editline]
I couldn't find it, but really you don't even have to do this with SQL..I'll look again tomorrow
but for earning XP this is the basic of how it would be done
[lua] if ( attacker == ply ) then
attacker:AddFrags( -1 )
else
attacker:AddFrags( 1 )
ply:SetNWInt("Experiance", ply:GetNWInt("Experiance") + 20 )
ply:ChatPrint("You've earned 20xp") -- err that might print for everyone?
end
[/lua]
[lua]
function levelchecking( ply )
if( ply:GetNWInt("Experiance") >= 100 ) then
ply:SetNWInt("Level", 1 )
print( .. ply:GetName() .. " has leveled up!" ) -- yeah kinda obvious
end
end
hook.Add( "PlayerSpawn", "derpherphurrrr", levelchecking ) -- Happens everytime the player respawns
[/lua]
yeah I don't know about that 2nd one..I'll try looking again tomorrow
Thanks everyone, but I got it.
well if he was gonna have an inventory system, why wouldn't he use mySQL, or does he only want temporary inventory such as DarkRP with pocket
[QUOTE=c-unit;21354198]well if he was gonna have an inventory system, why wouldn't he use mySQL, or does he only want temporary inventory such as DarkRP with pocket[/QUOTE]
file.Write
OP says nothing about an Inventory system, just because you have one thing on SQL doesn't mean everything has to be. What I posted is actually SQL but I was just saying it doesn't have to be as a reply to what you posted.
Btw its not MySQL its SQLite.
[editline]10:21PM[/editline]
[QUOTE=Wizey!;21354498]file.Write[/QUOTE]
this
I only called it mySQL because that;s what i saw it named in a tutorial long ago =\
Well, I have a new problem right now. In the HUD, I have a bar that displays the amount of XP. Well, it is only sized to 100 xp, so if you have over 100xp, it goes outside the background box. How can I make one that sizes to the amount of XP you need for your next level? Here is the code I use for the level system:
[lua]
--Configuration
XpVals = { }
XpVals[ "LevelXPNeeded" ] = 100 -- How much XP is needed * level.
XpVals[ "XpGive" ] = 20 -- How much XP they get on killing.
XpVals[ "TakeAway" ] = 100
function GiveEXP( victim, weapon, killer) -- function with args
if killer:IsPlayer() then -- check if the killer is a player
killer:SetNWInt("exp", killer:GetNWInt("exp") + XpVals[ "XpGive" ] ) -- Add 20 EXP.
if killer:GetNWInt("exp") >= XpVals[ "LevelXPNeeded" ] * (killer:GetNWInt("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] ".. killer:Nick() .." has reached level ".. killer:GetNWInt("CurLevel") + 1 ) -- The message.
end
end
killer:ChatPrint("[XP] You have reached level ".. killer:GetNWInt("CurLevel") + 1 .." for killing ".. victim:Nick() ..".") -- tell the killer they reached a new level.
killer:SetNWInt("CurLevel", killer:GetNWInt("CurLevel") + 1) -- Set there new level.
killer:SetNWInt( "exp", 0 )
end
end
end
hook.Add("PlayerDeath", "GiveEXPOnDeath", GiveEXP) -- hook to PlayerDeath.
function EXPOnSpawn( ply )
ply:SetNWInt("CurLevel", 0) -- Set the NWInt "CurLevel" to 0.
ply:SetNWInt("exp", 0) -- Set the NWInt "exp" to 0.
end
hook.Add("PlayerInitialSpawn", "SetEXPOnSpawn", EXPOnSpawn) -- hook to PlayerInitialSpawn
[/lua]
Use a percentage to next level instead of the actual amount of XP.
[QUOTE=DocDoomsday;21374249]Use a percentage to next level instead of the actual amount of XP.[/QUOTE]
How would I find the percentage? Would I do current level divided by next level? Or is there another way? Can you or someone please tell me?
[QUOTE=wakeboarderCWB;21374445]How would I find the percentage? Would I do current level divided by next level? Or is there another way? Can you or someone please tell me?[/QUOTE]
Did you take maths at school?
[lua]
(current exp / exp needed for next level ) x 100
[/lua]
[QUOTE=sintwins;21383281]Did you take maths at school?
[lua]
(current exp / exp needed for next level ) x 100
[/lua][/QUOTE]
Doesn't work.
[QUOTE=wakeboarderCWB;21388689]Doesn't work.[/QUOTE]
What do you mean it doesn't work? that's basic maths.
[editline]08:01PM[/editline]
Use a * instead of a x
[QUOTE=MakeR;21388735]What do you mean it doesn't work? that's basic maths.
[editline]08:01PM[/editline]
Use a * instead of a x[/QUOTE]
I did. This is what I did:
[lua]
local xp = ( LocalPlayer():GetNWInt( "exp" ) / LocalPlayer():GetNWInt( "CurLevel" ) + 1 * 100 ) * 100 [/lua]
The amount of XP to get to the next level is 100 times your next level.
You have your procedance wrong, you are dividing before you are adding on the 1 and multiplying by 100.
[lua]local xp = ( LocalPlayer():GetNWInt( "exp" ) / ( LocalPlayer():GetNWInt( "CurLevel" ) + 1 * 100 ) ) * 100[/lua]
Remember, division and multiplication come before addition and subtraction.
[QUOTE=MakeR;21388850]You have your procedance wrong, you are dividing before you are adding on the 1 and multiplying by 100.
[lua]local xp = ( LocalPlayer():GetNWInt( "exp" ) / ( LocalPlayer():GetNWInt( "CurLevel" ) + 1 * 100 ) ) * 100[/lua]
Remember, division and multiplication come before addition and subtraction.[/QUOTE]
It still doesn't work.
Remember, what I want is the bar to be sized to the amount of xp you need for your next level. So if you need 200xp, the bar will be sized for 200xp.
Instead of multiplying by 100, multiply by the width of the bar.
So if the width of the xp bar was 500px, you would multiply by 500.
[QUOTE=MakeR;21389070]Instead of multiplying by 100, multiply by the width of the bar.
So if the width of the xp bar was 500px, you would multiply by 500.[/QUOTE]
Well, for the xp bar, the width is the code that you had to fix for me. Here is the function for my XP hud:
[lua]
function XPhud()
local xp = ( LocalPlayer():GetNWInt( "exp" ) / ( LocalPlayer():GetNWInt( "CurLevel" ) + 1 * 100 ) ) * 100
local height = ScrH() / 32
local width = ScrW() / 1.970
local height2 = 11
draw.RoundedBox( 6, ScrW() * 0.25, ScrH() * 0.935, width, height, Color( 0, 0, 0, 200 ) )
draw.RoundedBox( 6, ScrW() * 0.255, ScrH() * 0.945, xp, height2, Color( 0, 0, 255, 200 ) )
end
hook.Add( "HUDPaint", "XPhud", XPhud )
[/lua]
So, how would I size the code to each amount of XP needed for this? Thanks.
Sorry, you need to Log In to post a reply to this thread.