In this tutorial, you'll learn how to set up a virtual currency system on your Garry's Mod server. This system lets players convert real money into virtual credits which they can then spend on in-game items. We'll create a basic Lua script to track and manage player currency, laying the groundwork for integrating real money transactions. 🚀
📌 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
-
(Optional) A payment gateway setup for processing real money transactions
1️⃣ First Step - Creating the Virtual Currency Script
-
Log in to VolticHost Game Panel.
-
Navigate to the File Manager from the main dashboard.
-
Go to the
/garrysmod/lua/autorun/server/
directory. -
Create a new file named
virtual_currency.lua
. -
Open
virtual_currency.lua
for editing and paste the following script:if SERVER then util.AddNetworkString("CurrencyUpdate") local playerCurrency = {} hook.Add("PlayerInitialSpawn", "InitializeCurrency", function(ply) local steamID = ply:SteamID() playerCurrency[steamID] = playerCurrency[steamID] or 0 end) concommand.Add("check_currency", function(ply) local steamID = ply:SteamID() local currency = playerCurrency[steamID] or 0 ply:ChatPrint("Your current currency: $" .. currency) end) function AddCurrency(ply, amount) local steamID = ply:SteamID() playerCurrency[steamID] = (playerCurrency[steamID] or 0) + amount net.Start("CurrencyUpdate") net.WriteInt(playerCurrency[steamID], 32) net.Send(ply) end end
-
Save the file after editing.
-
Restart your server from the VolticHost Game Panel to load the new script.
✅ Virtual currency script created and loaded successfully!
2️⃣ Next Step - Simulating Real Money Transactions
-
In the same
virtual_currency.lua
file, add a command to simulate a purchase that credits virtual currency:concommand.Add("simulate_purchase", function(ply) local amount = 100 -- Simulated credit amount for a real money purchase AddCurrency(ply, amount) ply:ChatPrint("Purchase successful! $" .. amount .. " added to your account.") end)
-
Save the changes to the file.
-
Restart your server from the VolticHost Game Panel again to apply the update.
-
Test the simulation by opening the in-game console and typing:
simulate_purchase
Then, check your currency with:
check_currency
✅ Virtual currency purchase simulation executed and verified successfully!
🎉 Conclusion
You have now successfully implemented a virtual currency system on your Garry's Mod server using the VolticHost Game Panel! This setup provides a foundation for integrating real money transactions, allowing players to convert their purchases into virtual credits for in-game use. 🚀
For more assistance, contact VolticHost Support.