Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local settings = {
- map = "@1920957",
- ammo = 6,
- force = 50,
- recoil = 10,
- maxObjects = 10,
- ammoTicks = 2,
- }
- local players = {}
- local objects = {}
- function main()
- objects = queue.new()
- tfm.exec.disableAutoScore(false)
- tfm.exec.disableAutoShaman(true)
- tfm.exec.disableAutoNewGame(true)
- tfm.exec.newGame(settings.map)
- tfm.exec.setUIMapName('<ROSE> </B> #SNIPER ')
- end
- print("<rose>Welcome to new game - Sniper! [TUTORIAL] Use the mouse to aim and shoot!")
- function eventNewGame()
- players = {}
- for name in pairs(tfm.get.room.playerList) do
- initPlayer(name)
- end
- end
- function initPlayer(name)
- players[name] = {ammo = 0}
- ui.addTextArea(0, "", name, 10, 30, settings.ammo * 15, 20, 0x010101, 0x000000, 0.5)
- system.bindMouse(name, true)
- end
- function eventMouse(name, x, y)
- local player = players[name]
- if player and player.ammo > 0 then
- -- remove one ammo
- ui.removeTextArea(player.ammo * 2 - 1, name)
- ui.removeTextArea(player.ammo * 2, name)
- player.ammo = player.ammo - 1
- local roomPlayer = tfm.get.room.playerList[name]
- -- calculate angle between player and click
- local dx = x - roomPlayer.x
- local dy = y - roomPlayer.y
- local angle = math.atan2(dy, dx)
- -- calculate speeds to direct arrow and always have the same total speed
- local vx = math.cos(angle)
- local vy = math.sin(angle)
- -- spawn arrow and add to queue
- 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))
- local recoil = -vx * settings.recoil
- -- workaround to avoid argument exception bug
- if recoil <= -1 or recoil >= 1 then
- tfm.exec.movePlayer(name, 0, 0, true, recoil, 0, true)
- end
- -- remove first arrow when there are too many
- if objects.size > settings.maxObjects then
- tfm.exec.removeObject(queue.remove(objects))
- end
- end
- end
- local loopCount = 0
- function eventLoop()
- -- loopCount resets after a certain amount
- if loopCount == 0 then
- ammo()
- end
- loopCount = (loopCount + 3) % settings.ammoTicks
- end
- function ammo()
- for name, player in pairs(players) do
- local ammo = player.ammo
- if ammo < settings.ammo then
- -- add one ammo
- player.ammo = ammo + 1
- ui.addTextArea(ammo * 2 + 1, "", name, 14 + ammo * 15, 39, 3, 3, 0x990000, 0x990000, 1)
- ui.addTextArea(ammo * 2 + 2, "", name, 15 + ammo * 15, 40, 1, 1, 0xff0000, 0xcc0000, 1)
- end
- end
- end
- function eventNewPlayer(name)
- initPlayer(name)
- end
- function eventPlayerWon(name)
- end
- -- simple queue for performance, much faster than system table queues, can contain nils
- queue = {}
- function queue.new()
- return {
- tail = nil,
- head = nil,
- size = 0
- }
- end
- function queue.insert(self, v)
- local i = {
- value = v,
- next = nil
- }
- if self.tail and self.head then
- self.tail.next = i
- else
- self.head = i
- end
- self.tail = i
- self.size = self.size + 1
- end
- function queue.peek(self)
- if self.head then
- return self.head.value
- else
- error("queue is empty")
- end
- end
- function queue.remove(self)
- local r = queue.peek(self)
- self.head = self.head.next
- if not self.head then
- tail = nil
- end
- self.size = self.size - 1
- return r
- end
- function eventChatCommand(name,command)
- if command == "credits" then
- ui.addPopup(1, 0, "Creators: Ovcapolska & Kubaws. Thanks for: Gunitor.", name, 280, 100, 270)
- elseif command== "q" then
- for p in pairs(tfm.get.room.playerList) do
- tfm.exec.setNameColor(name,0x12cd5f)
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement