Advertisement
sniki10

Untitled

Aug 26th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.53 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5. tfm.exec.disableAutoShaman(true)
  6. tfm.exec.disableAutoNewGame(true);
  7. tfm.exec.newGame("@4734030")
  8. maps={"@2386206", "@2221623", "@2186198", "@4734030"}
  9. function eventLoop(timePassed, timeLeft)
  10. if alive == 0 or timeLeft < 1000 then
  11. nextRound();
  12. end
  13. end
  14. function nextRound()
  15. tfm.exec.newGame(maps[math.random(#maps)]);
  16. end
  17.  
  18. function eventNewGame()
  19. alive=0
  20. for name,player in pairs(tfm.get.room.playerList) do
  21. alive=alive+1
  22. end
  23. end
  24.  
  25.  
  26. local players = {}
  27. local objects = {}
  28.  
  29. function main()
  30. objects = queue.new()
  31. tfm.exec.disableAutoScore(false)
  32. tfm.exec.disableAutoShaman(true)
  33. tfm.exec.setUIMapName('<ROSE> </B> #SNIPER ')
  34. end
  35. print("<rose>Welcome to new game - Sniper! [TUTORIAL] Use the mouse to aim and shoot!")
  36. function eventNewGame()
  37. players = {}
  38. for name in pairs(tfm.get.room.playerList) do
  39. initPlayer(name)
  40. end
  41. end
  42.  
  43. function initPlayer(name)
  44. players[name] = {ammo = 0}
  45. ui.addTextArea(0, "", name, 10, 30, 6 * 15, 20, 0x010101, 0x000000, 0.5)
  46. system.bindMouse(name, true)
  47. end
  48.  
  49. function eventMouse(name, x, y)
  50. local player = players[name]
  51. if player and player.ammo > 0 then
  52. -- remove one ammo
  53. ui.removeTextArea(player.ammo * 2 - 1, name)
  54. ui.removeTextArea(player.ammo * 2, name)
  55. player.ammo = player.ammo - 1
  56.  
  57. local roomPlayer = tfm.get.room.playerList[name]
  58.  
  59. -- calculate angle between player and click
  60. local dx = x - roomPlayer.x
  61. local dy = y - roomPlayer.y
  62. local angle = math.atan2(dy, dx)
  63.  
  64. -- calculate speeds to direct arrow and always have the same total speed
  65. local vx = math.cos(angle)
  66. local vy = math.sin(angle)
  67.  
  68. -- spawn arrow and add to queue
  69. queue.insert(objects, tfm.exec.addShamanObject(35, roomPlayer.x + 20 * vx, roomPlayer.y + 20 * vy, angle*180/math.pi, 50 * vx, 50 * vy, false))
  70.  
  71. local recoil = -vx * 10
  72. -- workaround to avoid argument exception bug
  73. if recoil <= -1 or recoil >= 1 then
  74. tfm.exec.movePlayer(name, 0, 0, true, recoil, 0, true)
  75. end
  76.  
  77. -- remove first arrow when there are too many
  78. if objects.size > 10 then
  79. tfm.exec.removeObject(queue.remove(objects))
  80. end
  81. end
  82. end
  83.  
  84. local loopCount = 0
  85. function eventLoop()
  86. -- loopCount resets after a certain amount
  87. if loopCount == 0 then
  88. ammo()
  89. end
  90. loopCount = (loopCount + 3) % 2
  91. end
  92.  
  93. function ammo()
  94. for name, player in pairs(players) do
  95. local ammo = player.ammo
  96. if ammo < 6 then
  97. -- add one ammo
  98. player.ammo = ammo + 1
  99. ui.addTextArea(ammo * 2 + 1, "", name, 14 + ammo * 15, 39, 3, 3, 0x990000, 0x990000, 1)
  100. ui.addTextArea(ammo * 2 + 2, "", name, 15 + ammo * 15, 40, 1, 1, 0xff0000, 0xcc0000, 1)
  101.  
  102. end
  103. end
  104. end
  105.  
  106. function eventNewPlayer(name)
  107. initPlayer(name)
  108.  
  109. end
  110.  
  111.  
  112. function eventPlayerWon(name)
  113.  
  114. end
  115.  
  116.  
  117. -- simple queue for performance, much faster than system table queues, can contain nils
  118. queue = {}
  119. function queue.new()
  120. return {
  121. tail = nil,
  122. head = nil,
  123. size = 0
  124. }
  125. end
  126. function queue.insert(self, v)
  127. local i = {
  128. value = v,
  129. next = nil
  130. }
  131. if self.tail and self.head then
  132. self.tail.next = i
  133. else
  134. self.head = i
  135. end
  136. self.tail = i
  137. self.size = self.size + 1
  138. end
  139. function queue.peek(self)
  140. if self.head then
  141. return self.head.value
  142. else
  143. error("queue is empty")
  144. end
  145. end
  146. function queue.remove(self)
  147. local r = queue.peek(self)
  148. self.head = self.head.next
  149. if not self.head then
  150. tail = nil
  151. end
  152. self.size = self.size - 1
  153. return r
  154. end
  155.  
  156.  
  157. function eventChatCommand(name,command)
  158. if command == "credits" then
  159. ui.addPopup(1, 0, "Creators: Ovcapolska & Kubaws. Thanks for: Gunitor.", name, 280, 100, 270)
  160. elseif command== "q" then
  161. for p in pairs(tfm.get.room.playerList) do
  162. tfm.exec.setNameColor("Ovcapolska",0x12cd5f)
  163. tfm.exec.setNameColor("Kubaws",0x12cd5f)
  164. end
  165. end
  166. end
  167.  
  168. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement