Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Check if user is a member on the forum and then gives them a reward
- ]]
- require ("mysqloo")
- local ForumCheck = {}
- ForumCheck.Config = {}
- ForumCheck.Config.Hostname = '127.0.0.1' --MYSQL Hostname
- ForumCheck.Config.Port = 3306 -- MYSQL Port
- ForumCheck.Config.Username = 'forums' --MYSQL Username
- ForumCheck.Config.Password = '&%6=d!ghh8Y%WUt+' --MYSQL Password
- ForumCheck.Config.Database = 'xplosion_forums' --MYSQL Database
- ForumCheck.Config.Table = 'mybb_users' --MYSQL Table
- ForumCheck.Config.SteamID = 'steamid' --MYSQL Field where SteamID is stored
- ForumCheck.Config.ForumURL = "https://xplosionnetwork.com/" -- This is the URL of your group.
- ForumCheck.Config.JoinCommand = "!forum" -- The command typed to join the group
- ForumCheck.Config.RewardMessage = "Join our Forum and receive $5000 by typing !forum" -- The message that is displayed at the below interval
- ForumCheck.Config.RewardMessageInterval = 360 -- This is the time between each announcement. Set it to 0 to disable it.
- ForumCheck.Config.MembershipStatusMessage = "Your forum membership status will be checked in %s."
- ForumCheck.Config.AlreadyJoinedMessage = "You've already received your reward." -- Message when the player has already received the reward.
- ForumCheck.Config.NotMemberOnForum = "Sorry %s but we couldn't find you on the forums or you took too long to join. Please try again." -- Message when the player takes too long to join forums or cannot be found.
- ForumCheck.Config.VerificationTime = 45 -- This is the time given for the player to join the group after typing the command.
- ForumCheck.Config.RewardSuccessMessage = "Thank you for joining our Forum, you have received your reward!" -- Message sent to the player after they join the group.
- ForumCheck.Config.RewardSuccessBroadcast = "%s has just joined our Forum and received $5000!" -- Message broadcasted to the server when they join the group.
- ForumCheck.Config.RewardFunction = function(ply) -- Function that gives the player their reward.
- ply:addMoney(5000)
- timer.Remove( "ForumCheck" .. ply:SteamID64() )
- forumchecktimer[ply] = false
- end
- function GiveItemByPrintName( ply, printName )
- local itemClass = Pointshop2.GetItemClassByPrintName( printName )
- if not itemClass then
- error( "Invalid item " .. tostring( printName ) )
- end
- return ply:PS2_EasyAddItem( itemClass.className )
- end
- function connectToDatabase(ply)
- databaseObject = mysqloo.connect(ForumCheck.Config.Hostname, ForumCheck.Config.Username, ForumCheck.Config.Password, ForumCheck.Config.Database, ForumCheck.Config.Port)
- databaseObject.onConnected = function()
- print("Database connected!")
- IsPlayerForumMember(ply)
- end
- databaseObject.onConnectionFailed = function()
- print("Failed to connect to the database.")
- end
- databaseObject:connect()
- end
- function checkQuery(query)
- local playerInfo = query:getData()
- if playerInfo[1] ~= nil then
- return true
- else
- return false
- end
- end
- function IsPlayerForumMember( ply )
- local PlayerSteamID = ply:SteamID64()
- local query1 = databaseObject:query("SELECT " .. ForumCheck.Config.SteamID .. " FROM " .. ForumCheck.Config.Table .. " WHERE " .. ForumCheck.Config.SteamID .. " = '" .. PlayerSteamID .. "'")
- query1.onSuccess = function(q)
- if checkQuery(q) then
- ply:SetPData("ForumCheck", true)
- ply:ColChatPrint( "Forum", ForumCheck.Config.RewardSuccessMessage)
- for k,v in ipairs(player.GetAll()) do
- if v == ply then continue end
- v:ColChatPrint( "Forum", string.format(ForumCheck.Config.RewardSuccessBroadcast, ply:Name()))
- end
- ForumCheck.Config.RewardFunction(ply)
- else
- ply:ColChatPrint( "Forum", string.format(ForumCheck.Config.NotMemberOnForum, ply:Name()))
- end
- end
- query1.onError = function(q,e) print("something went wrong when checking") end
- query1:start()
- end
- hook.Add("PlayerSay", "ForumCheck", function(p,t)
- if t:lower() ~= ForumCheck.Config.JoinCommand:lower() then return end
- if not forumchecktimer[ply] then
- return false
- end
- if tobool(p:GetPData("ForumCheck")) == true then
- p:ColChatPrint( "Forum", ForumCheck.Config.AlreadyJoinedMessage)
- return false
- end
- p:SendLua('gui.OpenURL("'..ForumCheck.Config.ForumURL..'")')
- p:ColChatPrint( "Forum", string.format(ForumCheck.Config.MembershipStatusMessage, string.NiceTime(ForumCheck.Config.VerificationTime)))
- timer.Create( "ForumCheck" .. ply:SteamID64(), ForumCheck.Config.VerificationTime, 1, function()
- forumchecktimer[ply] = true
- if not IsValid(p) then return end
- connectToDatabase(p)
- end )
- return false
- end)
- if ForumCheck.Config.RewardMessageInterval > 0 then
- timer.Create("ForumCheck", ForumCheck.Config.RewardMessageInterval, 0, function()
- for k,v in ipairs(player.GetAll()) do
- if tobool(v:GetPData("ForumCheck")) == false then
- v:ColChatPrint( "Forum", ForumCheck.Config.RewardMessage)
- return false
- end
- end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement