Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.89 KB | None | 0 0
  1. --[[
  2. Check if user is a member on the forum and then gives them a reward
  3. ]]
  4. require ("mysqloo")
  5. local ForumCheck = {}
  6. ForumCheck.Config = {}
  7.  
  8. ForumCheck.Config.Hostname = '127.0.0.1' --MYSQL Hostname
  9. ForumCheck.Config.Port = 3306 -- MYSQL Port
  10. ForumCheck.Config.Username = 'forums' --MYSQL Username
  11. ForumCheck.Config.Password = '&%6=d!ghh8Y%WUt+' --MYSQL Password
  12. ForumCheck.Config.Database = 'xplosion_forums' --MYSQL Database
  13. ForumCheck.Config.Table = 'mybb_users' --MYSQL Table
  14. ForumCheck.Config.SteamID = 'steamid' --MYSQL Field where SteamID is stored
  15.  
  16. ForumCheck.Config.ForumURL = "https://xplosionnetwork.com/" -- This is the URL of your group.
  17. ForumCheck.Config.JoinCommand = "!forum" -- The command typed to join the group
  18. ForumCheck.Config.RewardMessage = "Join our Forum and receive $5000 by typing !forum" -- The message that is displayed at the below interval
  19. ForumCheck.Config.RewardMessageInterval = 360 -- This is the time between each announcement. Set it to 0 to disable it.
  20. ForumCheck.Config.MembershipStatusMessage = "Your forum membership status will be checked in %s."
  21. ForumCheck.Config.AlreadyJoinedMessage = "You've already received your reward." -- Message when the player has already received the reward.
  22. 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.
  23. ForumCheck.Config.VerificationTime = 45 -- This is the time given for the player to join the group after typing the command.
  24. ForumCheck.Config.RewardSuccessMessage = "Thank you for joining our Forum, you have received your reward!" -- Message sent to the player after they join the group.
  25. ForumCheck.Config.RewardSuccessBroadcast = "%s has just joined our Forum and received $5000!" -- Message broadcasted to the server when they join the group.
  26. ForumCheck.Config.RewardFunction = function(ply) -- Function that gives the player their reward.
  27.     ply:addMoney(5000)
  28.     timer.Remove( "ForumCheck" .. ply:SteamID64() )
  29.     forumchecktimer[ply] = false
  30. end
  31.  
  32. function GiveItemByPrintName( ply, printName )
  33.         local itemClass = Pointshop2.GetItemClassByPrintName( printName )
  34.         if not itemClass then
  35.                 error( "Invalid item " .. tostring( printName ) )
  36.         end
  37.         return ply:PS2_EasyAddItem( itemClass.className )
  38. end
  39.  
  40. function connectToDatabase(ply)
  41.     databaseObject = mysqloo.connect(ForumCheck.Config.Hostname, ForumCheck.Config.Username, ForumCheck.Config.Password, ForumCheck.Config.Database, ForumCheck.Config.Port)
  42.     databaseObject.onConnected = function()
  43.         print("Database connected!")
  44.         IsPlayerForumMember(ply)
  45.     end
  46.     databaseObject.onConnectionFailed = function()
  47.         print("Failed to connect to the database.")
  48.     end
  49.     databaseObject:connect()
  50. end
  51.  
  52. function checkQuery(query)
  53.     local playerInfo = query:getData()
  54.     if playerInfo[1] ~= nil then
  55.         return true
  56.     else
  57.         return false
  58.     end
  59. end
  60.  
  61. function IsPlayerForumMember( ply )
  62.     local PlayerSteamID = ply:SteamID64()
  63.     local query1 = databaseObject:query("SELECT " .. ForumCheck.Config.SteamID .. " FROM " .. ForumCheck.Config.Table .. " WHERE " .. ForumCheck.Config.SteamID .. " = '" .. PlayerSteamID .. "'")
  64.     query1.onSuccess = function(q)
  65.         if checkQuery(q) then
  66.             ply:SetPData("ForumCheck", true)
  67.             ply:ColChatPrint( "Forum", ForumCheck.Config.RewardSuccessMessage)
  68.             for k,v in ipairs(player.GetAll()) do
  69.                 if v == ply then continue end
  70.                 v:ColChatPrint( "Forum", string.format(ForumCheck.Config.RewardSuccessBroadcast, ply:Name()))
  71.             end
  72.             ForumCheck.Config.RewardFunction(ply)
  73.         else
  74.             ply:ColChatPrint( "Forum", string.format(ForumCheck.Config.NotMemberOnForum, ply:Name()))
  75.         end
  76.     end
  77.     query1.onError = function(q,e) print("something went wrong when checking") end
  78.     query1:start()
  79. end
  80.  
  81. hook.Add("PlayerSay", "ForumCheck", function(p,t)
  82.    
  83.     if t:lower() ~= ForumCheck.Config.JoinCommand:lower() then return end
  84.    
  85.     if not forumchecktimer[ply] then
  86.         return false
  87.     end
  88.  
  89.     if tobool(p:GetPData("ForumCheck")) == true then
  90.         p:ColChatPrint( "Forum", ForumCheck.Config.AlreadyJoinedMessage)
  91.         return false
  92.     end
  93.  
  94.     p:SendLua('gui.OpenURL("'..ForumCheck.Config.ForumURL..'")')
  95.     p:ColChatPrint( "Forum", string.format(ForumCheck.Config.MembershipStatusMessage, string.NiceTime(ForumCheck.Config.VerificationTime)))
  96.     timer.Create( "ForumCheck" .. ply:SteamID64(), ForumCheck.Config.VerificationTime, 1, function()
  97.         forumchecktimer[ply] = true
  98.         if not IsValid(p) then return end
  99.         connectToDatabase(p)
  100.     end )
  101.     return false
  102. end)
  103.  
  104. if ForumCheck.Config.RewardMessageInterval > 0 then
  105.     timer.Create("ForumCheck", ForumCheck.Config.RewardMessageInterval, 0, function()
  106.         for k,v in ipairs(player.GetAll()) do
  107.             if tobool(v:GetPData("ForumCheck")) == false then
  108.                 v:ColChatPrint( "Forum", ForumCheck.Config.RewardMessage)
  109.                 return false
  110.             end
  111.         end
  112.     end)
  113. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement