Home Garry's Mod Setting Up a Server Voting System on a Garry's Mod Server

Setting Up a Server Voting System on a Garry's Mod Server

Last updated on Feb 13, 2025

This tutorial will show you how to set up a simple server voting system on your Garry's Mod server using a custom Lua script via the VolticHost Game Panel. This system allows players to cast votes (for maps, events, or any custom option) directly from the chat, with a summary announced automatically. πŸš€


πŸ“Œ Prerequisites

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

  • Access to the VolticHost Game Panel

  • Basic knowledge of Lua scripting and file management

  • Familiarity with in-game chat commands


1️⃣ First Step - Creating the Voting System 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 vote_system.lua.

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

    if SERVER then
        util.AddNetworkString("VoteSystem")
        local votes = {}
    
        hook.Add("PlayerSay", "HandleVoteCommands", function(ply, text)
            local option = string.match(text, "^!vote%s+(%S+)")
            if option then
                table.insert(votes, {player = ply:Nick(), vote = option})
                PrintMessage(HUD_PRINTTALK, ply:Nick() .. " voted for " .. option)
                return ""
            end
        end)
    
        timer.Create("AnnounceVotes", 60, 0, function()
            if #votes > 0 then
                PrintMessage(HUD_PRINTTALK, "Vote summary:")
                for _, v in ipairs(votes) do
                    PrintMessage(HUD_PRINTTALK, v.player .. " voted for " .. v.vote)
                end
                votes = {}
            end
        end)
    end
    
  6. Replace or adjust any parts of the script as needed for your server’s voting options.

  7. Save the file after editing.

βœ… Voting system script created and saved successfully!


2️⃣ Next Step - Activating and Testing the Voting System

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

  2. Connect to your Garry's Mod server and open the chat.

  3. Test the system by typing a command such as:

    !vote map1
    

    This command should record your vote and announce it to all players.

  4. Wait for the automatic vote summary (announced every 60 seconds) to confirm that all votes are tallied.

βœ… Voting system activated and tested successfully!


πŸŽ‰ Conclusion

You have now successfully set up a server voting system on your Garry's Mod server using the VolticHost Game Panel! Enjoy enhanced player interaction as your community casts votes for maps, events, or custom options. πŸš€

For more assistance, contact VolticHost Support.