Advertisement
Eliaseeg

Sistema de ataque, defensa y curación. (con equipos)

Mar 23rd, 2015
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.74 KB | None | 0 0
  1. local map = '<C><P Ca="" L="2000" /><Z><S><S P="0,0,0.3,0.2,-40,0,0,0" L="218" o="8c303b" X="320" Y="353" T="12" H="32" /><S P="0,0,0.3,0.2,0,0,0,0" L="319" o="8c303b" X="160" Y="388" T="12" H="29" /><S P="0,0,0.3,0.2,,0,0,0" L="218" o="8c303b" H="32" Y="295" T="12" X="84" /><S L="218" o="8c303b" X="267" H="32" Y="229" T="12" P="0,0,0.3,0.2,-40,0,0,0" /><S L="800" o="afc1cb" X="15" H="29" Y="0" T="12" P="0,0,0,0.2,90,0,0,0" /><S L="145" o="8c303b" H="32" X="492" Y="208" T="12" P="0,0,0.3,0.2,-45,0,0,0" /><S P="0,0,0,0.2,,0,0,0" L="2100" o="afc1cb" H="29" Y="10" T="12" X="1050" /><S L="399" o="20941f" H="32" X="1072" Y="385" T="12" P="0,0,0.3,0.2,0,0,0,0" /><S L="211" o="20941f" X="1333" H="32" Y="315" T="12" P="0,0,0.3,0.2,-45,0,0,0" /><S P="0,0,0.3,0.2,0,0,0,0" L="399" o="20941f" X="939" Y="385" T="12" H="32" /><S L="211" o="20941f" H="32" X="751" Y="231" T="12" P="0,0,0.3,0.2,-45,0,0,0" /><S L="82" H="10" X="1919" Y="370" T="2" P="0,0,0,0.6,0,0,0,0" /><S L="211" o="20941f" X="982" H="32" Y="237" T="12" P="0,0,0.3,0.2,30,0,0,0" /><S P="0,0,0,0.2,90,0,0,0" L="800" o="afc1cb" H="29" Y="0" T="12" X="1985" /><S L="258" o="1070a1" H="32" X="1841" Y="384" T="12" P="0,0,0.3,0.2,0,0,0,0" /><S P="0,0,0.3,0.2,45,0,0,0" L="200" o="1070a1" X="1763" Y="224" T="12" H="32" /><S L="120" o="1070a1" X="1536" H="32" Y="321" T="12" P="0,0,0.3,0.2,45,0,0,0" /><S P="0,0,0.3,0.2,0,0,0,0" L="270" o="1070a1" X="1497" Y="128" T="12" H="32" /><S L="270" o="20941f" X="1106" H="32" Y="128" T="12" P="0,0,0.3,0.2,0,0,0,0" /></S><D><DS Y="362" X="38" /></D><O /></Z></C>'
  2. local mice = {}
  3. local attack,deff,healer,leader = 1,2,3,4,5
  4. local red = {}
  5. local blue = {}
  6. function table_foreach(tab, func) for i,v in pairs(tab) do func(i,v) end end
  7.  
  8. function main()
  9.     tfm.exec.disableAutoShaman(true)
  10.     tfm.exec.disableAutoNewGame(true)
  11.     tfm.exec.disableAutoTimeLeft(true)
  12.     tfm.exec.newGame(map)
  13.     table_foreach(tfm.get.room.playerList, _G["eventNewPlayer"])
  14.     started = false
  15. end
  16.  
  17. _G["eventNewPlayer"]=function(name)
  18.     if not mice[name] then
  19.         mice[name] = {
  20.             class = attack,
  21.             hp = 100,
  22.             attack_bonus = math.random(5,10),
  23.             deff_bonus = math.random(3, 5),
  24.             cur_bonus = 0,
  25.             attack_countdown = 2.5,
  26.             cur_countdown = 2.5
  27.         }
  28.     end
  29.     tfm.exec.bindKeyboard(name, string.byte(" "), true, true)
  30. end
  31.  
  32. function eventNewGame()
  33.     blue = {}
  34.     red = {}
  35.     started = true
  36.     for name,_ in pairs(tfm.get.room.playerList) do
  37.         setUp(name)
  38.     end
  39.     makeTeams()
  40. end
  41.  
  42. function setUp(name)
  43. mice[name].attack_countdown = 2.5
  44. mice[name].cur_countdown = 2.5
  45.     if mice[name].class == 1 then
  46.         mice[name].attack_bonus = math.random(10, 15)
  47.         mice[name].deff_bonus = math.random(4, 6)
  48.     elseif mice[name].class == 2 then
  49.         mice[name].attack_bonus = math.random(4, 6)
  50.         mice[name].deff_bonus = math.random(10, 15)
  51.     elseif mice[name].class == 3 then
  52.         mice[name].cur_bonus = math.random(7,14)
  53.         mice[name].attack_bonus = 0
  54.         mice[name].deff_bonus = 0
  55.     elseif mice[name].class == 4 then
  56.         mice[name].attack_bonus = math.random(13, 17)
  57.         mice[name].deff_bonus = math.random(3, 5)
  58.     end
  59. end
  60.  
  61. function wizzard(wizzard_type, x, y, mice1, mice2)
  62. player = tfm.get.room.playerList[mice2]
  63.     if table.find(red, mice1) then
  64.         value = blue
  65.     elseif table.find(blue, mice1) then
  66.         value = red
  67.     end
  68.     if wizzard_type == 1 and mice[mice1].attack_countdown <= 0 and table.find(value, mice2) then
  69.         op = mice[mice1].attack_bonus - mice[mice2].deff_bonus
  70.         mice[mice2].hp = mice[mice2].hp - op
  71.         setUp(mice1)
  72.         print(mice2.." - "..mice[mice2].hp)
  73.         particles(30, player.x, player.y)
  74.         if mice[mice2].hp <= 0 then
  75.             mice[mice2].hp = 0
  76.             tfm.exec.killPlayer(mice2)
  77.         end
  78.     elseif wizzard_type == 2 and mice[mice1].cur_countdown <= 0 and table.find(value, mice2) then
  79.         if mice[mice2].hp <= 100 then
  80.             mice[mice2].hp = mice[mice2].hp + mice[mice1].cur_bonus
  81.             particles(35, player.x, player.y)
  82.             setUp(mice1)           
  83.         else
  84.             mice[mice2].hp = 100
  85.         end
  86.     end
  87. end
  88.  
  89. function particles(id, x, y)
  90.     for i=1,3 do
  91.         tfm.exec.displayParticle(id, x, y, math.random(-3,3), -9, 0,math.random(8,15)/10, nil) 
  92.     end
  93. end
  94.  
  95. function eventLoop()
  96.     for name,_ in pairs(tfm.get.room.playerList) do
  97.         if started then
  98.             ui.addTextArea(0, "<r><b>HP</b>: "..mice[name].hp.."<n>   |    <bv><b>Attack B</b>: "..mice[name].attack_bonus.."</b><n>      |   <ch><b>Deff B</b>: "..mice[name].deff_bonus.."<n>   |   <v><b>Cur B</b>: "..mice[name].cur_bonus, name, 400, 380, 395, 20, 0x191919, 0x191919, 0.6, true)
  99.             mice[name].attack_countdown = mice[name].attack_countdown - 0.5
  100.             mice[name].cur_countdown = mice[name].cur_countdown - 0.5
  101.         end
  102.     end
  103. end
  104.  
  105. function eventKeyboard(name, key, down, x, y)
  106.     if key == string.byte(" ") then
  107.         for playerName, player in pairs(tfm.get.room.playerList) do
  108.             if pythag(x, y, player.x, player.y, 25) and name ~= playerName and not player.isDead then
  109.                 if mice[name].class == 1 or mice[name].class == 2 or mice[name].class == 4 then
  110.                     wizzard(1, player.x, player.y, name, playerName)
  111.                 elseif mice[name].class == 3 then
  112.                     wizzard(2, player.x, player.y, name, playerName)
  113.                 end
  114.             end
  115.         end
  116.     end
  117. end
  118.  
  119. function makeTeams()
  120. local playerList={}
  121.     for name, player in pairs(tfm.get.room.playerList) do
  122.         table.insert(playerList, name)
  123.     end
  124.     for i=1,#playerList,1 do
  125.         local index = math.random(#playerList)
  126.         local name = playerList[index]
  127.     if i%2==0 then
  128.         table.insert(red, name)
  129.         tfm.exec.setNameColor(name, 0x8c303b)
  130.     else
  131.         table.insert(blue, name)
  132.         tfm.exec.setNameColor(name, 0x1070a1)
  133.     end
  134.         table.remove(playerList,index)
  135.     end
  136. end
  137.  
  138. function table.find(tab, elmt)
  139.     for key, val in pairs(tab) do
  140.         if val==elmt then return true, key end
  141.     end
  142.     return false
  143. end
  144.  
  145. function pythag(x1,y1,x2,y2,r)
  146.     local x=x2-x1
  147.     local y=y2-y1
  148.     local r=r+r
  149.     return x*x+y*y<r*r
  150. end
  151.  
  152. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement