Advertisement
sniki10

Untitled

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