Home Garry's Mod Creating a Donation Leaderboard on a Garry's Mod Server

Creating a Donation Leaderboard on a Garry's Mod Server

Last updated on Feb 13, 2025

In this tutorial, you'll learn how to create a donation leaderboard on your Garry's Mod server using the VolticHost Game Panel. This leaderboard will track and display the top donors, encouraging community support and friendly competition. 🚀


📌 Prerequisites

  • A Garry's Mod server purchased at VolticHost.com

  • Access to the VolticHost Game Panel

  • Basic knowledge of Lua scripting and server file management

  • A donation tracking system (such as the donation rewards system previously set up)


1️⃣ First Step - Creating the Leaderboard Script

  1. Log in to VolticHost Game Panel.

  2. Navigate to the File Manager from the main dashboard.

  3. Go to the /garrysmod/lua/autorun/server/ directory.

  4. Create a new file named donation_leaderboard.lua.

  5. Open donation_leaderboard.lua for editing and paste the following script:

    if SERVER then
        util.AddNetworkString("DonationLeaderboardUpdate")
        local donationLeaderboard = {}
        
        -- Function to update the leaderboard with a new donation
        function UpdateDonationLeaderboard(steamID, amount)
            donationLeaderboard[steamID] = (donationLeaderboard[steamID] or 0) + amount
        end
        
        -- Example integration with donation rewards
        -- Call UpdateDonationLeaderboard(ply:SteamID(), donationAmount) after a successful donation
        
        -- Command to display the leaderboard in-game
        concommand.Add("show_donation_leaderboard", function(ply, cmd, args)
            local sortedLeaderboard = {}
            for id, total in pairs(donationLeaderboard) do
                table.insert(sortedLeaderboard, {steamID = id, total = total})
            end
            table.sort(sortedLeaderboard, function(a, b) return a.total > b.total end)
            ply:ChatPrint("Donation Leaderboard:")
            for i, entry in ipairs(sortedLeaderboard) do
                ply:ChatPrint(i .. ". " .. entry.steamID .. " - $" .. entry.total)
            end
        end)
    end
    
  6. Save the file after editing.

  7. Restart your server from the VolticHost Game Panel to load the new leaderboard script.

Donation leaderboard script created and loaded successfully!


2️⃣ Next Step - Integrating and Testing the Leaderboard

  1. Ensure that your existing donation system calls the UpdateDonationLeaderboard function after a donation is processed. For example, after granting a reward, add:

    UpdateDonationLeaderboard(ply:SteamID(), donationAmount)
    
  2. Restart your server to apply any changes to your donation scripts.

  3. In-game, test the leaderboard by running the command:

    show_donation_leaderboard
    

    This should display a sorted list of top donors along with their donation totals.

Donation leaderboard integrated and tested successfully!


🎉 Conclusion

You have now successfully created a donation leaderboard on your Garry's Mod server using the VolticHost Game Panel! Showcase your top donors and encourage community support with this engaging feature. 🚀

For more assistance, contact VolticHost Support.