Skip to content

Instantly share code, notes, and snippets.

@Patosito
Created September 12, 2016 18:34
Show Gist options
  • Save Patosito/2181125255de3724f1249f8fbd1173ad to your computer and use it in GitHub Desktop.
Save Patosito/2181125255de3724f1249f8fbd1173ad to your computer and use it in GitHub Desktop.
Lanzar cañones / FFA
-- variables modificables
---------------------------------
despawnTime = 1500
fireDelay = 200
offsetX = 0
offsetY = 0
---------------------------------
keys = {0,2,32}
_left = 0
_right = 2
facingLeft = {}
toDespawn = {}
fireTS = {}
function main()
for n in pairs(tfm.get.room.playerList) do
eventNewPlayer(n)
end
end
function eventNewPlayer(name)
facingLeft[name] = false
fireTS[name] = 0
for _,k in pairs(keys) do
system.bindKeyboard(name, k, true)
end
end
function eventLoop(t, tr)
for i,o in ipairs(toDespawn) do
if os.time() > o[2] + despawnTime then
tfm.exec.removeObject (o[1])
table.remove (toDespawn, i)
end
end
end
function eventKeyboard(name, key, down, px, py)
if key == _left then
facingLeft[name] = true
elseif key == _right then
facingLeft[name] = false
elseif key==32 and os.time() > fireTS[name] + fireDelay then
fireTS[name] = os.time()
local dx,a,id
if facingLeft[name] then
dx,dy,a = -30,0,-90
else
dx,dy,a = 30,0,90
end
id = tfm.exec.addShamanObject(17, px+dx+offsetX, py+offsetY, a)
table.insert(toDespawn, {id, os.time()})
end
end
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment