• Help with gmod leveling system
    8 replies, posted
I am just starting glua and would like to know the hooks functions or anything needed for making a leveling system or anything useful comment anything helpful below thank you. Ps im looking to make a rank system based off of hours and kills if anyone can provide me with info about that
There's no hook for that, you must find what kind f sources do you want to use to level up and use variables with it
[QUOTE=KingSean02;52331636]I am just starting glua[/QUOTE] You might want to wait a bit before creating a leveling system
Note: This code is not meant to be used as is, it's merely to get you started and doesn't include networking/saving data. (it's pretty basic and bad) Here we set the player's xp and level when they first spawn in: [code] hook.Add("PlayerInitialSpawn", "levelSystem", function(ply) ply.xp = 0 ply.level = 1 end) [/code] Here is a function to add xp and check if the player should level up: [code] local pMeta = FindMetaTable("Player") function pMeta:addXP(xp) if self.xp + xp > self.level * 100 then --the player has leveled up self.xp = self.xp + xp - self.level * 100 self.level = self.level + 1 else --the player has not leveled up, add their new xp self.xp = self.xp + xp end end [/code] Here is a way that we can grant a player xp: [code] hook.Add("PlayerDeath", "levelSystemKillXP", function(victim, inflictor, attacker) if victim != attacker then attacker:addXP(20) attacker:ChatPrint("You were granted 20 XP for killing "..victim:Nick()..".") end end) [/code]
[QUOTE=Lil_Roach;52332944] [code] function addXP(ply, xp) if ply.xp + xp > ply.level * 100 then --the player has leveled up ply.xp = ply.xp + xp - ply.level * 100 ply.level = ply.level + 1 else --the player has not leveled up, add their new xp ply.xp = ply.xp + xp end end [/code] [/QUOTE] No reason to use a global function when you can define a metafunction.
[QUOTE=JasonMan34;52333151]No reason to use a global function when you can define a metafunction.[/QUOTE] Yes you're right, wasn't think when I wrote that.
Yea can you explain to me what i have to do fully.
[QUOTE=KingSean02;52334609]Yea can you explain to me what i have to do fully.[/QUOTE] No, it's your creation, you figure it out. Besides, there are [B]a lot[/B] of different ways to make a level/xp system, there's no explaining what you have to do fully because there are so many options of what can be done. If you have no idea what to do or how to do it, perhaps you should listen to my previous advice: [QUOTE=JasonMan34;52332860]You might want to wait a bit before creating a leveling system[/QUOTE]
Player:AddFrags()
Sorry, you need to Log In to post a reply to this thread.