Advertisement
Eliaseeg

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

Feb 21st, 2015
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.33 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. end
  15.  
  16. _G["eventNewPlayer"]=function(name)
  17.     if not mice[name] then
  18.         mice[name] = {
  19.             class = healer,
  20.             hp = 100,
  21.             attack_bonus = math.random(5,10),
  22.             deff_bonus = math.random(3, 5),
  23.             cur_bonus = nil,
  24.             attack_countdown = 2.5,
  25.             cur_countdown = 2.5
  26.         }
  27.     end
  28.     tfm.exec.bindKeyboard(name, string.byte(" "), true, true)
  29. end
  30.  
  31. function eventNewGame()
  32.     blue = {}
  33.     red = {}
  34.     for name,_ in pairs(tfm.get.room.playerList) do
  35.         setUp(name)
  36.     end
  37.     makeTeams()
  38. end
  39.  
  40. function setUp(name)
  41. mice[name].attack_countdown = 2.5
  42.     if mice[name].class == 1 then
  43.         mice[name].attack_bonus = math.random(10, 15)
  44.         mice[name].deff_bonus = math.random(4, 6)
  45.     elseif mice[name].class == 2 then
  46.         mice[name].attack_bonus = math.random(4, 6)
  47.         mice[name].deff_bonus = math.random(10, 15)
  48.     elseif mice[name].class == 3 then
  49.         mice[name].cur_bonus = math.random(7,14)
  50.         mice[name].attack_bonus = 0
  51.         mice[name].deff_bonus = 0
  52.     elseif mice[name].class == 4 then
  53.         mice[name].attack_bonus = math.random(13, 17)
  54.         mice[name].deff_bonus = math.random(3, 5)
  55.     end
  56. end
  57.  
  58. function wizzard(wizzard_type, x, y, mice1, mice2)
  59.     if wizzard_type == 1 and mice[mice1].attack_countdown <= 0 then
  60.         player = tfm.get.room.playerList[mice2]
  61.         op = mice[mice1].attack_bonus - mice[mice2].deff_bonus
  62.         mice[mice2].hp = mice[mice2].hp - op
  63.         print(mice2.. "-" ..mice[mice2].hp)
  64.         setUp(mice1)
  65.         attack_particle(player.x, player.y)
  66.         if mice[mice2].hp <= 0 then
  67.             mice[mice2].hp = 0
  68.             tfm.exec.killPlayer(mice2)
  69.         end
  70.     elseif wizzard_type == 2 and mice[mice1].cur_countdown <= 0 then
  71.         if mice[mice2].hp <= 100 then
  72.             mice[mice2].hp = mice[mice2].hp + mice[mice1].cur_bonus
  73.         else
  74.             mice[mice2].hp = 100
  75.         end
  76.     end
  77. end
  78.  
  79. function attack_particle(x, y)
  80.     for i=1,3 do
  81.         tfm.exec.displayParticle(30, x, y, math.random(-3,3), -9, 0,math.random(8,15)/10, nil) 
  82.     end
  83. end
  84.  
  85. function eventLoop()
  86.     for name,_ in pairs(tfm.get.room.playerList) do
  87.         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)
  88.         mice[name].attack_countdown = mice[name].attack_countdown - 1
  89.         mice[name].cur_countdown = mice[name].attack_countdown
  90.     end
  91. end
  92.  
  93. function eventKeyboard(name, key, down, x, y)
  94.     if key == string.byte(" ") then
  95.         for playerName, player in pairs(tfm.get.room.playerList) do
  96.             if pythag(x, y, player.x, player.y, 25) and name ~= playerName then
  97.                 if mice[name].class == 1 or mice[name].class == 2 or mice[name].class == 4 then
  98.                     wizzard(1, player.x, player.y, name, playerName)
  99.                 elseif mice[name].class == 3 then
  100.                     wizzard(2, player.x, player.y, name, playerName)
  101.                 end
  102.             end
  103.         end
  104.     end
  105. end
  106.  
  107. function makeTeams()
  108. local playerList={}
  109.     for name,player in pairs(tfm.get.room.playerList) do
  110.         table.insert(playerList,name)
  111.     end
  112.     for i=1,#playerList,1 do
  113.         local index=math.random(#playerList)
  114.         local name=playerList[index]
  115.     if i%2==0 then
  116.         table.insert(red,name)
  117.     else
  118.         table.insert(blue,name)
  119.     end
  120.         table.remove(playerList,index)
  121.     end
  122. end
  123.  
  124. function table.find(tab, elmt)
  125.     for key, val in pairs(tab) do
  126.         if val==elmt then return true, key end
  127.     end
  128.     return false
  129. end
  130.  
  131. function pythag(x1,y1,x2,y2,r)
  132.     local x=x2-x1
  133.     local y=y2-y1
  134.     local r=r+r
  135.     return x*x+y*y<r*r
  136. end
  137.  
  138.  
  139. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement