· 6 years ago · Mar 10, 2020, 09:02 PM
1local killer = "Brandondito#0000"
2
3-- Set "EVERYONE = true" if you want everyone to be able to kill
4local EVERYONE = false
5
6local SPACE_KEY = 32
7local MINIMUM_KILL_RANGE = 50
8
9-- Checking if a certain coordinate is within the range of another coordinate
10function withinRange(x1, y1, x2, y2, range)
11 local xDist = math.abs(x1 - x2)
12 local yDist = math.abs(y1 - y2)
13
14 if xDist < range and yDist < range then
15 return true
16 end
17
18 return false
19end
20
21-- If a player joins, bind their spacebar keyboard-key based on the configured settings.
22function eventNewPlayer(name)
23
24 if EVERYONE or killer == name then
25 tfm.exec.bindKeyboard(name, SPACE_KEY, true, true)
26 end
27end
28
29-- Function provided by TFM's API. Occurs whenever someone presses a binded key.
30function eventKeyboard(name, key, down, x, y)
31
32 if key == SPACE_KEY then
33 for _name, player in next, tfm.get.room.playerList do
34 if _name ~= name and withinRange(x, y, player.x, player.y, MINIMUM_KILL_RANGE) then
35 tfm.exec.killPlayer(_name)
36 end
37 end
38 end
39end
40
41-- For every player in the room, run eventNewPlayer on them.
42-- tfm.get.room.playerList gives us a list of players in the room.
43for name in next, tfm.get.room.playerList do
44 eventNewPlayer(name)
45end