• Having Problem With an EXP System
    2 replies, posted
To start off, nothing has ever made me more mad than this. A friend wanted me to edit an exp system that someone released over 2 years ago to give experience based on kills and what types of enemies your killing. It originally just gave 1 exp every time you hit an enemy, but now I have it set up to give a certain amount of exp based on what npc was killed. Now my problem is that the leveling up system was based on whenever the experience was equal to an amount given on a table. Since the experience given was always 1, he wrote it so that it had to EQUAL (not greater than or equal to) to that of the table. I wanted to change it so it would level up when it was equal to or greater than, but for some unknown reason, it refuses to level up if it is greater than the given experience. It will only level when it equals exactly the number. Not anything over. The table given for experience and level is this. [CODE]levelups = { 0, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 20000, 50000}[/CODE] The original piece of code for when an NPC was hit was this. [CODE]-- Give experience/level up on hit an npc or player function AddEXP( ply, hitgroup, dmginfo ) local attacker = dmginfo:GetAttacker() if attacker:IsPlayer() then if EXP_STOPATMAX == 1 and attacker:GetNWInt("CurLevel") == levelups[table.Count(levelups)] then return end attacker:SetNWInt("Exp",attacker:GetNWInt("Exp")+EXP_INC) if table.HasValue(levelups,attacker:GetNWInt("Exp")) then local leveln = 1 for k,v in ipairs(levelups) do if v == attacker:GetNWInt("Exp") then leveln = k end end if leveln == table.Count(levelups) then PrintAll(attacker:Name().." has reached the maximum level!") else PrintAll(attacker:GetName().." has now reached level "..leveln.."!") end attacker:SetNWInt("NextLevel",levelups[leveln+1]) attacker:SetNWInt("CurLevel",levelups[leveln]) attacker:SetNWInt("LevelNum",leveln) attacker:SendLua("surface.PlaySound(\"achievements/achievement_earned.mp3\")") end end end[/CODE] The code I had written (the important bits) is this. [CODE]function CheckNPC(npc) if npc:GetClass() == "npc_zombie" then return 3 end if npc:GetClass() == "npc_zombie_torso" then return 2 end if npc:GetClass() == "npc_headcrab" then return 1 end if npc:GetClass() == "npc_headcrab_fast" then return 2 end if npc:GetClass() == "npc_fastzombie" then return 5 end end -- Give experience/level up on hit an npc or player function AddEXP( victim, killer, weapon ) local attacker = killer if attacker:IsPlayer() then if EXP_STOPATMAX == 1 and attacker:GetNWInt("CurLevel") == levelups[table.Count(levelups)] then return end attacker:SetNWInt("Exp",attacker:GetNWInt("Exp")+ CheckNPC(victim) ) if table.HasValue(levelups,attacker:GetNWInt("Exp")) then if (attacker:GetNWInt("Exp") == 50 or attacker:GetNWInt("Exp") == 51) then if attacker:GetNWInt("LevelNum") == 1 then PrintAll(attacker:GetName().." has now reached level 2!") attacker:SetNWInt("NextLevel",levelups[3]) attacker:SetNWInt("CurLevel",levelups[2]) attacker:SetNWInt("LevelNum",2) attacker:SendLua("surface.PlaySound(\"achievements/achievement_earned.mp3\")") end end end end end[/CODE] There is a section in my new code that I had removed, but it is unfinished and unimportant. The problem I'm having is every time my attacker:GetNWInt("Exp") equals 50, it will level up, but not when it equals 51. I can't figure this out, and I really need to find out why this sin't working. I've included what I believe to be the important pieces of code in this problem, but if you want to help, but need to see more code, ask and I will supply it. Thanks in advance to whoever will help. EDIT: The only reason why I have the 50 and 51 in my modified piece of code is because if I can get just 51 to work, I can get everything else to work. But only 50 works for some strange reason. [highlight](User was banned for this post ("Wrong section" - mahalis))[/highlight]
so you want help with a working script that you couldent modify?
How about you rewrite that code before your server shits itself with that godawful saving technique and use metatables if you have to.
Sorry, you need to Log In to post a reply to this thread.