Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

How to make a simple Competitive/Ranked System

Newbie Spellweaver
Joined
Dec 27, 2015
Messages
11
Reaction score
8
Hello,

Today I will be explaining how to build a simple compettiive/ranked system using existing functions from Gunz itself.
I will not pass ready codes, just the explanation.

Use Case

- The player clicks on a button or types a command to enter a ranked queue.
- The system obtains the MUID of the player inserts it into a table in the database specifies that it represents the search by match
- The system returns a "Searching..." message
- The system has a timer that, every X seconds, selects players looking for a match.
- The system waits to reach 4 players looking for a match and starts a match
- The system removes players from the quest table and creates a room by pulling the players' MUIID.
- At the end of the game, add points to the winners, subtract points from the losers
- The system adds an image representing the amount of player points. This score is equivalent to a rank in competitive mode.

Database

- QueueDB: table responsible for storing players looking for a match. To prioritize performance, you can save the MUID and the points it has. That way you can filter players with similar scores.

Application

- Through a command or button (Widget) you need to make a call to the MatchServer. Use MCommand to send the Player's MUIID.

- This MCommand should consult the QueueDB table if the player is currently looking for a match. If it is, cancel the search (removing the MUUID from the database), if not, insert the MUUID to start the search.

- In MatchServer there are some timers. I prefer to use a separate service, but you can start using the matchserver's own timer. You know that message that appears from CountPlayers? Well, look for it and you will understand what a timer is. From time to time it performs some functions. Create a new function responsible for reading the QueueDB table and when you have 4 players (or as many as you want), remove them from the table to send them to a new match.

- Now enters the main function. I removed this feature from the Clan War system itself. Basically I create two groups (Red and Blue). I randomly insert the 4 players into the groups to get 2x2.I create a ladder and add the groups in this ladder. Basically all this information is in the Ladder creation function, if I'm not mistaken in MMatchLadder or something like that. It's not difficult, you just need to recreate the method or componentize it not to consider clans but whoever is in the QueueDB queue.

A simple example in Python

Python:
class CompetitiveMatch:

    queuedb:list = []

   # method to join and left from queue
    def toggle_search(self, muid):

        # check if player in QueueDB (like GetDBMgr->QueueDB)
        if muid in self.queuedb:
            self.queuedb.remove(muid)
            return 'Search cancelled.'

        # Insert player in QueueDB
        self.queuedb.append(muid)

        return 'Searching...'

    def start_match(self, players_muid: list):

        pserver = MatchServer()
        ladder = GetLadderMgr()

        group_a = ladder.CreateLadderGroup()
        group_b = ladder.CreateLadderGroup()

        # you need convert your muid to CID (Character ID)
        player1 = pserver.GetPlayerByCID(players_muid[0])
        player2 = pserver.GetPlayerByCID(players_muid[1])
        player3 = pserver.GetPlayerByCID(players_muid[2])
        player4 = pserver.GetPlayerByCID(players_muid[3])


        # add players to groups
        group_a.addPlayer(player1)
        group_a.addPlayer(player2)

        group_b.addPlayer(player3)
        group_b.addPlayer(player4)

        # create a id for stage
        uidStage = MUID(0,0)

        # add stage
        StageAdd(NULL, "RANKED_GAME", True, "", uidStage)

        # add players to stage
        LadderJoin(player1.uid, uidStage, RED);
        LadderJoin(player2.uid, uidStage, RED);
        LadderJoin(player3.uid, uidStage, BLUE);
        LadderJoin(player4.uid, uidStage, BLUE);

        #get stage
        pStage = FindStage(uidStage)

        # now you change settings of stage
        # you can change mode type
        # rounds, maps, etc. be creative :)

        # start game and route to stage
        pStage.StartGame()

        # finally, launch ladder using this new stage
        ReserveAgent(pStage)
        mCMD = CreateCommand(MC_MATCH_LADDER_LAUNCH, MUID(0,0))
        mCMD.AddParameter(MCmdParamUID(uidStage))
        mCMD.AddParameter(MCmdParamStr( pStage.GetMapName() ))
        RouteToStage(uidStage, mCMD)

    # If you follow Ladder flow, you see after game how points is distributed.
    # You will need to create a copy but in your case increasing points all players of winner team.
    # And decrease points of loser team.
    def update_ranked_info(self, winners_muid:list, losers_muid: list):
        for player in winners_muid:
            player.update(competitive_points = player.competitive_points + 15)
        for player in losers_muid:
            player.update(competitive_points = player.competitive_points - 13)

Timer

Ok. To find the timer function in MatchServer, search for:

#define MINTERVAL_GARBAGE_SESSION_PING

This is the timer. You need to build another timer to check players in QueueDB.
After got 4 players waiting for game, remove then from database and call your LadderStart method (like the code above, write in C++ of course).

Conclusion

I believe it was understandable. It's something very basic, it has vulnerabilities and the idea is for you to make it more secure and complex. But it's a good base to start if your server doesn't have a competitive system.

updated* fixed code block formatting
 
Last edited:
Back
Top