So i currently own a TF2 server and i have a numbe rof VIPS on there that are stored into a mysql database, then i decited to buy a garrysmod server and turn it into a TTT only server but i wanted to get some cool addons for it. Then i found this
[URL="http://www.facepunch.com/threads/1119621"]GoldenForge-Hat/Trails Shop[/URL]
I want to make this for my vips, but i have there information setup in a mysql database, i understand the whole timer part
[lua]timer.Create( "gsmem", 60, 0, function()
for k, v in pairs(GF.GetPlayers()) do
if v:IsUserGroup("vip") then
v:GiveScrapMeatal(15, "Thanks For Donating to the server, you get 15 more metal in 1 min")
else
v:GiveScrapMetal(2, "Thanks for playing on VDGN TTT Server, you receive more metal in 1 min")
end
end
end)[/lua]
which is checking if the user is in the custom group "vip", but that information is stored in the Garry's Mod root folder>\settings\users.txt... How can i get it to read the steamid from my database and make them part of that group?
All i want is to give VIPs more metal then other players, but i need help setting up the actual group. (How do i get the groups setup via mysql)
I do know a bit about coding since i have been reading up on books and making some simple projects but i am still in a very nooby stage when it comes to lua coding for gmod..
So what do i need, im pretty sure there's a (modual?) for mysql for gmod? Do i need that and if so how would i use it to get all of the players on the database updated to VIP (And when they are removed from the database they will become a normal player again and not a VIP)
EDIT: I found [URL="http://www.facepunch.com/threads/933647"]THIS[/URL], i understand how to put my database info into it but how would i get my players STEAMID and make them each VIPS and or make them normal players if they are not in the database and are not admins/superadmins?
You use the player.SteamID method to get their SteamID.
Then you need to use a select query to see if they are a VIP or not in a mysql query.
I would suggest looking at some tutorials on Mysql at w3schools.
[QUOTE=zzaacckk;32072436]You use the player.SteamID method to get their SteamID.
Then you need to use a select query to see if they are a VIP or not in a mysql query.
I would suggest looking at some tutorials on Mysql at w3schools.[/QUOTE]
Cool ill take a look ^^ and i use that site as a reference for my site im working on
[editline]2nd September 2011[/editline]
OKay this is what i got :]
This is located into the test/MySQL00 folder of the mysql00 addon folder. (Tell me if it should be in there or not)
vipcheck.lua
[lua]
require("mysqloo")
local DATABASE_HOST = "HOST"
local DATABASE_PORT = PORT
local DATABASE_NAME = "DATABASE_vip"
local DATABASE_USERNAME = "DATABASE_user"
local DATABASE_PASSWORD = "PASSWORD"
local ID_STEAM = player.SteamID()
function makeVIP(query)
player:SetUserGroup("vip")
end
function afterConnected(database)
local query1 = database:query("SELECT steamid FROM donators WHERE steamid == ID_STEAM")
query1.onData = function(Q,D) print("Q1") PrintTable(D) end
query1.onSuccess = makeVIP
query1.onError = function(Q,E) print("Q1") print(E) end
query1:start()
end
function connectToDatabase()
local databaseObject = mysqloo.connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME, DATABASE_PORT)
databaseObject.onConnected = afterConnected
databaseObject:connect()
end
connectToDatabase()
[/lua]
Like i said im a bit new to lua but im learning :]
I would use a COUNT query to tell you the amount of times that the given SteamID is depicted in the mysql table.
e.g.
[code]"SELECT COUNT(*) FROM donators WHERE steamid = '" .. ID_STEAM .. "'"[/code]
Okay so it would be this
[lua]
require("mysqloo")
local DATABASE_HOST = "HOST"
local DATABASE_PORT = PORT
local DATABASE_NAME = "DATABASE_vip"
local DATABASE_USERNAME = "DATABASE_user"
local DATABASE_PASSWORD = "PASSWORD"
local ID_STEAM = player.SteamID()
function makeVIP(query)
player:SetUserGroup("vip")
end
function afterConnected(database)
local query1 = database:query("SELECT COUNT(*) FROM donators WHERE steamid = '" .. ID_STEAM .. "'")
query1.onData = function(Q,D) print("Q1") PrintTable(D) end
query1.onSuccess = makeVIP
query1.onError = function(Q,E) print("Q1") print(E) end
query1:start()
end
function connectToDatabase()
local databaseObject = mysqloo.connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME, DATABASE_PORT)
databaseObject.onConnected = afterConnected
databaseObject:connect()
end
connectToDatabase()
[/lua]
And did i place the files in the right locations?
Anyone please? :}
BUMP: All i need to know is where do i put the vipcheck.lua file and if im calling it right with the connectToDatabase() or should i use some type of hook, if so which one? Someone please help me :/
You have alot of errors in your code.
ID_STEAM should equal ply:SteamID()
MakeVIP isnt being called, isnt using the query, nor is the player argument passed.
Ill try to fix this for you in an hour or so if someone else dosent, but I am a bit busy right now.
Thank you :] oh and ID_STEAM does equal i just didn't put it up its a local also if that matters
EDIT: Anyone?
BUMP:Can someone help me please :/
Okay well the script works when i use the lua_openfile thing but i cant seem to get it to load once the player joins..
at the end of the file on the last line i added a hook for PlayerInitialSpawn and when i join the server nothing happens.. No error no nothing... The file is located in the lua/autorun/server folder.. Whats going on?
Sorry, you need to Log In to post a reply to this thread.