1x_Gacha

Bounty System | Server | Explained

Sep 11th, 2020 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.28 KB | None | 0 0
  1. local DataStore2 = require(game.ServerScriptService:WaitForChild('DataStore2')) -- Require DataStore2 Module, a Wrapper for DataStore.
  2.  
  3. local function checkAssets(plr) -- Check if Player Owns Asset.
  4.     local Asset_Id = 000000000 -- The Asset Id
  5.     local markerplaceservice = game:GetService('MarketplaceService') -- MarketPlaceService
  6.     local ownsasset = markerplaceservice.PlayerOwnsAsset -- Parameter Shortcut
  7.    
  8.     local success, playerownsasset = pcall(ownsasset, markerplaceservice, plr, Asset_Id) -- PCall
  9.  
  10.     if playerownsasset then -- If returned True then
  11.         print('Player Owns Asset.')
  12.         return true -- Return True
  13.        
  14.        
  15.     else -- Otherwise Return False
  16.         warn('Player does not own Asset.') -- Warn Player Does NOT Have Asset
  17.     end
  18. end
  19.  
  20. -- // [[
  21.  
  22. local rs = game:GetService('ReplicatedStorage') -- Replicated Storage.
  23. local remotefolder = rs:FindFirstChild('Remotes') -- Remote Folder
  24.  
  25. local bountytrigger = remotefolder:FindFirstChild('Bounty') -- RemoteEvent
  26. local claimbounty = remotefolder:FindFirstChild('Claim') -- RemoteEvent
  27. local toll = remotefolder:FindFirstChild('PayToll') -- RemoteEvent
  28. local eventtrigger = remotefolder:FindFirstChild('EventTrigger') -- RemoteEvent
  29. local teleporttrigger = remotefolder:FindFirstChild('TeleportTrigger') -- RemoteEvent
  30. local blackmarkettrigger = remotefolder:FindFirstChild('BlackMarket') -- RemoteEvent
  31.  
  32. local eventModule = require(rs.Resources.Events) -- Require Module, Events,
  33.  
  34. local function sendbountyinfo(plr, target, val) -- Send Bounty Info( Creating a new Bounty. )
  35.     local coinstore = DataStore2('ZetaCredit', plr) -- Player Currency
  36.     if game.Players:FindFirstChild(target)then -- If the Players Target is in Game then...
  37.         local player = game.Players:FindFirstChild(target) -- The Targets Player Instance.
  38.         local bountystore = DataStore2('ZetaBounty', player) -- Target Players bounty amount.
  39.         if val <= coinstore:Get()then -- If the Player can afford the Bounty requested then...
  40.             coinstore:Increment(-val) -- Deduct amount from Player
  41.             bountystore:Increment(val) -- Add Target Bounty.
  42.         end
  43.     end
  44. end
  45.  
  46. local function claimTac(plr, event, target) -- Bounty System, Claim Bounty.
  47.     if event == 'INFO' then -- Check Event Required
  48.         print('SERVER CHECK')
  49.        
  50.     claimbounty:FireClient(plr, checkAssets(plr)) -- If the Player owns Gamepass, return true. Otherwise, false.
  51.    
  52.     elseif event == 'CLAIM' then -- If the Event is to Claim a Bounty then...
  53.          if game.Players:FindFirstChild(target) then -- If the Target is in Game...
  54.             local claimTarget = game.Players:FindFirstChild(target) -- The Target
  55.             local claim = game.Players:FindFirstChild(plr.Name) -- The Player who is trying to claim the bounty.
  56.            
  57.             local charTarget = game.Workspace:FindFirstChild(claimTarget.Name) - The Targets Character.
  58.            
  59.             local bountystore = DataStore2('ZetaBounty', claimTarget) -- Bounty Data
  60.             local coinstore = DataStore2('ZetaCredit', claim) -- Players Currency
  61.             local bountycollectstore = DataStore2('ZetaBountyClaim', claim) -- Bounty Data ( # of Bounties Completed)
  62.             local bountyaccumulated = DataStore2('ZetaBountyAccumulate', claim)  Bounty Data ( Career amount earned )
  63.            
  64.             coinstore:Increment(bountystore:Get()) -- Gives Player the Amount states.
  65.             bountyaccumulated:Increment(bountystore:Get()) -- Update Data
  66.             bountystore:Increment(-bountystore:Get()) -- Update Data
  67.             bountycollectstore:Increment(1) -- Update Data
  68.             claimTarget:LoadCharacter() -- Respawn player with Bounty.
  69.            
  70.         end
  71.     end
  72. end
  73.  
  74. local function PayToll(plr, city) -- Not Part of Bounty System.
  75.     local player = game.Players:FindFirstChild(plr.Name) -- Find Player
  76.     local coinstore = DataStore2('ZetaCredit', player) -- Get DataStore2 Data.
  77.     coinstore:Increment(-10) -- Pay the Required Toll.
  78.     player.PlayerGui.TeleportGui.Enabled = true -- Enable Gui
  79.     teleporttrigger:FireClient(plr, city) -- Fire the Client to Work out the Guis appearance.
  80. end
  81.  
  82. local function EventCheck(plr, FORM, EventId) -- Not part of Bounty System, Check if they are in the Event.
  83.    
  84.         local m = eventModule.Events -- Fetch the Events from Module.
  85.         local InEvent = plr.Bools.InEvent -- BoolValue in Player Stats, to tell if they are in an event.
  86.         local Completed = plr.Bools.IsComplete -- BoolValue in PLayer Stats, to tell if they are finished.
  87.        
  88.     if game.Players:FindFirstChild(plr.Name)then -- If the Player is in Game.
  89.         if FORM == 'CHECK' then -- Check the Players current Status in the Event
  90.             local folder = plr:FindFirstChild(m[EventId]['NAME']) -- Find the Players Event.
  91.             local count = folder:FindFirstChild(m[EventId]['GOAL']) -- Check the Amount of work done.
  92.             local goal = folder:FindFirstChild('Goal') -- Check the Goal.
  93.            
  94.             local coinstore = DataStore2('ZetaCredit', plr) -- DataStore2 Data.
  95.            
  96.             if count.Value >= goal.Value then -- If the amount of work done is Greater than or equal to the goal then...
  97.                 print('CHECK TRUE')
  98.                 Completed.Value = true -- Completed = True
  99.                 folder:Destroy() -- Destroy the Folder
  100.                 InEvent.Value = false -- InEvent False
  101.                 coinstore:Increment(m[EventId]['PAY']) -- Pay the Player the amount listed.
  102.             else -- Otherwise
  103.                 print('CHECK FALSE')
  104.                 Completed.Value = false -- Completed is False.
  105.             end
  106.         end
  107.        
  108.         if FORM == 'REGISTER'then -- Register a Player for an event.
  109.             eventtrigger:FireClient(plr, EventId) -- Fire the Client to create the Event.
  110.             print('CHECK')
  111.             InEvent.Value = true -- InEvent = true
  112.             Completed.Value = false -- Completed = False
  113.             local folder = Instance.new('Folder', plr) -- Create a Folder
  114.             folder.Name = m[EventId]['NAME'] -- Name the Folder the Event Name.
  115.             local count = Instance.new('IntValue', folder) -- Create an IntValue
  116.             count.Name  = m[EventId]['GOAL'] -- Set the InValue Name to the Item they need. Parented under the Folder
  117.             count.Value = 0 -- Obviously set it to Zero...
  118.             local goal = Instance.new('IntValue', folder) -- New  IntValue, which is for the Required amount, under Folder.
  119.             goal.Name = 'Goal'
  120.             goal.Value = m[EventId]['AMOUNT'] -- The Required Amount.
  121.         end
  122.     end
  123. end
  124.  
  125. local function teleport(plr, destination) -- Not part of Bounty System, Teleports Player
  126.     local player = game.Players:FindFirstChild(plr.Name) -- Finds the Player
  127.     local char = player.Character -- Player Character
  128.     local locations = game.Workspace:FindFirstChild('EventLocations'):FindFirstChild('Teleport') -- Fetch Teleport Locations
  129.     if locations:FindFirstChild(destination)then -- Find their Destinations.
  130.         char.Torso.CFrame = locations[destination].CFrame -- Teleport Via CFrame.
  131.     end
  132.     wait(3)
  133.     player.PlayerGui.TeleportGui.Enabled = false -- Turn Off Gui
  134. end
  135.  
  136. local function blackmarket(plr, call, item) -- Not part of Bounty System.
  137.     local player = game.Players:FindFirstChild(plr.Name)
  138.     local char = player.Character -- Player Character
  139.     local location = game.Workspace:FindFirstChild('BlackmarketFolder'):WaitForChild('Center') -- Check if player is nearby.
  140.     if call == 'OPEN' then -- Open Gui
  141.         if (location.Position - char.Torso.Position).magnitude < 100 then -- If they are within 100 studs.
  142.             player.PlayerGui.Blackmarket.Enabled  = true
  143.         end
  144.     end
  145.    
  146.     if call == 'EXIT' then -- Close Gui
  147.         player.PlayerGui.Blackmarket.Enabled = false
  148.     end
  149.    
  150.     if call == 'PURCHASE' then -- Purchase Item
  151.         local m = require(rs.Resources.Blackmarket) -- Require a Module, which contains the Items Data.
  152.         local coinstore = DataStore2('ZetaCredit', player) -- DataStore2 Data.
  153.         if coinstore:Get() >= m.Items[item]['price'] then -- If they have enough to purchase the Item.
  154.             coinstore:Increment(m.Items[item]['deduct']) -- Deduct amount.
  155.             local tool = game:GetService('ServerStorage'):FindFirstChild(item):Clone() -- Find the Tool they purchased.
  156.             tool.Parent = plr.Backpack -- Give them the Tool.
  157.         end
  158.     end
  159. end
  160.  
  161.  
  162. -- Remote Events
  163.  
  164. bountytrigger.OnServerEvent:Connect(sendbountyinfo) -- Sends Bounty Information to Create new Bounty.
  165. claimbounty.OnServerEvent:Connect(claimTac) -- Sends Request to Claim Bounty.
  166. toll.OnServerEvent:Connect(PayToll) -- Not part of Bounty System, but a Toll system.
  167. eventtrigger.OnServerEvent:Connect(EventCheck) -- Triggers Event, not part of Bounty System
  168. teleporttrigger.OnServerEvent:Connect(teleport) -- Teleports Player, not part of Bounty System.
  169. blackmarkettrigger.OnServerEvent:Connect(blackmarket) -- Blackmarket, not part of Bounty System.
Advertisement
Add Comment
Please, Sign In to add comment