Advertisement
greatgamer38

Untitled

May 3rd, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. stands = {}
  2. CTF_mode = false
  3.  
  4.  
  5. function onHumanoidDied(humanoid, player)
  6. local stats = player:findFirstChild("leaderstats")
  7. if stats ~= nil then
  8. local deaths = stats:findFirstChild("Wipeouts")
  9. if deaths ~= nil then
  10. deaths.Value = deaths.Value + 1
  11.  
  12. -- do short dance to try and find the killer
  13.  
  14. local killer = getKillerOfHumanoidIfStillInGame(humanoid)
  15.  
  16. handleKillCount(humanoid, player)
  17. end
  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.  
  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(3)
  111. end
  112.  
  113. stats.Parent = newPlayer
  114.  
  115. else
  116.  
  117. local stats = Instance.new("IntValue")
  118. stats.Name = "leaderstats"
  119.  
  120. -- local l = Instance.new("IntValue")
  121. -- l.Name = "Medals"
  122. -- l.Value = 0
  123.  
  124. -- local b = Instance.new("IntValue")
  125. -- b.Name = "Boost"
  126. -- b.Value = 0
  127.  
  128. local w = Instance.new("IntValue")
  129. w.Name = "Points"
  130. w.Value = 0
  131.  
  132. -- b.Parent = stats
  133. w.Parent = stats
  134. -- l.Parent = stats
  135.  
  136. -- VERY UGLY HACK
  137. -- Will this leak threads?
  138. -- Is the problem even what I think it is (player arrived before character)?
  139. while true do
  140. if newPlayer.Character ~= nil then break end
  141. wait(3)
  142. end
  143.  
  144. local humanoid = newPlayer.Character.Humanoid
  145.  
  146. humanoid.Died:connect(function() onHumanoidDied(humanoid, newPlayer) end )
  147.  
  148. -- start to listen for new humanoid
  149. newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )
  150.  
  151.  
  152. stats.Parent = newPlayer
  153.  
  154. end
  155.  
  156. end
  157.  
  158.  
  159. function onCaptureScored(player)
  160.  
  161. local ls = player:findFirstChild("leaderstats")
  162. if ls == nil then return end
  163. local caps = ls:findFirstChild("Captures")
  164. if caps == nil then return end
  165. caps.Value = caps.Value + 1
  166.  
  167. end
  168.  
  169.  
  170. findAllFlagStands(game.Workspace)
  171. hookUpListeners()
  172. if (#stands > 0) then CTF_mode = true end
  173. game.Players.ChildAdded:connect(onPlayerEntered)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement