MySQL help for noob!

Hey :slight_smile:

I have been asking help with MySQL from almost everyone i know, but no one can’t help me. So im asking help from here, maybe someone is friendly and can help me without moaning or saying “just google it fag”. For those “google guys”, i have already read many tutorials, but i just can’t understand them :stuck_out_tongue:

My Steam name is Niskuo


It might help if you ask a question, and post a problem you’re having.

It’s unlikely anyone is going to add you on steam to help you.

Are you talk-thanks for submitting phone-ing about adding mysqloo to your server?

That’s at the bottom of the post, and simple as all get out.

Question: How do i set up MySQL database for my gmod server? :slight_smile:

I have no idea what you’d like to do with the database.

So don’t i, but my friend said that i need database so players of my server “saves” their money in the database.

Pretty sure it already uses an inbuilt sqlite database which can be accessed by using PData…

Well, thats really nice to know after two weeks of research… Thanks btw lol, should i edit something from there?

just add me to steam i’ll help you.

Not really.

[lua]ply:SetPData( “where to”, “string”/int)[/lua]

then do

[lua]ply:GetPData( “where to” )[/lua]

To add onto this:

There is a built in SQL database that comes with gmod.

This database can be easily stored too and retrieved from by using the method “ply:SetPData()”

the arguements of this method are the name of the data you’d like to store, and it’s value.

So for a money addon, you’d want something that looks like this:

local Player = FindMetaTable("Player")
if !Player then return end

function Player:GetMoney()
	return self.Money or 0

function Player:CanAfford(num)
	return (self:GetMoney()-num) >= 0

if SERVER then
	function Player:SetMoney(num)
		self:SetPData("money", num)
		self.Money = num
			net.WriteInt(num, 32)
	function Player:AddMoney(num)
	local startMoney = 100
	hook.Add("PlayerInitialSpawn", "sh_money.PlayerInitialSpawn", function(ply)
		timer.Simple(1, function()	
			if !IsValid(ply) then return end
			ply:SetMoney(ply:GetPData("money", startMoney))
	net.Receive("ply_Money", function(len)
		local ply = net.ReadEntity()
		local num = net.ReadInt(32)
		if !IsValid(ply) then return end
		ply.Money = num

Note that this isn’t my code, it’s Brandonj4’s. You’d want to put this in your lua/autorun folder.