Donator manager script

Helllo folks, trying to make a script that does a few things: can add people to donator with concommand ‘adddonator [player] [how long]’ and ‘adddonatorbyid [steamid] [how long]’. I want to be able to call IsDonator() (i.e. PS.Config.CalculateBuyPrice = function(ply, item) if ply:IsDonator() then return math.Round(item.Price * 0.75) end) from anywhere.

I am also trying to get it to store donators in a MySQL database, but in sv.db would be fine if I could do that.

A couple questions I have:

How would I go about storing something in a database, like reading and writing mysql tables from LUA?
How could I make a function be able to be called on a object like ply and return a boolean?

I’m not asking for somebody to write this whole thing out for me, I’d like to do it myself, but I’m a busy guy, and my communities developers are semi-retarded, so a shell of the script would be nice too.

[lua]
local meta = FindMetaTable(“Player”)

function meta:IsDonator()

return self:IsUserGroup(“vip”)

end
[/lua]

Wouldn’t IsUserGroup(“vip”) resolve to ULX?
I would prefer to keep ulx completely separate from my donator script so members and staff can donate without having to pull any strings.

Yes, IsUserGroup is mainly for ULX.
What admin mod are you using?

ULX, but since you can’t have more than one group for someone in ULX, I need this to be completely separate.

I don’t understand why you would need more than one group for someone in ULX, pretty sure you’re over thinking this.

Because if I wanted someone to be a donator and a moderator, so I could use IsUserGroup(‘donator’), whilst they have all their moderator stuff and name tags.

Other way around. ULX uses IsUserGroup which is built-in to gmod.

So it is possible for me to utilize IsUserGroup() without fucking with ULX?

How could I add a timed system (date based, so like 2 months of a certain IsUserGroup()), in the metatable?

You want something to trigger when a person is in a user group for 2 months? I’m not sure what you mean. The two functions built-in are pretty simple.

Player:SetUserGroup(“something”)
Player:IsUserGroup(“something”)

By default it will also read users.txt and set people to groups defined in there (for admins usually).

Learn SQL, use that

I want to be able to set how long a person will be in a group, like say, set someone to donator for 2 months and have a concommand to set this.

So if I set a user’s group to donator, they can be a different group seen by ulx, correct? And it’ll store my donator’s data in users.txt?

Like i said, learn the time format in sql, and check every so often, SQL is great for that .

How would I go about accessing sql tables from Garry’s Mod LUA?

Default SQLite ? Or install the mysql module ?

SQLite

Okay, so I worked on it a little, and I have a hacky weird broken ass shell of a script.

I looked over SQL a little bit, and know my script is borked as fuck, but I wrote it in maybe 2/3 minutes and used some resources. I can’t think really, tonight, so I just threw shit together. It looks sort of like lua, but it’s not, really. Any suggestions for making this look more functional, just wanting to have a little fun and practice, or just wanting to be nice, appreciated.

Add me on steam Bearclaw_ if you’re nice, and want to help.

Current broken ass shell of a script/far from functional:



// Donator Management Script

local IsDonator = false

local meta = FindMetaTable("Player")

function meta:IsDonator()
	return GetDonatorInfo()
end

function GetDonatorInfo( ply, steamid )
	IsDonator = sql.QueryValue("SELECT isdonator from player_info WHERE unique_id = '"steamid"'")
	return IsDonator
end


function tables_exist()
 
	if (sql.TableExists("player_info") then
		Msg("Tables are Geed to go !")
	else
		if (!sql.TableExists("player_info")) then
			query = "CREATE TABLE player_info ( unique_id varchar(255), isdonator BOOL )"
			result = sql.Query(query)
			if (sql.TableExists("player_info")) then
				Msg("Yo table has been made 
")
			else
				Msg("Somthing went wrong with the query ! 
")
				Msg( sql.LastError( result ) .. "
" )
			end	
		end
	end
end

add_donation( ply, length )
	// code to add player donator data to sql tables
	local isAlreadyInSystem = sql.Query("unique_id = '"..steamID.."'")
	
	if isAlreadyInSystem then new_donator( ply, length ) end
	
	steamid = ply:GetNetworkedString("steamid")
	sql.Query("UPDATE player_info SET isdonator = true WHERE unique_id = '"..steamid.."'")
	ply:ChatPrint("UserAdded !")	
end

function new_donator( ply, length )
 
		steamID = SteamID
		sql.Query( "INSERT INTO player_info (`unique_id`, `money`)VALUES ('"..steamID.."', '100')" )
		result = sql.Query( "SELECT unique_id, money FROM player_info WHERE unique_id = '"..steamID.."'" )
		if (result) then
 
			sql.Query( "INSERT INTO player_skills (`unique_id`, `speech`, `fish`, `farm`)VALUES ('"..steamID.."', '1', '1', '1')" )
			result = sql.Query( "SELECT unique_id, speech, fish, farm FROM player_skills WHERE unique_id = '"..steamID.."'" )
			if (result) then
				Msg("Player account created !
")
				sql_value_stats( ply )
				sql_value_skills( ply )
			else
				Msg("Something went wrong with creating a players skills !
")
			end
 
		else
			Msg("Something went wrong with creating a players info !
")
		end
end

add_donator( ply, length)
	ply:SetNetworkedString("steamid", steamid)
	tables_exist()
	add_donation( ply, length )
end

function getAutoCompleteOptions(add_donator,steamid,length)
    return "donator..[name]..[length(months)]"
end

concommand.Add("donator",add_donator,getAutoCompleteOptions)