Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.56 KB | None | 0 0
  1. ------------------------------------------------------------------
  2. -- ______ _____ __ _ _______ _______ _____ _____ __ _ --
  3. -- | \ | | | \ | |_____| | | | | | \ | --
  4. -- |_____/ |_____| | \_| | | | __|__ |_____| | \_| --
  5. -- --
  6. -- _ _ _______ __ __ _______ --
  7. -- |____/ |______ \_/ |______ --
  8. -- | \_ |______ | ______| --
  9. ------------------------------------------------------------------
  10.  
  11. -- Welcome to the Donation keys script! Follow these instructions and
  12. -- you will be able to have a successful donation key system on your
  13. -- server!
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34. local DONATIONTYPES = {}
  35.  
  36. if SERVER then
  37. util.AddNetworkString("cl_sendDonationKey")
  38. local ulx = true; -- Are you using ulx?
  39. local evolve = false; -- Are you using evolve?
  40. -- if we are not using any of the above we assume you are using default FAdmin
  41.  
  42. DONATIONTYPES["1"] = function(ply)
  43. --code to apply reward for donation of type 1
  44. ply:addMoney(10000)
  45. ply:PrintMessage(HUD_PRINTTALK, "You received 10k cash!")
  46. game.ConsoleCommand("say " ..ply:Nick().. " Has purchased 10k cash! Thank you!")
  47. end
  48. DONATIONTYPES["2"] = function(ply)
  49. if(ulx)then
  50. game.ConsoleCommand("ulx adduser "..ply:Nick().." donator")
  51. elseif(evolve) then
  52. game.ConsoleCommand("ev rank "..ply:Nick().." donator")
  53. else
  54. ply:SetUserGroup("donator")
  55. end
  56. ply:addMoney(50000)
  57. ply:PrintMessage(HUD_PRINTTALK, "You received donator status and 50k cash!")
  58. game.ConsoleCommand("say " ..ply:Nick().. " Has purchased 50k! Thank you!")
  59. end
  60.  
  61. DONATIONTYPES["3"] = function(ply)
  62. if(ulx)then
  63. game.ConsoleCommand("ulx adduser "..ply:Nick().." donator")
  64. elseif(evolve) then
  65. game.ConsoleCommand("ev rank "..ply:Nick().." donator")
  66. else
  67. ply:SetUserGroup("donator")
  68. end
  69. ply:addMoney(100000)
  70. ply:PrintMessage(HUD_PRINTTALK, "You received donator status and 100k cash!")
  71. game.ConsoleCommand("say " ..ply:Nick().. " Has purchased 1ook Thank you!")
  72. end
  73.  
  74. DONATIONTYPES["4"] = function(ply)
  75. if(ulx)then
  76. game.ConsoleCommand("ulx adduser "..ply:Nick().." Vip")
  77. elseif(evolve) then
  78. game.ConsoleCommand("ev rank "..ply:Nick().." Vip")
  79. else
  80. ply:SetUserGroup("Xeon")
  81. end
  82. ply:addMoney(250000)
  83. ply:PrintMessage(HUD_PRINTTALK, "You received Vip status and 250k cash!")
  84. game.ConsoleCommand("say " ..ply:Nick().. " Has purchased 250k! Thank you!")
  85. end
  86.  
  87. DONATIONTYPES["5"] = function(ply)
  88. if(ulx)then
  89. game.ConsoleCommand("ulx adduser "..ply:Nick().." Super-Vip")
  90. elseif(evolve) then
  91. game.ConsoleCommand("ev rank "..ply:Nick().." Super-Vip")
  92. else
  93. ply:SetUserGroup("Super-Vip")
  94. end
  95. ply:addMoney(250000)
  96. ply:PrintMessage(HUD_PRINTTALK, "You received Super-Vip status and 1m cash!")
  97. game.ConsoleCommand("say " ..ply:Nick().. " Has purchased 1m! Thank you!")
  98. end
  99. DONATIONTYPES["6"] = function(ply)
  100.  
  101. ply:PS_GivePoints(5000)
  102. ply:PrintMessage(HUD_PRINTTALK, "You received 5k points!")
  103. game.ConsoleCommand("say " ..ply:Nick().. " Has purchased 5k points! Thank you!")
  104. end
  105.  
  106. DONATIONTYPES["7"] = function(ply)
  107. if(ulx)then
  108. game.ConsoleCommand("ulx adduser "..ply:Nick().." donator")
  109. end
  110. ply:PS_GivePoints(50000)
  111. ply:PrintMessage(HUD_PRINTTALK, "You received 50k points!")
  112. game.ConsoleCommand("say " ..ply:Nick().. " Has purchased 50k points and donator rank ! Thank you!")
  113. end
  114.  
  115. DONATIONTYPES["8"] = function(ply)
  116. game.ConsoleCommand("ulx adduser "..ply:Nick().." donator")
  117. ply:PS_GivePoints(100000)
  118. ply:PrintMessage(HUD_PRINTTALK, "You received 100k points and donator rank!")
  119. game.ConsoleCommand("say " ..ply:Nick().. " Has purchased 100k points! Thank you!")
  120. end
  121.  
  122. DONATIONTYPES["9"] = function(ply)
  123. game.ConsoleCommand("ulx adduser "..ply:Nick().." Vip")
  124. ply:PS_GivePoints(250000)
  125. ply:PrintMessage(HUD_PRINTTALK, "You received 250k points and vip rank!")
  126. game.ConsoleCommand("say " ..ply:Nick().. " Has purchased 250k points! Thank you!")
  127. end
  128.  
  129.  
  130. DONATIONTYPES["10"] = function(ply)
  131. game.ConsoleCommand("ulx adduser "..ply:Nick().." Super-Vip")
  132. ply:PS_GivePoints(100000)
  133. ply:PrintMessage(HUD_PRINTTALK, "You received 500k points and supervip rank!")
  134. game.ConsoleCommand("say " ..ply:Nick().. " Has purchased 500k points! Thank you!")
  135. end
  136. end
  137.  
  138. if CLIENT then
  139.  
  140. --This is the chat command. THIS CHAT COMMAND ONLY WORKS ON DARKRP. If you are using anything else you need
  141. -- to delete the code between the word start and end. Users can redeem their code by openeing console and typing redeem.
  142.  
  143.  
  144. --START
  145. hook.Add( "OnPlayerChat", "donateCommand", function( ePlayer, sText )
  146.  
  147. if ( ePlayer ~= LocalPlayer() ) then
  148. return;
  149. end
  150.  
  151. if ( string.StartWith( string.lower( sText ), "/redeem" ) ) then
  152. DonationKeyEnter();
  153. return;
  154. end
  155.  
  156. end );
  157.  
  158. --END
  159.  
  160. function DonationKeyEnter()
  161. local frame = vgui.Create("DFrame")
  162. frame:SetPos(ScrW()/2-200,ScrH()/2-100)
  163. frame:SetSize(400,100)
  164. frame:SetTitle("Redeem Donation Key")
  165. frame:SetVisible(true)
  166. frame:ShowCloseButton(true)
  167. frame:MakePopup()
  168. frame.Paint = function()
  169. draw.RoundedBox(4,0,0,frame:GetWide(),frame:GetTall(),Color(0,0,0,170))
  170. end
  171.  
  172. local label = vgui.Create("DLabel", frame)
  173. label:SetText("Enter your key and press enter: ")
  174. label:SetPos(10,40)
  175. label:SizeToContents()
  176.  
  177. local textbox = vgui.Create("DTextEntry", frame)
  178. textbox:SetPos(15+label:GetWide(),40)
  179. textbox:SetSize(200,20)
  180. textbox:SetEnterAllowed(true)
  181. textbox.OnEnter = function()
  182. if(textbox:GetValue() == "") then return end
  183. net.Start("cl_sendDonationKey")
  184. net.WriteString(textbox:GetValue())
  185. net.SendToServer()
  186. end
  187. end
  188.  
  189. concommand.Add("redeem",DonationKeyEnter, 1.5)
  190.  
  191. end
  192.  
  193. if SERVER then
  194. require("tmysql4")
  195.  
  196. local host = "t-servers.site.nfoservers.com" //use this instead of locahost
  197. local user = "thalexs"
  198. local pass = "LTdcG3wvXn"
  199. local dbname = "thalexs_donations"
  200. local port = 3306
  201. local db = {}
  202. local err = ""
  203.  
  204. function connectDatabase()
  205.  
  206. db, err = tmysql.initialize( host,user,pass,dbname,port)
  207. end
  208.  
  209. hook.Add("Initialize", "connectDatabase", connectDatabase)
  210.  
  211. net.Receive("cl_sendDonationKey", function(len,ply)
  212. local key = net.ReadString()
  213. ProcessKey(ply,key)
  214. end)
  215.  
  216. function ProcessKey(ply,key)
  217.  
  218. db:Query("SELECT * FROM donationkeys WHERE donationkey='"..tmysql.escape(key).."' AND used=0", function(result,status,error)
  219. if status then
  220. if #result > 0 and #result < 2 then
  221. if DONATIONTYPES[result[1]["type"]] then
  222. DONATIONTYPES[result[1]["type"]](ply)
  223. db:Query("UPDATE donationkeys SET used=1 WHERE donationkey='"..tmysql.escape(key).."' AND used=0", function(res,stat,err)
  224. if stat then
  225. print(ply:Nick().."'s key was used, updated database")
  226. else
  227. print(ply:Nick().."'s key could not be updated, something went wrong: "..err)
  228. end
  229. end,1)
  230. else
  231. ply:PrintMessage(HUD_PRINTTALK,"Key found but no code exists, contact administrator")
  232. end
  233. elseif #result > 0 then
  234. ply:PrintMessage(HUD_PRINTTALK, "Multiple keys exist, contact administrator")
  235. else
  236. ply:PrintMessage(HUD_PRINTTALK, "Nothing found")
  237. end
  238. else
  239. ply:PrintMessage(HUD_PRINTTALK, "Could not contact server, contact administrator")
  240. end
  241. end, 1)
  242. db:Poll()
  243.  
  244. end
  245.  
  246. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement