-- ShopScript
-- Purpose: Controls Shop UI Mechanics
-- Created by: Lugical (3/8/20)
local repStorage = game:GetService("ReplicatedStorage")
local transition = require(repStorage["UI_MODULE"])
local shopOpened = false
local allowChanges = true
local itemsAndPrices = {
["Pistol"] = {1, 0, 0, "Pistol", "Your starting pistol. Gets the job done, at least.", 4}, --position, price, DPM
["Long Barrel Shotgun"] = {2, "1,500", 0, "Long Barrel", "With this, you get to shove zombies full of lead!"},
["Uzi"] = {3, "2,800", 0, "Uzi", "Small and efficient, it's great for taking out zombies!"},
["M-16 Assault"] = {4, "6,000", 0, "M-16", "M-16? Watch them shiver at such a sight!"},
["M249"] = {5, "10,000", 0, "M249", "The weapon with legs. Don't mess with it!", 6},
["Dragonov"] = {6, "15,300", 0, "Dragonov", "Shoot the zombies out from far out! They'll never see it!"},
["Pasg"] = {7, "21,400", 0, "Pasg", "With a single shot, they're going to cower for their...existence."},
["MP-18"] = {8, "30,800", 0, "MP-18", "A blast from the past with this one! Show 'em what you got!"},
["MP8"] = {9, "41,600", 0, "MP8", "Ah, the MP8. It'll do you good. It'll do the zombies some bad.", 7},
["Tavor21"] = {10, "54,000", 0, "Tavor21", "Tavor21s. The 21s are for how many zombies it'll make run, I think."},
["RPD"] = {11, "95,000", 0, "RPD", "With only 3 letters, scare away the hoardes of monsters!"},
["MSR"] = {12, "126,000", 0, "MSR", "It's big, and its sight alone will cause any zombie to see it to scream!"},
["AA-12 Shotgun"] = {13, "175,000", 0, "AA-12", "The AA-12 is quite a mighty shotgun, perfect for your defense needs!"},
["PPSH-41"] = {14, "190,000", 0, "PPSH-41", "With this one, you're sure to clear out the hordes in style!"},
["G36"] = {15, "220,000", 0, "G36", "The G36 is one of those that are feared by all! Use this, and command to victory!"},
["RM-277"] = {16, "265,000", 0, "RM-277", "A sight of this, and the city might as well be all good to go!"},
["RPG"] = {17, "396,000", 0, "RPG", "It's green end will make all the zombies beg...beg to not use it, of course.", 10},
["GAU-17 Minigun"] = {18, "525,000", 0, "GAU-17", "Everytime you shoot with this, a zombie cowers for their existence."},
}
local priceItems = {
["PISTOL"] = 0, --position, price, DPM
["LONG BARREL SHOTGUN"] = 1500,
["UZI"] = 2800,
["M-16 ASSAULT"] = 6000,
["M249"] = 10000,
["DRAGONOV"] = 15300,
["PASG"] = 21400,
["MP-18"] = 30800,
["MP8"] = 41600,
["TAVOR21"] = 54000,
["RPD"] = 95000,
["MSR"] = 126000,
["AA-12 SHOTGUN"] = 175000,
["PPSH-41"] = 190000,
["G36"] = 220000,
["RM-277"] = 265000,
["RPG"] = 396000,
["GAU-17 MINIGUN"] = 525000,
}
local itemNames = {
["PISTOL"] = "Pistol", --position, price, DPM
["LONG BARREL SHOTGUN"] = "Long Barrel Shotgun",
["UZI"] = "Uzi",
["M-16 ASSAULT"] = "M-16 Assault",
["M249"] = "M249",
["DRAGONOV"] = "Dragonov",
["PASG"] = "Pasg",
["MP-18"] = "MP-18",
["MP8"] = "MP8",
["TAVOR21"] = "Tavor21",
["RPD"] = "RPD",
["MSR"] = "MSR",
["AA-12 SHOTGUN"] = "AA-12 Shotgun",
["PPSH-41"] = "PPSH-41",
["G36"] = "G36",
["RM-277"] = "RM-277",
["RPG"] = "RPG",
["GAU-17 MINIGUN"] = "GAU-17 Minigun",
}
local positionsForAmounts = {
UDim2.new(0.945, 0,0.04, 0),
UDim2.new(0.925, 0,0.04, 0),
UDim2.new(0.915, 0,0.04, 0),
UDim2.new(0.9, 0,0.04, 0),
UDim2.new(0.88, 0,0.04, 0),
UDim2.new(0.87, 0,0.04, 0),
UDim2.new(0.85, 0,0.04, 0),
}
local inventoryItems = {}
local primaryWeapon
local function updatePos()
local x = tonumber(script.Parent.Frame.Frame.AmountFrame.TextLabelCash.Text)
local y = tonumber(script.Parent.Frame.Frame.AmountFrame.TextLabelCredits.Text)
local dominant
if x> y then
dominant = x
else
dominant = y
end
script.Parent.Frame.Frame.AmountFrame.Position = positionsForAmounts[string.len(tostring(dominant))]
end
--spawn(function()
-- while wait(.5) do
-- updatePos()
-- end
--end)
repStorage.UpdateDataValue.OnClientEvent:Connect(function(newValue, dataSubject, plr)
if dataSubject == "Inventory" then
inventoryItems = newValue
for _, v in pairs(inventoryItems) do -- 87, 177, 104
local renderSpace = script.Parent.Frame.PartyFrame.WeaponFrame.Frame.ScrollingFrame:WaitForChild(v, .25)
if renderSpace then
renderSpace.BuyFrame.ImageColor3 = Color3.fromRGB(87, 177, 104)
end
end
elseif dataSubject == "PrimaryWeapon" then
primaryWeapon = newValue
elseif dataSubject == "ZCash" then
script.Parent.Frame.Frame.AmountFrame.TextLabelCash.Text = tostring(newValue)
elseif dataSubject == "ZCredits" then
script.Parent.Frame.Frame.AmountFrame.TextLabelCredits.Text = tostring(newValue)
end
end)
for weaponName, information in pairs(itemsAndPrices) do
local renderSpace = script.Parent.Frame.PartyFrame.WeaponFrame.Frame.ScrollingFrame:WaitForChild(weaponName)
renderSpace.BuyFrame.TextButton.Text = information[2]
local newFrame = Instance.new("Frame")
newFrame.Parent = renderSpace
newFrame.Size = UDim2.new(1,0,1,0)
newFrame.BackgroundTransparency = 1
newFrame.ZIndex = 6
newFrame.ClipsDescendants = true
local newView = Instance.new("ViewportFrame")
newView.Parent = newFrame
newView.Size = UDim2.new(.375,0,1,0)
newView.BackgroundColor3 = Color3.fromRGB(91,91,91)
newView.BackgroundTransparency = 1
newView.ZIndex = 6
local newWeapon = repStorage.ViewportWeapons:FindFirstChild(weaponName):Clone()
newWeapon.Parent = workspace.CurrentCamera
newWeapon:SetPrimaryPartCFrame(workspace.CameraPartRender.CFrame)
local newCamera = Instance.new("Camera")
newCamera.FieldOfView = 10.5
if information[6] ~= nil then
newCamera.FieldOfView = information[6]
end
newCamera.Parent = newView
newWeapon.Parent = newView
newView.CurrentCamera = newCamera
local newButton = Instance.new("ImageButton", renderSpace)
newButton.BackgroundTransparency = 1
newButton.ImageTransparency = 1
newButton.Size = UDim2.new(1,0,1,0)
newButton.ZIndex = 10
newButton.Name = weaponName
newButton.Parent = renderSpace
spawn(function()
newButton.MouseButton1Click:Connect(function()
game.SoundService.ButtonPressSound:Play()
local isInventory = false
local isPrimary = false
if renderSpace.BackgroundColor3 == Color3.fromRGB(91, 91, 91) then
allowChanges = true
renderSpace.BackgroundColor3 = Color3.fromRGB(49, 49, 49)
if renderSpace.BuyFrame.ImageColor3 ~= Color3.fromRGB(87, 177, 104) then
renderSpace.BuyFrame.ImageColor3 = Color3.fromRGB(47,47,47)
end
local newFrame = script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame
newFrame.TextL.Text = "SELECT ONE"
newFrame.TextLabelDMP.Text = ""
newFrame.TextLabel.Text = ""
for _, v in pairs(newFrame.PreviewFrame:GetChildren()) do
v:Destroy()
end
else
for i, v in pairs(script.Parent.Frame.PartyFrame.WeaponFrame.Frame.ScrollingFrame:GetChildren()) do
v.BackgroundColor3 = Color3.fromRGB(91,91,91)
if v.BuyFrame.ImageColor3 ~= Color3.fromRGB(87, 177, 104) then
v.BuyFrame.ImageColor3 = Color3.fromRGB(47,47,47)
end
end
allowChanges = false
renderSpace.BackgroundColor3 = Color3.fromRGB(91,91,91)
if renderSpace.BuyFrame.ImageColor3 ~= Color3.fromRGB(87, 177, 104) then
renderSpace.BuyFrame.ImageColor3 = Color3.fromRGB(65,65,65)
end
local newFrame = script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame
newFrame.TextL.Text = string.upper(newButton.Name)
local viewportPreview = newView:Clone()
viewportPreview.Size = UDim2.new(1,0,.95,0)
for _, v in pairs(newFrame.PreviewFrame:GetChildren()) do
v:Destroy()
end
newFrame.BuyFrame.Icon.Visible = false
viewportPreview.Parent = newFrame.PreviewFrame
newFrame.TextLabelDMP.Text = "DPM: "..string.match(string.gsub(script.Parent.Frame.PartyFrame.WeaponFrame.Frame.ScrollingFrame:WaitForChild(weaponName).TextDMP.Text, ",", ""), "%d+")
newFrame.TextLabel.Text = information[5]
for _,v in pairs(inventoryItems) do
if v == weaponName then
isInventory = true
end
end
if primaryWeapon == weaponName then
isPrimary = true
end
newFrame.BuyFrame.Icon.Visible = false
if isPrimary then
newFrame.BuyFrame.TextButton.Text = "Unequip"
elseif isInventory then
newFrame.BuyFrame.TextButton.Text = "Equip"
else
newFrame.BuyFrame.Icon.Visible = true
newFrame.BuyFrame.TextButton.Text = tostring(information[2])
end
end
end)
end)
end
script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame.BuyFrame.TextButton.MouseButton1Click:Connect(function()
game.SoundService.ButtonPressSound:Play()
if script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame.BuyFrame.Icon.Visible == true then
local added = repStorage.PurchaseInformation:InvokeServer("INVENTORY_PURCHASE", (priceItems[script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame.TitleFrame.TextL.Text]), itemNames[script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame.TitleFrame.TextL.Text])
if added then
game.SoundService.ButtonPressSound:Stop()
game.SoundService.PurchaseSound:Play()
script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame.BuyFrame.TextButton.Text = "Equip"
script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame.BuyFrame.Icon.Visible = false
else
game.SoundService.ButtonPressSound:Stop()
game.SoundService.ErrorSound:Play()
script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame.BuyFrame:TweenPosition(UDim2.new(.53,0,.911,0), "Out", "Linear", .05, true)
wait(.05)
script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame.BuyFrame:TweenPosition(UDim2.new(.47,0,.911,0), "Out", "Linear", .1, true)
wait(.1)
script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame.BuyFrame:TweenPosition(UDim2.new(.5,0,.911,0), "Out", "Linear", .05, true)
end
elseif script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame.BuyFrame.TextButton.Text == "Equip" then
local added1 = repStorage.PurchaseInformation:InvokeServer("EQUIP", (priceItems[script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame.TextL.Text]), itemNames[script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame.TextL.Text])
if added1 then
primaryWeapon = script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame.TextL.Text
script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame.BuyFrame.TextButton.Text = "Unequip"
wait(.1)
repStorage.EquippingSignal:FireServer(true)
end
elseif script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame.BuyFrame.TextButton.Text == "Unequip" then
if script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame.TextL.Text ~= "Pistol" then
local added2 = repStorage.PurchaseInformation:InvokeServer("UNEQUIP", (priceItems[script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame.TextL.Text]), itemNames[script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame.TextL.Text])
if added2 then
primaryWeapon = "Pistol"
script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame.BuyFrame.TextButton.Text = "Equip"
wait(.1)
repStorage.EquippingSignal:FireServer(true)
end
end
end
end)
local currentColors = {Color3.fromRGB(62, 190, 87), Color3.fromRGB(32, 102, 44)} --shadow, regular
local otherColors = {Color3.fromRGB(35, 35, 35), Color3.fromRGB(56,56,56)} --shadow, regular
local function changeFrames(object)
game.SoundService.ButtonPressSound:Play()
for _, v in pairs(script.Parent.Frame.Frame:GetChildren()) do
if v:IsA("ImageLabel") and v.Name ~= "AmountFrame" then
if v.Name ~= tostring(object) then
v.ImageColor3 = otherColors[1]
v.Frame.ImageColor3 = otherColors[2]
v.Frame.Position = UDim2.new(0,0,-.1,0)
else
v.ImageColor3 = currentColors[2]
v.Frame.ImageColor3 = currentColors[1]
v.Frame.Position = UDim2.new(0,0,0,0)
end
end
end
local differenceX = .5 - object.Position.X.Scale
local differenceY = .5 - object.Position.Y.Scale
local timeS = .75
if differenceX > 1.05 or differenceX < -1.05 then
timeS = 1
end
for _, v in pairs(script.Parent.Frame.PartyFrame:GetChildren()) do
v:TweenPosition(v.Position + UDim2.new(differenceX, 0, differenceY, 0), "Out", "Quint", timeS, true)
end
end
script.Parent.Frame.Changed:Connect(function()
if script.Parent.Frame.Position == UDim2.new(1,0,0,0) then
local newFrame = script.Parent.Frame.PartyFrame.WeaponFrame.PreviewFrame
newFrame.TextL.Text = "SELECT ONE"
newFrame.TextLabelDMP.Text = ""
newFrame.TextLabel.Text = ""
for _, v in pairs(newFrame.PreviewFrame:GetChildren()) do
v:Destroy()
end
-- changeFrames(script.Parent.Frame.PartyFrame.MoneyFrame)
end
end)
changeFrames(script.Parent.Frame.PartyFrame:WaitForChild("WeaponFrame"))
script.Parent.Frame.Frame.MoneyFrame.Frame.TextButton.MouseButton1Click:Connect(function() changeFrames(script.Parent.Frame.PartyFrame:WaitForChild("MoneyFrame")) end)
script.Parent.Frame.Frame.SkinFrame.Frame.TextButton.MouseButton1Click:Connect(function() changeFrames(script.Parent.Frame.PartyFrame:WaitForChild("SkinFrame")) end)
script.Parent.Frame.Frame.WeaponFrame.Frame.TextButton.MouseButton1Click:Connect(function() changeFrames(script.Parent.Frame.PartyFrame:WaitForChild("WeaponFrame")) end)
script.Parent.Frame.Frame.PerkFrame.Frame.TextButton.MouseButton1Click:Connect(function() changeFrames(script.Parent.Frame.PartyFrame:WaitForChild("PerkFrame")) end)
1 Like