Advertisement
szymski

Untitled

Nov 11th, 2015
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.62 KB | None | 0 0
  1. /*-----------------------------------------------------------
  2. Chests
  3.  
  4. Dedicated solution for Rage-gaming.pl
  5.  
  6. This product cannot be redistributed.
  7.  
  8. Copyright © 2015 Szymon (Szymekk) Jankowski
  9. All Rights Reserved
  10. Steam: https://steamcommunity.com/id/szymski
  11. -------------------------------------------------------------*/
  12.  
  13. if SERVER then
  14. AddCSLuaFile()
  15.  
  16. resource.AddFile("sound/chest/pirate.wav")
  17.  
  18. resource.AddFile("materials/chests/2500.png")
  19. resource.AddFile("materials/chests/5000.png")
  20. resource.AddFile("materials/chests/10000.png")
  21. resource.AddFile("materials/chests/25000.png")
  22. resource.AddFile("materials/chests/keys.png")
  23. resource.AddFile("materials/chests/shoe.png")
  24. resource.AddFile("materials/chests/svip.png")
  25. resource.AddFile("materials/chests/2x.png")
  26. resource.AddFile("materials/chests/hook.png")
  27. resource.AddFile("materials/chests/main.png")
  28.  
  29. resource.AddFile("materials/models/custom/chest.vmt")
  30. resource.AddFile("models/custom/chest.mdl")
  31.  
  32. hook.Add("InitPostEntity", "ChestSpawn", function()
  33. timer.Simple(10, function()
  34. local ent = ents.Create("chest")
  35. ent:SetPos(Vector(-1423, 3301, -724.3))
  36. ent:SetAngles(Angle(0,90,0))
  37. ent:Spawn()
  38. ent:SetMoveType(MOVETYPE_NONE)
  39. end)
  40. end)
  41. end
  42.  
  43. /*--------------------------
  44. Prizes
  45. ----------------------------*/
  46.  
  47. local function GetPrize()
  48. local prize = { }
  49.  
  50. local rand = math.random(0,100)
  51.  
  52. if rand < 1 then
  53. prize.Name = "3 klucze"
  54. prize.Func = function(ply)
  55. ply:SetNWInt("chest_keys", (ply:GetNWInt("chest_keys") or 0) + 3)
  56. ply:SetPData("chest_keys", (ply:GetNWInt("chest_keys") or 0))
  57. end
  58. elseif rand < 3 then
  59. prize.Name = "SuperVIP"
  60. prize.Func = function(ply)
  61. ulx.tempadduser(Entity(0), ply, "svip", 43200, "user")
  62. end
  63. elseif rand < 5 then
  64. prize.Name = "2x money"
  65. prize.Func = function(ply)
  66. ply:addMoney(ply:getDarkRPVar("money"))
  67. end
  68. elseif rand < 10 then
  69. prize.Name = "$25000"
  70. prize.Func = function(ply)
  71. ply:addMoney(25000)
  72. end
  73. /*elseif rand < 15 then
  74. prize.Name = "20 bouncy balls"
  75. prize.Func = function(ply)
  76. timer.Create("chest_balls", 0.15, 30, function()
  77. local ent = ents.Create("sent_ball")
  78. ent:SetPos(ply:GetPos()+Vector(math.sin(RealTime()*5)*100,math.cos(RealTime()*5)*100,100))
  79. ent:SetBallSize(math.random( 16, 48 ))
  80. ent:Spawn()
  81. ent:Activate()
  82. end)
  83. end*/
  84. elseif rand < 20 then
  85. prize.Name = "Hat's hook"
  86. prize.Func = function(ply)
  87. ply:Give("realistic_hook")
  88. end
  89. elseif rand < 30 then
  90. prize.Name = "$10000"
  91. prize.Func = function(ply)
  92. ply:addMoney(10000)
  93. end
  94. elseif rand < 45 then
  95. prize.Name = "$5000"
  96. prize.Func = function(ply)
  97. ply:addMoney(5000)
  98. end
  99. else
  100. prize.Name = "$2500"
  101. prize.Func = function(ply)
  102. ply:addMoney(2500)
  103. end
  104. end
  105.  
  106. return prize
  107. end
  108.  
  109. concommand.Add("chest_allkeys", function()
  110. for k, v in pairs(player.GetAll()) do print(v:Name().." - "..(v:GetNWInt("chest_keys") or 0)) end
  111. end)
  112.  
  113. if SERVER then
  114. util.AddNetworkString("chest_start")
  115. util.AddNetworkString("chest_prize")
  116. util.AddNetworkString("chest_buykey")
  117. util.AddNetworkString("chest_keyend")
  118.  
  119. net.Receive("chest_buykey", function(len, ply)
  120. local code = net.ReadString()
  121.  
  122. http.Fetch("http://rage-gaming.pl/chest/check.php?check="..code, function(body)
  123. local valid = body == "1"
  124.  
  125. if valid then
  126. ply:SetNWInt("chest_keys", (ply:GetNWInt("chest_keys") or 0) + 2)
  127. ply:SetPData("chest_keys", (ply:GetNWInt("chest_keys") or 0))
  128. end
  129.  
  130. net.Start("chest_buykey")
  131. net.WriteBool(valid)
  132. net.Send(ply)
  133. end, function() end)
  134. end)
  135.  
  136. net.Receive("chest_start", function(len, ply)
  137. local prize = GetPrize()
  138.  
  139. local valid = (ply:GetNWInt("chest_keys") or 0) > 0
  140.  
  141. if valid then
  142. ply:SetNWInt("chest_keys", (ply:GetNWInt("chest_keys") or 0) - 1)
  143. ply:SetPData("chest_keys", (ply:GetNWInt("chest_keys") or 0))
  144. timer.Simple(12, function()
  145. prize.Func(ply)
  146. end)
  147. end
  148.  
  149. net.Start("chest_prize")
  150. net.WriteBool(valid)
  151. net.WriteString(prize.Name)
  152. net.Send(ply)
  153. end)
  154.  
  155. hook.Add("PlayerInitialSpawn", "ChestLoad", function(ply)
  156. ply:SetNWInt("chest_keys", tonumber(ply:GetPData("chest_keys") or 0) or 0)
  157. end)
  158. end
  159.  
  160. if SERVER then return end
  161.  
  162. /*--------------------------
  163. Materials
  164. ----------------------------*/
  165.  
  166. local mats = {
  167. ["$2500"] = Material("materials/chests/2500.png"),
  168. ["$5000"] = Material("materials/chests/5000.png"),
  169. ["$10000"] = Material("materials/chests/10000.png"),
  170. ["$25000"] = Material("materials/chests/25000.png"),
  171. ["3 klucze"] = Material("materials/chests/keys.png"),
  172. ["But"] = Material("materials/chests/shoe.png"),
  173. ["SuperVIP"] = Material("materials/chests/svip.png"),
  174. ["Hat's hook"] = Material("materials/chests/hook.png"),
  175. ["2x money"] = Material("materials/chests/2x.png")
  176. }
  177.  
  178. local mainMat = Material("materials/chests/main.png")
  179.  
  180. /*--------------------------
  181. Box drawing
  182. ----------------------------*/
  183.  
  184. local function DrawBox(x, y, w, h, n, prize, typ)
  185. draw.RoundedBox(0, x+2, y+2, w-4, h-4, Color(120,120,120))
  186. draw.RoundedBox(0, x+3, y+3, w-6, h-6, Color(60,60,60))
  187.  
  188. draw.SimpleText(typ, "Trebuchet18", x+w/2, y+h/2,prize and Color(0,255,0) or Color(255,0,0), 1, 1)
  189.  
  190. if mats[typ] then
  191. surface.SetMaterial(mats[typ])
  192. surface.SetDrawColor(255,255,255)
  193. surface.DrawTexturedRect(x+3, y+3, w-6, h-6)
  194. end
  195. end
  196.  
  197. /*--------------------------
  198. GUI
  199. ----------------------------*/
  200.  
  201. surface.CreateFont("chest_keys", {
  202. font = "Roboto",
  203. size = 70,
  204. weight = 100,
  205. blursize = 0,
  206. scanlines = 0,
  207. antialias = true,
  208. })
  209.  
  210. if IsValid(CHM) then
  211. CHM:Remove()
  212. end
  213.  
  214. local function OpenMenu()
  215. if IsValid(CHM) then
  216. CHM:Remove()
  217. end
  218.  
  219. CHM = vgui.Create("DFrame")
  220. local main = CHM
  221. main:SetSize(1024, 1024)
  222. main:Center()
  223. main:MakePopup()
  224. main:SetTitle("")
  225. main:ShowCloseButton(false)
  226. function main:Paint(w, h)
  227. surface.SetDrawColor(255,255,255)
  228. surface.SetMaterial(mainMat)
  229. surface.DrawTexturedRect(0, 0, w, h)
  230. end
  231.  
  232. local exit = main:Add("DButton")
  233. exit:SetPos(882,168)
  234. exit:SetSize(34,34)
  235. exit:SetText("")
  236. function exit:Paint() end
  237. function exit:DoClick()
  238. CHM:Remove()
  239. end
  240.  
  241. local code = main:Add("DTextEntry")
  242. code:SetPos(536,412)
  243. code:SetSize(215,54)
  244. code:SetFont("DermaLarge")
  245.  
  246. local codeBtn = main:Add("DButton")
  247. codeBtn:SetPos(536+215,412)
  248. codeBtn:SetSize(156,54)
  249. codeBtn:SetText("")
  250. function codeBtn:Paint(w, h)
  251. draw.RoundedBox(0, 0, 0, w, h, self:IsHovered() and Color(255,255,255,20) or (self:IsDown() and Color(0,0,0,255) or Color(0,0,0,0)))
  252. end
  253. function codeBtn:DoClick()
  254. net.Start("chest_buykey")
  255. net.WriteString(code:GetValue())
  256. net.SendToServer()
  257. end
  258.  
  259. local keys = main:Add("DLabel")
  260. keys:SetFont("chest_keys")
  261. keys:SetColor(Color(255,255,255))
  262. keys:SetPos(810,255)
  263. keys:SetSize(300,200)
  264. keys:SetContentAlignment(4)
  265. function keys:Think()
  266. keys:SetText("x" .. (LocalPlayer():GetNWInt("chest_keys") or 0))
  267. end
  268.  
  269. local prizePnl = main:Add("DPanel")
  270. prizePnl:SetPos(183,673+24)
  271. prizePnl:SetSize(660,128)
  272. prizePnl.visible = false
  273.  
  274. local pos = 0
  275. local npos = -128*200
  276.  
  277. local off = math.random(-54, 54)
  278.  
  279. local endTime = CurTime()+8
  280. startTime = CurTime()
  281.  
  282. local active = false
  283.  
  284. local prizes = { }
  285.  
  286. function prizePnl:Paint(w, h)
  287. if !self.visible then
  288. draw.RoundedBox(0, 0, 0, w, h, Color(50,50,50))
  289. return
  290. end
  291.  
  292. local diff = !active and 5 or math.min(-(endTime-CurTime()), 0)
  293.  
  294. draw.RoundedBox(0, 0, 0, w, h, Color(0,0,0))
  295.  
  296. pos = -(diff^2)*100-128*20-64-w/2+off
  297.  
  298. //pos = pos + FrameTime() * vel
  299. //vel = math.max(vel - FrameTime()*200, 0)
  300.  
  301. if pos > npos then
  302. surface.PlaySound("buttons/lightswitch2.wav")
  303. npos = pos + h
  304. end
  305.  
  306. for i = 0, 65 do
  307. DrawBox(i*h-(pos)%(h*60), 0, h, h, i, i==39, prizes[i] or "")
  308. end
  309.  
  310. draw.RoundedBox(0, w/2, 0, 1, h, Color(255,210,110))
  311. end
  312.  
  313. local run = main:Add("DButton")
  314. run:SetPos(183,643)
  315. run:SetSize(660,55)
  316. run:SetText("")
  317. run.active = true
  318. function run:DoClick()
  319. if !self.active then return end
  320. self.active = false
  321. net.Start("chest_start")
  322. net.SendToServer()
  323. end
  324. function run:Paint(w, h)
  325. draw.RoundedBox(0, 0, 0, w, h, (self:IsHovered() && self.active) and Color(255,255,255,20) or (self.active and Color(0,0,0,0) or Color(0,0,0,230)))
  326. end
  327.  
  328. local function CheckKeys()
  329. local keys = LocalPlayer():GetNWInt("chest_keys") or 0
  330.  
  331. if keys > 0 then
  332. run.active = true
  333. else
  334. run.active = false
  335. end
  336. end
  337.  
  338. CheckKeys()
  339.  
  340. net.Receive("chest_prize", function()
  341. local valid = net.ReadBool()
  342. local prize = net.ReadString()
  343.  
  344. if IsValid(CHM) && !valid then
  345. run.active = true
  346. end
  347.  
  348. if IsValid(CHM) && valid then
  349. surface.PlaySound("chest/pirate.wav")
  350. run.active = false
  351. timer.Simple(4, function()
  352. if IsValid(CHM) then
  353. prizePnl.visible = true
  354. for i = 1, 65 do
  355. prizes[i] = GetPrize().Name
  356. end
  357. prizes[39] = prize
  358. active = true
  359. pos = 0
  360. npos = -128*200
  361. off = math.random(-54, 54)
  362. endTime = CurTime()+8
  363. timer.Simple(8, function()
  364. if !IsValid(CHM) then return end
  365. timer.Simple(2, function()
  366. if !IsValid(CHM) then return end
  367. prizePnl.visible = false
  368. CheckKeys()
  369. end)
  370. end)
  371. end
  372. end)
  373. end
  374. end)
  375.  
  376. net.Receive("chest_buykey", function()
  377. local valid = net.ReadBool()
  378.  
  379. if IsValid(CHM)then
  380. if valid then
  381. surface.PlaySound("buttons/button9.wav")
  382. run.active = true
  383. else
  384. surface.PlaySound("buttons/button10.wav")
  385. end
  386. code:SetValue("")
  387. end
  388. end)
  389. end
  390.  
  391. net.Receive("chest_open", function()
  392. OpenMenu()
  393. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement