Advertisement
Patosho

Ejemplo FFA

Dec 6th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.15 KB | None | 0 0
  1. --  variables modificables
  2. ---------------------------------
  3. despawnTime = 1500
  4. fireDelay = 200
  5. offsetX = 0
  6. offsetY = 0
  7. ---------------------------------
  8.  
  9. keys = {0,2,32}
  10. _left = 0
  11. _right = 2
  12.  
  13. facingLeft = {}
  14. toDespawn = {}
  15. fireTS = {}
  16.  
  17. function main()
  18.     for n in pairs(tfm.get.room.playerList) do
  19.         eventNewPlayer(n)
  20.     end
  21. end
  22.  
  23. function eventNewPlayer(name)
  24.     facingLeft[name] = false
  25.     fireTS[name] = 0
  26.    
  27.     for _,k in pairs(keys) do
  28.         system.bindKeyboard(name, k, true)
  29.     end
  30. end
  31.  
  32. function eventLoop(t, tr)
  33.     for i,o in ipairs(toDespawn) do
  34.         if os.time() > o[2]+despawnTime then
  35.             tfm.exec.removeObject (o[1])
  36.             table.remove (toDespawn, i)
  37.         end
  38.     end
  39. end
  40.  
  41. function eventKeyboard(name, key, down, px, py)
  42.     if key == _left then
  43.         facingLeft[name] = true
  44.    
  45.     elseif key == _right then
  46.         facingLeft[name] = false
  47.    
  48.     elseif key==32 and os.time() > fireTS[name] + fireDelay then
  49.         fireTS[name] = os.time()
  50.         local dx,a,id
  51.         if facingLeft[name] then
  52.             dx,dy,a = -30,0,-90
  53.         else
  54.             dx,dy,a = 30,0,90
  55.         end
  56.         id = tfm.exec.addShamanObject(17, px+dx+offsetX, py+offsetY, a)
  57.         table.insert(toDespawn, {id, os.time()})
  58.     end
  59. end
  60.  
  61. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement