Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.40 KB | None | 0 0
  1. %Tkv1yYRhpicRbxVHDZQnaf3y84n0Lv5elv/c7ydDbqHs7AxRkxCo2DrpFW9U5ytbVEMduvh721v3l4wKqDKv25ZdC+YUen9msRFjPwuvgiWRjlsgcT6QO0hD4ar9TY0yhWmyULuL5nQudmfaA3Kr0sBeesM45v8y3+hHMt45B34=%%1018966%print("LinkedLeaderboard script version 5.00 loaded")
  2.  
  3. stands = {}
  4. CTF_mode = false
  5.  
  6.  
  7. function onHumanoidDied(humanoid, player)
  8.     local stats = player:findFirstChild("leaderstats")
  9.     if stats ~= nil then
  10.         local deaths = stats:findFirstChild("Wipeouts")
  11.         deaths.Value = deaths.Value + 1
  12.  
  13.         -- do short dance to try and find the killer
  14.  
  15.         local killer = getKillerOfHumanoidIfStillInGame(humanoid)
  16.  
  17.         handleKillCount(humanoid, player)
  18.     end
  19. end
  20.  
  21. function onPlayerRespawn(property, player)
  22.     -- need to connect to new humanoid
  23.    
  24.     if property == "Character" and player.Character ~= nil then
  25.         local humanoid = player.Character.Humanoid
  26.             local p = player
  27.             local h = humanoid
  28.             humanoid.Died:connect(function() onHumanoidDied(h, p) end )
  29.     end
  30. end
  31.  
  32. function getKillerOfHumanoidIfStillInGame(humanoid)
  33.     -- returns the player object that killed this humanoid
  34.     -- returns nil if the killer is no longer in the game
  35.  
  36.     -- check for kill tag on humanoid - may be more than one - todo: deal with this
  37.     local tag = humanoid:findFirstChild("creator")
  38.  
  39.     -- find player with name on tag
  40.     if tag ~= nil then
  41.        
  42.         local killer = tag.Value
  43.         if killer.Parent ~= nil then -- killer still in game
  44.             return killer
  45.         end
  46.     end
  47.  
  48.     return nil
  49. end
  50.  
  51. function handleKillCount(humanoid, player)
  52.     local killer = getKillerOfHumanoidIfStillInGame(humanoid)
  53.     if killer ~= nil then
  54.         local stats = killer:findFirstChild("leaderstats")
  55.         if stats ~= nil then
  56.             local kills = stats:findFirstChild("KOs")
  57.             if killer ~= player then
  58.                 kills.Value = kills.Value + 1
  59.                 Cash.Value = Cash.Value + 5
  60.             else
  61.                 kills.Value = kills.Value - 1
  62.                
  63.             end
  64.         end
  65.     end
  66. end
  67.  
  68.  
  69. -----------------------------------------------
  70.  
  71.  
  72.  
  73. function findAllFlagStands(root)
  74.     local c = root:children()
  75.     for i=1,#c do
  76.         if (c[i].className == "Model" or c[i].className == "Part") then
  77.             findAllFlagStands(c[i])
  78.         end
  79.         if (c[i].className == "FlagStand") then
  80.             table.insert(stands, c[i])
  81.         end
  82.     end
  83. end
  84.  
  85. function hookUpListeners()
  86.     for i=1,#stands do
  87.         stands[i].FlagCaptured:connect(onCaptureScored)
  88.     end
  89. end
  90.  
  91. function onPlayerEntered(newPlayer)
  92.  
  93.     if CTF_mode == true then
  94.  
  95.         local stats = Instance.new("IntValue")
  96.         stats.Name = "leaderstats"
  97.  
  98.         local captures = Instance.new("IntValue")
  99.         captures.Name = "Captures"
  100.         captures.Value = 0
  101.  
  102.  
  103.         captures.Parent = stats
  104.  
  105.         -- VERY UGLY HACK
  106.         -- Will this leak threads?
  107.         -- Is the problem even what I think it is (player arrived before character)?
  108.         while true do
  109.             if newPlayer.Character ~= nil then break end
  110.             wait(5)
  111.         end
  112.  
  113.         stats.Parent = newPlayer
  114.  
  115.     else
  116.  
  117.         local stats = Instance.new("IntValue")
  118.         stats.Name = "leaderstats"
  119.  
  120.         local kills = Instance.new("IntValue")
  121.         kills.Name = "KOs"
  122.         kills.Value = 0
  123.  
  124.         local deaths = Instance.new("IntValue")
  125.         deaths.Name = "Wipeouts"
  126.         deaths.Value = 0
  127.  
  128.         kills.Parent = stats
  129.         deaths.Parent = stats
  130.  
  131.         -- VERY UGLY HACK
  132.         -- Will this leak threads?
  133.         -- Is the problem even what I think it is (player arrived before character)?
  134.         while true do
  135.             if newPlayer.Character ~= nil then break end
  136.             wait(5)
  137.         end
  138.  
  139.         local humanoid = newPlayer.Character.Humanoid
  140.  
  141.         humanoid.Died:connect(function() onHumanoidDied(humanoid, newPlayer) end )
  142.  
  143.         -- start to listen for new humanoid
  144.         newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )
  145.  
  146.  
  147.         stats.Parent = newPlayer
  148.  
  149.     end
  150.  
  151. end
  152.  
  153.  
  154. function onCaptureScored(player)
  155.  
  156.         local ls = player:findFirstChild("leaderstats")
  157.         if ls == nil then return end
  158.         local caps = ls:findFirstChild("Captures")
  159.         if caps == nil then return end
  160.         caps.Value = caps.Value + 1
  161.  
  162. end
  163.  
  164.  
  165. findAllFlagStands(game.Workspace)
  166. hookUpListeners()
  167. if (#stands > 0) then CTF_mode = true end
  168. game.Players.ChildAdded:connect(onPlayerEntered)
  169.  
  170.  
  171.  
  172.  
  173. --[[Leader Board #2 For Cash
  174. Please note that cash is also in the above script. Why? Because it is to tell that if the KO goes up by 1, cash's value goes up by 5.
  175.  
  176. ]]--
  177.  
  178. print("Cash Leaderboard Loaded")
  179.  
  180.  
  181. function onPlayerEntered(newPlayer)
  182.  
  183.     local cash = Instance.new("IntValue")
  184.     cash.Name = "Cash"
  185.     cash.Value = 0
  186.  
  187.     cash.Parent = leaderstats
  188. end
  189.  
  190.  
  191.  
  192. game.Players.ChildAdded:connect(onPlayerEntered)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement