• Unfinished XP System.
    21 replies, posted
Sorry if this is wrong placed but i think it will be useful for people that needs Lua helps and people that go into this sub forum mostly does. So i made a XP System long time ago i did not finish because of its trash code. Feel free to use it as you want. Pastebin: [url]http://pastebin.com/e9UEHDfs[/url] [LUA] XPSystem = {} XPSystem.Shared = {} XPSystem.VIP = {} XPSystem.Buttons = {} XPSystem.ConVars.VIP = {} XPSystem.ConVars = {} XPSystem.ConVars.XPOverTime = true -- bolean false or true XPSystem.ConVars.XPOverTimeSeconds = 300 -- only matters if true XPSystem.ConVars.VIP.XPOverTimeXP = math.random( 40, 65 ) -- only matters if true XPSystem.ConVars.XPOverTimeXP = math.random( 40, 55 ) -- only matters if true function RaiseLVL ( ply ) timer.Create("RaiseLVL", 3, 0, function( ply ) if table.HasValue( ply:GetUserGroup(), XPSystem.Groups ) and ply:GetNWInt("xp") <= XPSystem.LevelUPAmount then ply:SetNWInt("lvl", ply:GetNWInt("lvl") + 1 ) ply:SetNWInt("skillp", ply:GetNWInt("skillp") + 1 ) elseif table.HasValue ( ply:GetUserGroup(), XPSystem.VIP.Groups ) and ply:GetNWInt("xp") <= XPSystem.VIP.LevelUPAmount then ply:SetNWInt("lvl", ply:GetNWiNT("lvl") + 1 ) ply:SetNWInt("skillp", ply:GetNWInt("skillp") + 1 ) else return false end end) end function XPOverTime ( ply ) if XPSystem.ConVars.XPOverTime = true then timer.Create("XPOverTime", XPSystem.ConVars.XPOverTimeSeconds, 0, function( ply ) if table.HasValue( ply:GetUserGroup(), XPSystem.Groups ) then ply:SetNWInt("lvl", ply:GetNWInt("lvl") + 1 ) ply:SetNWInt("skillp", ply:GetNWInt("skillp") + 1 ) ply:SetNWInt("xp", ply:GetNWInt("xp") + XPSystem.ConVars.XPOverTimeXP ) elseif table.HasValue( ply:GetUserGroup(), XPSystem.VIP.Groups ) then ply:SetNWInt("lvl", ply:GetNWInt("lvl") + 1 ) ply:SetNWInt("skillp", ply:GetNWInt("skillp") + 1 ) ply:SetNWInt("xp", ply:GetNWInt("xp") + XPSystem.ConVars.VIP.XPOverTimeXP ) ------ Displayed at the buttons ingame in the menu XPSystem.Buttons.HP = "Upgrade HP" XPSystem.Buttons.ARM = "Upgrade Armor" XPSystem.Buttons.RUN = "Upgrade Run speed" XPSystem.Buttons.Walk = "Upgrade Walk speed" XPSystem.Buttons.DMG = "Upgrade damage" ------ For normal people XPSystem.XPPerkill = 20 -- How many xp per kill XPSystem.LevelUPAmount = 250 -- How much it is required to level up XPSystem.HPMaxLVL = 10 XPSystem.ARMMaxLVL = 0 XPSystem.BulletScaleMaxLVL = 5 XPSystem.Groups = { "VIP", "admin", "superadmin" } XPSystem.Shared.AllowPrestige = 20 XPSystem.Shared.MaxPrestige = 10 XPSystem.Shared.MaxLVL = 50 XPSystem.VIP.Groups = { "VIP", "admin", "superadmin" } XPSystem.VIP.SpeedUpgrade = 10 XPSystem.VIP.BulletScaleMaxLVL = 5 XPSystem.VIP.XPPerkill = 25 XPSystem.VIP.HPMaxLVL = 15 XPSystem.VIP.ARMMaxLVL = 25 XPSystem.VIP.LevelUPAmount = 200 functino LoadXP( ply ) if file.Exists("exp/"..ply:SteamID(.."exp.txt", ply:GetNWInt("xp")) then ply:SetNWInt("exp"), file.Read( function SaveXP( ply ) file.CreateDir("exp") file.Write("exp/"..ply:SteamID().."exp.txt", ply:GetNWInt("xp")) file.Write("exp/"..ply:SteamID().."lvl.txt", ply:GetNWInt("lvl")) file.Write("exp/"..ply:SteamID().."skillp.txt", ply:GetNWInt("skillp")) file.Write("exp/"..ply:SteamID().."xp_skill_hp", ply:GetNWInt("xp_skill_hp")) file.Write("exp/"..ply:SteamID().."xp_skill_arm", ply:GetNWInt("xp_skill_arm")) file.Write("exp/"..ply:SteamID().."xp_skill_bulletd", ply:GetNWInt("xp_skill_bulletd")) file.Write("exp/"..ply:SteamID().."xp_skill_run", ply:GetNWInt("xp_skill_run")) file.Write("exp/"..ply:SteamID().."allowprestige", ply:GetNWInt("prestige")) file.Write("exp/"..ply:SteamID().."allowprestige", ply:GetNWInt("allowprestige")) end hook.Add("PlayerDeath", "SaveXP", SaveXP) function AddXP( victim, weapon, killer ) if table.HasValue( killer:GetUserGroup() ( XPSystem.VIP.Groups ) ) and killer:IsValid() and killer:IsPlayer() then killer:SetNWInt("xp", killer:GetNWInt("xp") + XPSystem.VIP.XPPerkill ) elseif table.HasValue( killer:GetUserGroup(), ( XPSystem.Groups ) ) and killer:IsValid() and killer:IsPlayer() then killer:SetNWInt("xp", killer:GetNWInt("xp") + XPSystem.XPPerkill ) end end hook.Add("PlayerDeath", "AddXP", AddXP) function AddLVL( victim, weapon, ply ) if ply:GetNWInt("lvl") >= XPSystem.Shared.MaxLVL then return false end if table.HasValue( ply:GetUserGroup(), ( XPSystem.Groups ) ) then if ply:GetNWInt("xp") <= XPSystem.LevelUPAmount then ply:SetNWInt("lvl", ply:GetNWInt("lvl") + 1 ) ply:SetNWInt("skillp", ply:GetNWInt("skillp") + 1 ) elseif table.HasValue( ply:GetUserGroup(), ( XPSystem.VIP.Groups ) ) then if ply:GetNWInt("xp") <= XPSystem.VIP.LevelUPAmount then ply:SetNWInt("lvl", ply:GetNWInt("lvl") + 1 ) ply:SetNWInt("skillp", ply:GetNWInt("skillp") + 1 ) else return false end end end end hook.Add("PlayerDeath", "AddLVL", AddLVL) function BuyHP( ply ) if ply:GetNWInt("skillp") >= 0 then return false end if table.HasValue( ply:GetUserGroup() ( XPSystem.Groups ) ) then if ply:GetNWInt("xp_skill_hp") <= XPSystem.HPMaxLVL then return false end else ply:SetNWInt("skillp", ply:GetNWInt("skillp") - 1 ) ply:SetNWInt("xp_skill_hp", ply:GetNWInt("xp_skill_hp") + 1 ) if table.HasValue( ply:GetUserGroup() ( XPSystem.VIP.Groups ) ) then if ply:GetNWInt("xp_skill_hp") <= XPSystem.VIP.HPMaxLVL then return false end else ply:SetNWInt("skillp", ply:GetNWInt("skillp") - 1 ) ply:SetNWInt("xp_skill_hp", ply:GetNWInt("xp_skill_hp") + 1 ) end end end concommand.Add("xpsys_hp", BuyHP) function LoadoutPerks( ply ) ply:SetHealth(ply:Health() + ply:GetNWInt("xp_skill_hp") ) ply:SetArmor(ply:Armor() + ply:GetNWInt("xp_skill_arm") ) ply:SetRunSpeed(ply:GetRunSpeed() + ply:GetNWInt("xp_skill_run") * 5 ) end hook.Add("PlayerLoadout", "XPSystem.Loadout", LoadoutPerks) function BuyWalk( ply) if ply:GetNWInt("skillp") >= 0 then ply:PrintMessage( HUD_PRINTTALK, WALKMESSAGE ) function ScaleDamageXP( ply ) dmginfo:ScaleDamage( 100 + ply:GetNWInt("xp_skill_bulletd") ) end hook.Add("ScalePlayerDamage","XPSystem.ScaleDamage", ScaleDamageXP) function BuySpeed( ply ) if ply:GetNWInt("skillp") <= 0 then return false end if ply:GetNWInt("skillp") >= 1 and table.HasValue( ply:GetUserGroup(), ( XPSystem.Groups ) ) then if ply:GetNWInt("xp_skill_run") >= XPSystem.MaxLVLSpeed then ply:SetNWInt("xp_skill_run", ply:GetNWInt("xp_skill_run") + XPSystem.SpeedUpgrade ) ply:SetNWInt("skillp", ply:GetNWInt("skillp") - 1 ) elseif ply:GetNWInt("skillp") >= 1 and table.HasValue( ply:GetUserGroup(), ( XPSystem.VIP.Groups ) ) then if ply:GetNWInt("xp_skill_run") >= XPSystem.VIP.MaxLVLSpeed then ply:SetNWInt("xp_skill_run", ply:GetNWInt("xp_skill_run") + XPSystem.VIP.SpeedUpgrade ) ply:SetNWInt("skillp", ply:GetNWInt("skillp") - 1 ) end end end end concommand.Add("xpsys_speed", BuySpeed) function BuyArmor( ply ) if ply:GetNWInt("skillp") <= 0 then return false end if ply:GetNWInt("skillp") >= 1 and table.HasValue( ply:GetUserGroup(), ( XPSystem.VIP.Groups ) ) and ply:GetNWInt("xp_skill_arm") >= XPSystem.VIP.ARMMaxLVL then ply:SetNWInt("xp_skill_arm", ply:GetNWInt("xp_skill_arm") + 1 ) ply:SetNWInt("skillp", ply:GetNWInt("skillp") - 1 ) elseif ply:GetNWInt("skillp") >= 1 and table.HasValue( ply:GetUserGroup(), ( XPSystem.Groups ) ) and ply:GetNWInt("xp_skill_arm") >= XPSystem.ARMMaxLVL then ply:SetNWInt("xp_skill_arm", ply:GetNWInt("xp_skill_arm") + 1 ) ply:SetNWInt("skillp", ply:GetNWInt("skillp") - 1 ) end end concommand.Add("xpsys_armor", BuyArmor) function BuyBulletDamage( ply ) if ply:GetNWInt("skillp") >= 0 then return false elseif ply:GetNWInt("skillp") <= 1 then if table.HasValue ( ply:GetUserGroup(), ( XPSystem.Groups ) ) and ply:GetNWInt("xp_skill_arm") >= XPSystem.BulletScaleMaxLVL then ply:SetNWInt("xp_skill_bulletd", ply:GetNWInt("xp_skill_bulletd") + 1 ) ply:SetNWInt("skillp", ply:GetNWInt("skillp") - 1 ) elseif table.HasValue ( ply:GetUserG
This code is horrendous.
SetNWInt? ohnoes
Well its a idea for beginners how to use it. Dont use any sample of this directly please. It is so bad coded. It was my first Lua thing ever
[QUOTE=Doge is Hope;43471500]Well its a idea for beginners how to use it. Dont use any sample of this directly please. It is so bad coded. It was my first Lua thing ever[/QUOTE] So you're working on the same concept when my teacher thinks its good to let a smart student try to teach the class? But like with a retarded student.
What, writing 10+ text files for every player upon death? Are you serious. Also you can't have ":" in files names (they are in steamids). Look into PData.
Ik PData. This is very old. I made a new fully functional xp system with alot better code
[lua] ply:SetNWInt("lvl", ply:GetNWInt("lvl") + 1 ) ply:SetNWInt("skillp", ply:GetNWInt("skillp") + 1 )[/lua] No thanks, I am good. @Edit: But if I was to moan a little bit more about how bad it would be to learn off this code then here it goes: -You made the global table, yet you only run it inside one file -Ever heard of Metatables? -You store everything in separate text files -Your functions aren't local, they aren't even stored in a table so chances of other scripts having "BuyArmor" functions are like chances of having a green apple amongst apples (which is huge) -Saving XP on PlayerDeath, really? -Umsg? Why do you stick to the past so much? So my suggestion: remove the code before someone gets hurt.
this is why you don't release your first addon, anything you code while still learning is pretty much guaranteed to be complete rubbish
[QUOTE=Handsome Matt;43477407]usermessages[/QUOTE] I'm just curious, but does anyone have a good argument for why not to use usermessages? I've transitioned to the net library since GMod 13, but is there anything inherently bad about usermessages?
[QUOTE=SteelSliver;43471481]SetNWInt? ohnoes[/QUOTE] May I ask, what is so bad about networked vars? You've made me concerned now, is there a better alternative?
[QUOTE=samm5506;43483727]I'm just curious, but does anyone have a good argument for why not to use usermessages? I've transitioned to the net library since GMod 13, but is there anything inherently bad about usermessages?[/QUOTE] Nothing really, but why use something outdated with less features? If the usermessages were perfect, net library wouldn't even get created. [QUOTE=Alig96;43483815]May I ask, what is so bad about networked vars? You've made me concerned now, is there a better alternative?[/QUOTE] Net library is the alternative. NWVars get sent all the time, regardless if their value changed or not. And in Net library you can choose when you want to send the info, like put the sending inside a separate function for example: mymod.SendInfo( player ) and then call it inside GM:PlayerDeath() or something like that so it's only sent when player dies.
[QUOTE=Netheous;43483817]Nothing really, but why use something outdated with less features? If the usermessages were perfect, net library wouldn't even get created. Net library is the alternative. NWVars get sent all the time, regardless if their value changed or not. And in Net library you can choose when you want to send the info, like put the sending inside a separate function for example: mymod.SendInfo( player ) and then call it inside GM:PlayerDeath() or something like that so it's only sent when player dies.[/QUOTE] Ah thank you, seems as though I've got some modifying to do!
[QUOTE=samm5506;43483727]I'm just curious, but does anyone have a good argument for why not to use usermessages? I've transitioned to the net library since GMod 13, but is there anything inherently bad about usermessages?[/QUOTE] Last I read, net messages are a lot faster and don't queue up, can send a bunch more data than usermessages, and have the ability of sending messages to the server too.
[QUOTE=Netheous;43477161][lua] ply:SetNWInt("lvl", ply:GetNWInt("lvl") + 1 ) ply:SetNWInt("skillp", ply:GetNWInt("skillp") + 1 )[/lua] No thanks, I am good. @Edit: But if I was to moan a little bit more about how bad it would be to learn off this code then here it goes: -You made the global table, yet you only run it inside one file -Ever heard of Metatables? -You store everything in separate text files -Your functions aren't local, they aren't even stored in a table so chances of other scripts having "BuyArmor" functions are like chances of having a green apple amongst apples (which is huge) -Saving XP on PlayerDeath, really? -Umsg? Why do you stick to the past so much? So my suggestion: remove the code before someone gets hurt.[/QUOTE] - XPSystem.Buttons (pl0x i have a clientside file also to retrieve everything) - Yus ofc?? - Yus very old - well change when - yus :P - Was noobed at Network at that time. Still bad at it :) -- HMM Nope
[QUOTE=Doge is Hope;43484512]- XPSystem.Buttons (pl0x i have a clientside file also to retrieve everything) - Yus ofc?? - Yus very old - well change when - yus :P - Was noobed at Network at that time. Still bad at it :) -- HMM Nope[/QUOTE] Whatever, make yourself an even bigger fool, not my problem.
Tried to talk some sense into him and teach some lua, but he does not give a fuck. Enjoy your ban. [IMG]http://puu.sh/6g9zm.png[/IMG] Also his steam permalink: [url]http://steamcommunity.com/profiles/76561198012445258[/url]
Genious. My IP ban at first was also an VPN. You basically cant do anything cause this VPN does have 253 different IP i can choose. Better luck getting 254 different IPs and alot countrys
[lua]player:SetPData("Experience", 0)[/lua] groundbreaking technology here guys [QUOTE=Doge is Hope;43488040]Genious. My IP ban at first was also an VPN. You basically cant do anything cause this VPN does have 253 different IP i can choose. Better luck getting 254 different IPs and alot countrys[/QUOTE] nobody cares if you're coming back or not we just like to waste your time, and it's also pretty comforting knowing you're over there with sweaty pants getting all angry and shit and trying to get the last say. while we do nothing, good stuff.
Sorry, you need to Log In to post a reply to this thread.