Defranco Posted February 28, 2017 Posted February 28, 2017 I'd thought I would share a basic level system for anyone new (or checking forums search function) could use as a base point to get started. At the top --------- Level System --------- --below is the player level Script.playerLevel = nil --below is the players maximum level, I use 99 for this game Script.playerMaximumLevel = 99 --below is the players starting level Script.playerStartingLevel = 1 --------- Experience System --------- --below is the players current experience points Script.playerExperiencePoints = nil --below is the players current maximum experience points Script.playerMaximumExperiencePoints = nil --below is the players starting experience points Script.playerStartingExperiencePoints = 0 --below is the players starting maximum experience points Script.playerStartingMaximumExperiencePoints = 500 --below is the amount of maximum experience points increase multiplier per level up Script.playerRateExperiencePoints = 2 --below is the calculator for extra experience points after leveling up to make sure it carries over to the next level Script.playerExtraPoints = 0 Inside the Function Start --------- SETUP LEVEL & EXP--------- --below we setup our level, experience and maximum experience to match starting values self.playerLevel = self.playerStartingLevel self.playerExperiencePoints = self.playerStartingExperiencePoints self.playerMaximumExperiencePoints = self.playerStartingMaximumExperiencePoints Scripts -- We received EXP (EXP = Experience Points) -- And if the EXP bar reaches full, then we level up and check the EXP function Script:PlayerReceiveEXP(expPoints) --lets check that we aren't going to die, dead people don't receive exp, lets also check that we are not maximum level if self.health > 0 and self.playerLevel < self.playerMaximumLevel then --lets check if our experience is less than our maximum experience if self.playerExperiencePoints < self.playerMaximumExperiencePoints then --if it is, we can add the experience points to our player self.playerExperiencePoints = self.playerExperiencePoints + expPoints end --now lets check if our experience is equal or greater to our maximum experience if self.playerExperiencePoints >= self.playerMaximumExperiencePoints then --if it is, we need to run a check to calculate the extra experience points self:PlayerCheckEXP() --also, we need to level up self:PlayerReceiveLevel(1) end end end -- We need to check how much EXP is left -- After that, we will give the EXTRA EXP back after leveling up function Script:PlayerCheckEXP() --below we calculate our extra experience points after leveling up and set them aside self.playerExtraPoints = self.playerExperiencePoints - self.playerMaximumExperiencePoints --now we reset our current experience back to 0 self.playerExperiencePoints = 0 --now we give the player back just the extra experience points self:PlayerReceiveEXP(self.playerExtraPoints) --now we reset the extra points set aside back to 0 self.playerExtraPoints = 0 end -- We received a level -- After that, we increase the maximum EXP allowed function Script:PlayerReceiveLevel(levelPoints) --we need to check that we are not maximum level first if self.playerLevel < self.playerMaximumLevel then --below we add the level to our player self.playerLevel = self.playerLevel + levelPoints --now that we have leveled up, below we increase our maximum experience points to get to the next level self.playerMaximumExperiencePoints = self.playerMaximumExperiencePoints * self.playerRateExperiencePoints end end All you have to do to receive Experience points is point to the Script:PlayerReceiveEXP(expPoints) So if you kill a monster, or finish a quest, or anything you can say something like self:PlayerReceiveEXP(250) to get 250 experience points, or run the script like self.player.script:PlayerReceiveEXP(250) or however you have it setup. The reason I personally used the words Player and player in all the names above is because this allows me to know all these functions are specifically for the player so I can have other NPCS/monsters in the game also have their own style of level system and not get it mixed up with the players scripts. 2 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.