Leveling up, ranks & XP - PHP & MYSQL

Hello,

I have recently got myself a base script for a MMORPG, I know some PHP and some MySQL. I am learning as I go along, as everyone has to start somewhere.

Currently I am able to ‘commit’ crimes of which adds XP to my user every time it is successful.
When my user reaches a certain number of XP matching the next rank, it should automatically change, but ofcourse it doesnt.
The percentage just keeps going up past 300% and stays the same rank name.

I have users, ranks and user stats set up in my database.

[php]public function checkRank() {

        if ($this->loggedin) {
		
            $rank = $this->getRank();

            if ($rank->R_exp < $this->info->US_exp || $rank->R_exp == $this->info->US_exp) {

                $this->db->query("UPDATE userStats SET US_money = US_money + ".$rank->R_cashReward.", US_bullets = US_bullets + ".$rank->R_bulletReward.", US_rank = US_rank + 1, US_exp = ".($this->info->US_exp - $rank->R_exp)." WHERE US_id = ".$this->info->US_id);

                $this->info->US_exp = ($this->info->US_exp - $rank->R_exp);
                $this->info->US_rank++;
                $this->info->US_bullets = $this->info->US_bullets + $rank->R_bulletReward;
                $this->info->US_money = $this->info->US_money + $rank->R_cashReward;

                return true;

            } else {

                return false;

            }

        }
	
	}[/php]

Any help is appreciated.

I can help you out a little for I have a degree in Computer Graphics: Game Design and Interactive Media and I know PHP pretty well.

First thing to say I think we just need a little more of your class (script) that shows us how you write (read) to the database. That would help out tremendously.

Second the Query statement doesn’t look like it is doing anything, but it might (see above) because not all of the code is there.

Third, I don’t think you need a less than in your if statement for if you have your database table setup correctly rankings should go from high to low (Top to Bottom). This means all you need to check is if the ranking is higher (>=) and if it is then move it to that ranking to the correct spot and all the lower rankings should fall down in line.

Some generalizations that I notice. You’re not taking full advantage of OOP, by that I mean the player should be a record on itself. I notice you said you know some PHP. Diving into Object-Oriented Programming right away is something I wouldn’t recommend. I would stick with procedural programming for it would make more sense and be easier. Even if you are modifying an existing script that using OOP there is nothing wrong with your part of the code being procedural. I do that all the time and I have found out that if I want to I can convert my procedural code over to OOP if it’s warranted or I feel like it. ;D

Sponsor our Newsletter | Privacy Policy | Terms of Service