Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require("mysqloo")
- local DATABASE_HOST = ""
- local DATABASE_PORT = "3306" //most common damn port
- local DATABASE_NAME = ""
- local DATABASE_USERNAME = ""
- local DATABASE_PASSWORD = ""
- local databaseObject = NULL;
- function connectToDatabase( )
- databaseObject = mysqloo.connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME, DATABASE_PORT);
- databaseObject.onConnected = function( )
- print("Database connection successful.");
- end
- databaseObject.onConnectionFailed = function( )
- print("Database connection failed.");
- end
- databaseObject:connect()
- end
- hook.Add("Initialize", "init_db", connectToDatabase)
- function checkQuery( query )
- local playerInfo = query:getData();
- if (playerInfo[1] && playerInfo[1] != "") then
- return true;
- end
- return false;
- end
- function firstJoin( Player )
- local Query = databaseObject:query("SELECT * FROM Players WHERE ID = '" .. Player:SteamID() .. "'");
- Query.onSuccess = function( toCheck );
- if !checkQuery(toCheck) then
- local Query = databaseObject:query("INSERT INTO Players(ID, Money) VALUES ('" .. Player:SteamID() .. "', '" .. 1000 .. "')");
- Query.onSuccess = function( query ) print("Account created for " .. ".");
- Query.onError = function( query, Error ) print("Something went wrong when trying to create an account for " .. Player:Nick() .. ".");
- Query.start();
- else
- print( Player:Nick() .. " has logged on.");
- end
- Query.onError = function( Query, Error )
- print("Authenticating issue has occurred.");
- end
- Query.start();
- end
- hook.Add("PlayerInitialSpawn", "PInitSpawn", firstJoin)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement