Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*-----------------------------------------------------------
- Chests
- Dedicated solution for Rage-gaming.pl
- This product cannot be redistributed.
- Copyright © 2015 Szymon (Szymekk) Jankowski
- All Rights Reserved
- Steam: https://steamcommunity.com/id/szymski
- -------------------------------------------------------------*/
- if SERVER then
- AddCSLuaFile()
- resource.AddFile("sound/chest/pirate.wav")
- resource.AddFile("materials/chests/2500.png")
- resource.AddFile("materials/chests/5000.png")
- resource.AddFile("materials/chests/10000.png")
- resource.AddFile("materials/chests/25000.png")
- resource.AddFile("materials/chests/keys.png")
- resource.AddFile("materials/chests/shoe.png")
- resource.AddFile("materials/chests/svip.png")
- resource.AddFile("materials/chests/2x.png")
- resource.AddFile("materials/chests/hook.png")
- resource.AddFile("materials/chests/main.png")
- resource.AddFile("materials/models/custom/chest.vmt")
- resource.AddFile("models/custom/chest.mdl")
- hook.Add("InitPostEntity", "ChestSpawn", function()
- timer.Simple(10, function()
- local ent = ents.Create("chest")
- ent:SetPos(Vector(-1423, 3301, -724.3))
- ent:SetAngles(Angle(0,90,0))
- ent:Spawn()
- ent:SetMoveType(MOVETYPE_NONE)
- end)
- end)
- end
- /*--------------------------
- Prizes
- ----------------------------*/
- local function GetPrize()
- local prize = { }
- local rand = math.random(0,100)
- if rand < 1 then
- prize.Name = "3 klucze"
- prize.Func = function(ply)
- ply:SetNWInt("chest_keys", (ply:GetNWInt("chest_keys") or 0) + 3)
- ply:SetPData("chest_keys", (ply:GetNWInt("chest_keys") or 0))
- end
- elseif rand < 3 then
- prize.Name = "SuperVIP"
- prize.Func = function(ply)
- ulx.tempadduser(Entity(0), ply, "svip", 43200, "user")
- end
- elseif rand < 5 then
- prize.Name = "2x money"
- prize.Func = function(ply)
- ply:addMoney(ply:getDarkRPVar("money"))
- end
- elseif rand < 10 then
- prize.Name = "$25000"
- prize.Func = function(ply)
- ply:addMoney(25000)
- end
- /*elseif rand < 15 then
- prize.Name = "20 bouncy balls"
- prize.Func = function(ply)
- timer.Create("chest_balls", 0.15, 30, function()
- local ent = ents.Create("sent_ball")
- ent:SetPos(ply:GetPos()+Vector(math.sin(RealTime()*5)*100,math.cos(RealTime()*5)*100,100))
- ent:SetBallSize(math.random( 16, 48 ))
- ent:Spawn()
- ent:Activate()
- end)
- end*/
- elseif rand < 20 then
- prize.Name = "Hat's hook"
- prize.Func = function(ply)
- ply:Give("realistic_hook")
- end
- elseif rand < 30 then
- prize.Name = "$10000"
- prize.Func = function(ply)
- ply:addMoney(10000)
- end
- elseif rand < 45 then
- prize.Name = "$5000"
- prize.Func = function(ply)
- ply:addMoney(5000)
- end
- else
- prize.Name = "$2500"
- prize.Func = function(ply)
- ply:addMoney(2500)
- end
- end
- return prize
- end
- concommand.Add("chest_allkeys", function()
- for k, v in pairs(player.GetAll()) do print(v:Name().." - "..(v:GetNWInt("chest_keys") or 0)) end
- end)
- if SERVER then
- util.AddNetworkString("chest_start")
- util.AddNetworkString("chest_prize")
- util.AddNetworkString("chest_buykey")
- util.AddNetworkString("chest_keyend")
- net.Receive("chest_buykey", function(len, ply)
- local code = net.ReadString()
- http.Fetch("http://rage-gaming.pl/chest/check.php?check="..code, function(body)
- local valid = body == "1"
- if valid then
- ply:SetNWInt("chest_keys", (ply:GetNWInt("chest_keys") or 0) + 2)
- ply:SetPData("chest_keys", (ply:GetNWInt("chest_keys") or 0))
- end
- net.Start("chest_buykey")
- net.WriteBool(valid)
- net.Send(ply)
- end, function() end)
- end)
- net.Receive("chest_start", function(len, ply)
- local prize = GetPrize()
- local valid = (ply:GetNWInt("chest_keys") or 0) > 0
- if valid then
- ply:SetNWInt("chest_keys", (ply:GetNWInt("chest_keys") or 0) - 1)
- ply:SetPData("chest_keys", (ply:GetNWInt("chest_keys") or 0))
- timer.Simple(12, function()
- prize.Func(ply)
- end)
- end
- net.Start("chest_prize")
- net.WriteBool(valid)
- net.WriteString(prize.Name)
- net.Send(ply)
- end)
- hook.Add("PlayerInitialSpawn", "ChestLoad", function(ply)
- ply:SetNWInt("chest_keys", tonumber(ply:GetPData("chest_keys") or 0) or 0)
- end)
- end
- if SERVER then return end
- /*--------------------------
- Materials
- ----------------------------*/
- local mats = {
- ["$2500"] = Material("materials/chests/2500.png"),
- ["$5000"] = Material("materials/chests/5000.png"),
- ["$10000"] = Material("materials/chests/10000.png"),
- ["$25000"] = Material("materials/chests/25000.png"),
- ["3 klucze"] = Material("materials/chests/keys.png"),
- ["But"] = Material("materials/chests/shoe.png"),
- ["SuperVIP"] = Material("materials/chests/svip.png"),
- ["Hat's hook"] = Material("materials/chests/hook.png"),
- ["2x money"] = Material("materials/chests/2x.png")
- }
- local mainMat = Material("materials/chests/main.png")
- /*--------------------------
- Box drawing
- ----------------------------*/
- local function DrawBox(x, y, w, h, n, prize, typ)
- draw.RoundedBox(0, x+2, y+2, w-4, h-4, Color(120,120,120))
- draw.RoundedBox(0, x+3, y+3, w-6, h-6, Color(60,60,60))
- draw.SimpleText(typ, "Trebuchet18", x+w/2, y+h/2,prize and Color(0,255,0) or Color(255,0,0), 1, 1)
- if mats[typ] then
- surface.SetMaterial(mats[typ])
- surface.SetDrawColor(255,255,255)
- surface.DrawTexturedRect(x+3, y+3, w-6, h-6)
- end
- end
- /*--------------------------
- GUI
- ----------------------------*/
- surface.CreateFont("chest_keys", {
- font = "Roboto",
- size = 70,
- weight = 100,
- blursize = 0,
- scanlines = 0,
- antialias = true,
- })
- if IsValid(CHM) then
- CHM:Remove()
- end
- local function OpenMenu()
- if IsValid(CHM) then
- CHM:Remove()
- end
- CHM = vgui.Create("DFrame")
- local main = CHM
- main:SetSize(1024, 1024)
- main:Center()
- main:MakePopup()
- main:SetTitle("")
- main:ShowCloseButton(false)
- function main:Paint(w, h)
- surface.SetDrawColor(255,255,255)
- surface.SetMaterial(mainMat)
- surface.DrawTexturedRect(0, 0, w, h)
- end
- local exit = main:Add("DButton")
- exit:SetPos(882,168)
- exit:SetSize(34,34)
- exit:SetText("")
- function exit:Paint() end
- function exit:DoClick()
- CHM:Remove()
- end
- local code = main:Add("DTextEntry")
- code:SetPos(536,412)
- code:SetSize(215,54)
- code:SetFont("DermaLarge")
- local codeBtn = main:Add("DButton")
- codeBtn:SetPos(536+215,412)
- codeBtn:SetSize(156,54)
- codeBtn:SetText("")
- function codeBtn:Paint(w, h)
- 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)))
- end
- function codeBtn:DoClick()
- net.Start("chest_buykey")
- net.WriteString(code:GetValue())
- net.SendToServer()
- end
- local keys = main:Add("DLabel")
- keys:SetFont("chest_keys")
- keys:SetColor(Color(255,255,255))
- keys:SetPos(810,255)
- keys:SetSize(300,200)
- keys:SetContentAlignment(4)
- function keys:Think()
- keys:SetText("x" .. (LocalPlayer():GetNWInt("chest_keys") or 0))
- end
- local prizePnl = main:Add("DPanel")
- prizePnl:SetPos(183,673+24)
- prizePnl:SetSize(660,128)
- prizePnl.visible = false
- local pos = 0
- local npos = -128*200
- local off = math.random(-54, 54)
- local endTime = CurTime()+8
- startTime = CurTime()
- local active = false
- local prizes = { }
- function prizePnl:Paint(w, h)
- if !self.visible then
- draw.RoundedBox(0, 0, 0, w, h, Color(50,50,50))
- return
- end
- local diff = !active and 5 or math.min(-(endTime-CurTime()), 0)
- draw.RoundedBox(0, 0, 0, w, h, Color(0,0,0))
- pos = -(diff^2)*100-128*20-64-w/2+off
- //pos = pos + FrameTime() * vel
- //vel = math.max(vel - FrameTime()*200, 0)
- if pos > npos then
- surface.PlaySound("buttons/lightswitch2.wav")
- npos = pos + h
- end
- for i = 0, 65 do
- DrawBox(i*h-(pos)%(h*60), 0, h, h, i, i==39, prizes[i] or "")
- end
- draw.RoundedBox(0, w/2, 0, 1, h, Color(255,210,110))
- end
- local run = main:Add("DButton")
- run:SetPos(183,643)
- run:SetSize(660,55)
- run:SetText("")
- run.active = true
- function run:DoClick()
- if !self.active then return end
- self.active = false
- net.Start("chest_start")
- net.SendToServer()
- end
- function run:Paint(w, h)
- 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)))
- end
- local function CheckKeys()
- local keys = LocalPlayer():GetNWInt("chest_keys") or 0
- if keys > 0 then
- run.active = true
- else
- run.active = false
- end
- end
- CheckKeys()
- net.Receive("chest_prize", function()
- local valid = net.ReadBool()
- local prize = net.ReadString()
- if IsValid(CHM) && !valid then
- run.active = true
- end
- if IsValid(CHM) && valid then
- surface.PlaySound("chest/pirate.wav")
- run.active = false
- timer.Simple(4, function()
- if IsValid(CHM) then
- prizePnl.visible = true
- for i = 1, 65 do
- prizes[i] = GetPrize().Name
- end
- prizes[39] = prize
- active = true
- pos = 0
- npos = -128*200
- off = math.random(-54, 54)
- endTime = CurTime()+8
- timer.Simple(8, function()
- if !IsValid(CHM) then return end
- timer.Simple(2, function()
- if !IsValid(CHM) then return end
- prizePnl.visible = false
- CheckKeys()
- end)
- end)
- end
- end)
- end
- end)
- net.Receive("chest_buykey", function()
- local valid = net.ReadBool()
- if IsValid(CHM)then
- if valid then
- surface.PlaySound("buttons/button9.wav")
- run.active = true
- else
- surface.PlaySound("buttons/button10.wav")
- end
- code:SetValue("")
- end
- end)
- end
- net.Receive("chest_open", function()
- OpenMenu()
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement