Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by davidflynn2 · Jun 21, 2013 at 04:51 PM · c#barexperience

MMO Like Experience System

I am trying to create a MMO like leveling system that has a bar across the screen that as you level fill up then when you level it clears and starts to fill all over again. I have made one that works for one level but I cant seem to figure out how to make one for multiple levels that take different experice to reach.

Any one know where I could find a tutorial on this or somthing close that I could mod to work. I have some good basic knowlege of C# and am studying hard in it to learn all I can but at the time beeing im now sure how to do this and I realy need it for a class project we are working on.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer Wiki

Answer by Dracorat · Jun 21, 2013 at 05:05 PM

The steps are:

Identify the experience needed for each level. Identify which level you're in based upon these thresholds. Subtract the top of the last level from your current xp amount to get the amount "in to this level" you are. Subtract the top of the last level from the top of this level to get the amount "of xp required this level" Divide "amount I'm in this level" by "amount required" to get "percent in this level".

Draw bar PERCENT wide. Where percent is the amount you just calculated and you multiply that percent by the width of a 100% bar. (If you are 20% in and the bar is 200 px wide, it would be 0.20 * 200 = 40 pixels wide)

 void Main()
 {
     XP xp = new XP(1300);
     Console.WriteLine("Our character starts at {0} xp and is level {1}.", xp.GetCurrentXp(), xp.GetCurrentLevel());
     Console.WriteLine("Now, we add 2000 xp.");
     xp.AddXp(2000);
     Console.WriteLine("Now, our character has {0} xp and is level {1}.", xp.GetCurrentXp(), xp.GetCurrentLevel());
     Console.WriteLine("Our character is {0}% in to his next level", xp.GetPercentInToLevel() * 100f);
 }
 
 public class XP {
     private int[] xpTargets = new int[] {0, 1000, 3000, 6000, 10000};
     private int currentXp = 0;
     
     public XP() { }
     public XP(int startingXp) { this.SetXp(startingXp); }
     
     public int GetCurrentXp(){
         return this.currentXp;
     }
     
     public int GetCurrentLevel(){
         for(int i = 0; i < (this.xpTargets.Length - 1) ; i++){ // Have to minus one since we're checking against "the next item" and there is no "next item" at the end of the list
             if(this.currentXp == this.xpTargets[i] || (this.currentXp > this.xpTargets[i] && this.currentXp < this.xpTargets[i + 1])){
             return (i + 1); // Since i is 0-based
             }
         }
         
         //If we're here, they're at the max level
         return this.xpTargets.Length;
     }
     
     public float GetPercentInToLevel(){
         int currentLevel = this.GetCurrentLevel();
         if(currentLevel == this.xpTargets.Length){
             // At max level, so 100%
             return 1.0f;
         }
         
         decimal xpInToLevel = (decimal)currentXp - (decimal)this.xpTargets[currentLevel - 1];
         decimal xpTopEnd = (decimal)this.xpTargets[currentLevel] - (decimal)this.xpTargets[currentLevel - 1];
         float percent = (float)xpInToLevel / (float)xpTopEnd;
         return percent;
     }
     
     public void SetXp(int newXp) {
         this.currentXp = newXp;
     }
     
     public bool AddXp(int xp){
         int startingLevel = this.GetCurrentLevel();
         this.currentXp += xp;
         if(this.GetCurrentLevel() == startingLevel) {
             return false; // We didn't level up with this xp
         }
         
         return true; // We leveled up.
     }
 }

Output:

 Our character starts at 1300 xp and is level 2.
 Now, we add 2000 xp.
 Now, our character has 3300 xp and is level 3.
 Our character is 10% in to his next level
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kovenant · Sep 26, 2013 at 01:44 PM 0
Share

How can I modify this so that xp is 0 at each level up but at the same time keep my level?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

new user very easy c# question regarding syntax 1 Answer

Distribute terrain in zones 3 Answers

Health Help D: 2 Answers

Creating a timer for combat (C#) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges