musugas

Surviver

Jan 6th, 2019
852
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 31.65 KB | None | 0 0
  1. -- OldSurvivor #2
  2.  
  3. --[[    ID list
  4. textArea
  5. 1   debug(?) classic
  6. 10  notifications - cerrar (hardmode, achievements)
  7. 11  perfil - ventana principal
  8. 12  perfil - cerrar
  9. 21+ perfil - pestañas
  10.  
  11. popUp
  12.  
  13. ]]
  14.  
  15.  
  16. do
  17.     function flattenFunctionTree(tree, path)
  18.         for name, value in pairs(tree) do
  19.             if type(value) == "table" then
  20.                 flattenFunctionTree(value, path .. name .. "_")
  21.             elseif type(value) == "function" then
  22.                 _G[path .. name] = value
  23.             end
  24.         end
  25.     end
  26.    
  27.     local temp = {}
  28.     for name, value in pairs(_G) do
  29.         if value ~= _G then
  30.             temp[name] = value
  31.         end
  32.     end
  33.     flattenFunctionTree(temp, "")
  34. end
  35.  
  36. local game_name = "new old new old new survivor"
  37. local game_owner = "Musugas"
  38. local game_id = 101
  39. local game_data_version = 3
  40. local data_header = "PATO0003"
  41.  
  42. local stats_name = {"level","exp","money","a_shop"}
  43. local stats_size = {1,3,3,1}
  44. local stats_n = 4
  45.  
  46. local playerData = {}
  47. local playerFile = {}
  48.  
  49. --  settings
  50. local s_min_players = 3
  51. local s_max_level = 100
  52. local imgs = {
  53.     logo = "";
  54.     logros = {},
  55.     win ="",
  56.     no_shamanModes="",
  57.     windows = {"","",""}, -- Shop, Ranking, Logros
  58.     profile = {} -- Random  imgs
  59.     }
  60. local _unlock = {
  61.     {1,3,5,10,20,40},
  62.     {1,2},
  63.     {1,2},
  64.     {1},
  65.     {1},
  66.     {1},
  67.     {1}
  68. }
  69. local text = {
  70.     es = {
  71.         logros = {
  72.             {"Ratón Clásico","a2","a3","a4","a5","a6"},
  73.             {"En equipos","Patata"},
  74.             {"Granja de ovejas","Ponquesito"},
  75.             {"Chamán unitario"},
  76.             {"Conde Drekkemaus"},
  77.             {"Caza fantasmas"},
  78.             {"Cursor"}
  79.         },
  80.         welcome = "Bienvenido a #OldSurvivor. Estamos en fase de pruebas, todo lo hecho, será borrado despues.",  
  81.         ach_unlocked = "Nuevo logro desbloqueado",
  82.         hm_header = "Desactiva Hard Mode o Divine Mode para jugar",
  83.         hm_text = "Al hacerlo, reaparecerás",
  84.         lvl_up = "%s <BL>ha subido al nivel %d",
  85.         team_win = "El equipo %s ha ganado",
  86.         shaman_win = "¡El chamán ha ganado!",
  87.         mice_win = "¡Los ratones han ganado!",
  88.         no_win = "Nadie ganó :[",
  89.         countdown = "<BL>El chamán tiene 20 segundos para matar a %s",
  90.         is_shaman = "%s <BL>es ahora el chamán ¡Cuidado!",
  91.         is_vampire = "%s es ahora Drekkemaus",
  92.         blue = "Azul",
  93.         red = "Rojo",
  94.         win = "%s ha ganado",
  95.         vampire_win = "Los sirvientes del conde Drekkemaus, han ganado",
  96.         introduction = {
  97.             [0] = "Se necesitan 3 ratones para jugar",
  98.             "Sobrevive al ataque del todopoderoso chamán",
  99.             "¡Derrota al otro equipo!",
  100.             "Abre el paraguas, y cubrete de la lluvia de objetos",
  101.             "Derrota a los demás chamanes",
  102.             "Muerde a los demás",
  103.             "¡BUU! Cuidado con los fantasmas",
  104.             "El mundo informatico le dió el poder del Mouse a un raton"
  105.         }
  106.     },
  107.     en = {
  108.         logros = {
  109.             {"Ratón Clásico","a2","a3","a4","a5","a6"},
  110.             {"En equipos","Patata"},
  111.             {"Granja de ovejas","Ponquesito"},
  112.             {"Chamán unitario"},
  113.             {"Conde Drekkemaus"},
  114.             {"Caza fantasmas"},
  115.             {"Cursor"}
  116.         },
  117.         welcome = "Welcome to #OldSurvivor. We are in testings, everything done, will be deleted later.",      
  118.         ach_unlocked = "New achievement unlocked",
  119.         hm_header = "Disable Hard Mode or Divine Mode to play",
  120.         hm_text = "Once disabled, you'll reappear",
  121.         lvl_up = "%s is now level %d",
  122.         team_win = "%s team has won",
  123.         shaman_win = "The Shaman has won!",
  124.         mice_win = "The mice have won!",
  125.         no_win = "No contest :[",
  126.         countdown = "The Shaman's got 20 seconds to kill %s",
  127.         is_shaman = "%s is now the Shaman. Watch out!",
  128.         is_vampire = "%s is now Drekkemaus",
  129.         blue = "Blue",
  130.         red = "Red",
  131.         win = "%s has won",
  132.         vampire_win = "Count Drekkemaus' servants have won",
  133.         introduction = {
  134.             [0] = "3 mice are needed in order to play",
  135.             "Survive the attack of the almighty Shaman",
  136.             "Defeat the other team!",
  137.             "Open the umbrella, and cover yourself from the rain of objects",
  138.             "Defeat the other shamans",
  139.             "Bite the other mice",
  140.             "BOO! Watch out for the ghosts",
  141.             "Computer science gave a mouse the power of the Click"
  142.         }
  143.     }
  144. }    
  145.  
  146. --  const
  147. local LOBBY,CLASSIC,TEAMS,RAIN,ALLSHAMANS,VAMPIRE,GHOST,CLICK = 0,1,2,3,4,5,6,7
  148.  
  149. --  datos
  150. --local maps = {5356733,4752763,5315470,5346896,4858080,4690132,4975835,5355152,5356589,5356805,5356815,5358594,5382526,5383222,5383462,5315218,4667683,5383505,4666824,4666393,4494912,4479901,4478049,4446077,4386714,4372471,4671796,5393225,5393409,5393149,5393484,5393151,5397551,5402869,5399385,5402898,5399265,5416277,5412457,5420479,5420408,5432422,5432381,5432347,5435548,5428059,5427979,5425838,5425724,5422451,5422637,5422414,5420632,5421011,5420537}
  151. local maps = {5355152,5445280,5346896,5393409,5445181,5445572,5445400}
  152. local lobby = {5468613,5468613}
  153.  
  154. --local maps = {5355152,5355152}    --CLASSIC
  155. --local maps = {5445280,5445280}    --TEAMS
  156. --local maps = {5346896,5346896}    --RAIN
  157. --local maps = {5393409,5393409}    --AllSHAMANS
  158. --local maps = {5445181,5445181}    --VAMPIRE
  159. --local maps = 55445262,5445262}    --GHOST
  160. --local maps = {5445572,5445572}    -- Ghost ~viprin
  161. --local maps = {5445400,5445400}      -- Clicker
  162.  
  163. local keys = {37,64,81,39,68,32,40,83}
  164.  
  165. local _modos = {
  166.     {"Lobby",30,0,0},
  167.     {"Classic",120,30,10},
  168.     {"Teams",130,30,10},
  169.     {"Rain",60,25,10},
  170.     {"Allshamans",130,35,20},
  171.     {"Vampire",120,35,20},
  172.     {"Ghost",60,25,10},
  173.     {"Click",130,30,20},
  174. }
  175. local modos = {}
  176. for i=1,8 do modos[i-1] = {name = _modos[i][1], time = _modos[i][2], exp = math_floor(_modos[i][3]/5), money = math.floor(_modos[i][4]/5)} end
  177.  
  178. --  variables del juego
  179. local playersInRoom = 0
  180. local playersAlive = 99
  181. local shaman
  182. local vampire = {}
  183. local miceAlive = {}
  184. local currentMap
  185. local gameMode
  186. local gameLoaded
  187. local gameStarted
  188. local gameFinished
  189. local blue = {}
  190. local red = {}
  191. local startMode = false
  192. local xmldom
  193. local data = {}
  194. local imageBox_id = {}
  195. local inEasyMode = {}
  196. local mice_afk = {}
  197. local killed_afk
  198. -- variables específicas de minijuegos
  199. -- classic
  200. local classic_countdown
  201. local classic_winner
  202. local classic_rival
  203. -- teams
  204. local teams_red = {}
  205. local teams_blue = {}
  206. local teams_blue_n = 0
  207. local teams_red_n = 0
  208. -- rain
  209. local rain_winner
  210. -- allshamans
  211. local allshamans_winner
  212. -- vampire
  213. local vampire_winner
  214. local vampire_normalMice
  215. -- ghost
  216. local ghost_winner
  217. -- click
  218. local click_countdown
  219. local click_winner
  220. local click_rival
  221.  
  222. function loadGame()
  223.     tfm.exec.disableAutoNewGame(true)  
  224.     tfm.exec.disableAutoTimeLeft(true)
  225.     tfm.exec.disableAllShamanSkills(true)
  226.     tfm.exec.disableAutoShaman (true)
  227.     tfm.exec.disableAutoTimeLeft (true)
  228.     math_randomseed(os.time())
  229.     for _,com in ipairs({"comando","comandu"}) do
  230.         system_disableChatCommandDisplay(com, true)
  231.     end
  232.     for name in pairs(tfm.get.room.playerList) do
  233.         eventNewPlayer(name)
  234.     end
  235.     startGame()
  236. end
  237.  
  238. function eventNewPlayer(name)
  239.     data[name] = {
  240.         name = name,
  241.         timestamp = 0,
  242.         facing = true,
  243.         win_profile = false,
  244.         profileUser = nil,
  245.         profileTab = 1
  246.     }
  247.     playersInRoom = playersInRoom + 1
  248.     for _,k in pairs(keys) do
  249.         tfm_exec_bindKeyboard(name, k, true)
  250.     end
  251.    
  252.     playerData[name] = defaultData()
  253.    
  254.     if gameLoaded and playersInRoom == s_min_players then
  255.         modeEnd()
  256.     end
  257.     outputMsg("<ROSE><b>"..getTrans().welcome.."</b>",name)
  258. end
  259.  
  260. function outputMsg(txt,to)
  261.     ui.addTextArea(600,txt.."<a href='event:petra'><R> [X]",to,400, 25,nil,nil,0x26353d,0x435e6c,0.8,true)
  262. end
  263. function eventPlayerLeft(name)
  264.     playersInRoom = playersInRoom - 1
  265.     data[name] = nil
  266. end
  267.  
  268. function eventPlayerDied(name)
  269.     if gameFinished or not gameLoaded then return end
  270.     miceAlive[name] = nil
  271.     playersAlive = playersAlive - 1
  272.     checkPlayers()
  273.    
  274.     if gameMode == CLASSIC then
  275.         if classic_countdown then
  276.             if name == shaman then
  277.                 classic_winner = 2
  278.             else
  279.                 classic_winner = 1
  280.             end
  281.             modeEnd()
  282.         else
  283.             if name==shaman then
  284.                 classic_winner = 2
  285.                 modeEnd()
  286.             else
  287.                 if playersAlive == 2 and classic_winner == 0 then
  288.                     tfm_exec_setGameTime(20)
  289.                     classic_countdown = true
  290.                    
  291.                     for m in pairs(miceAlive) do
  292.                         if m ~= shaman then
  293.                             classic_rival = m
  294.                             break
  295.                         end
  296.                     end
  297.                     --debugMsg(shaman.." tiene 20 segundos para matar a "..classic_rival)
  298.                     outputMsg("<J>"..string_format(getTrans().countdown,"<CH>"..classic_rival),name)
  299.        
  300.                 end
  301.             end
  302.         end
  303.    
  304.  
  305.        
  306.     elseif gameMode == GHOST then
  307.         if playersAlive == 1 then
  308.             for m in pairs(miceAlive) do
  309.                ghost_winner = m
  310.             end
  311.             modeEnd()
  312.         end
  313.     elseif gameMode == CLICK then
  314.         if click_countdown then
  315.             if name == shaman then
  316.                 click_winner = 2
  317.             else
  318.                 click_winner = 1
  319.             end
  320.             modeEnd()
  321.         else
  322.             if name==shaman then
  323.                 click_winner = 2
  324.                 modeEnd()
  325.             else
  326.                 if playersAlive == 2 and click_winner == 0 then
  327.                     tfm_exec_setGameTime(20)
  328.                     click_countdown = true
  329.                     for m in pairs(miceAlive) do
  330.                         if m ~= shaman then
  331.                             click_rival = m
  332.                             break
  333.                         end
  334.                     end
  335.                     outputMsg("<BL>"..string_format(getTrans().countdown,"<J>"..click_rival),name)
  336.  
  337.        
  338.                 end
  339.             end
  340.         end
  341.    
  342.     end
  343. end
  344.  
  345. function checkPlayers()
  346.     if playersAlive == 0 or playersAlive == 1 and not gameFinished then
  347.         modeEnd()
  348.     end
  349. end
  350.  
  351. function eventPlayerVampire(name)
  352.     if gameFinished then return end
  353.     vampire[name] = true
  354.     miceAlive[name] = nil
  355.     vampire_normalMice = vampire_normalMice - 1
  356.     if vampire_normalMice == 0 then
  357.         modeEnd()
  358.     end    
  359. end
  360.  
  361. function startGame()
  362.     local players_easy = 0
  363.     inEasyMode = {}
  364.     for name in pairs(data) do
  365.         if tfm.get.room.playerList[name] and tfm.get.room.playerList[name].inHardMode == 0 then
  366.             players_easy = players_easy + 1
  367.        end
  368.     end
  369.    
  370.     local mapList
  371.     if players_easy >= s_min_players then
  372.         mapList = maps
  373.     else
  374.         mapList = lobby
  375.     end
  376.    
  377.     local newMap
  378.     repeat
  379.         newMap = math_random(#mapList)
  380.     until newMap ~= currentMap or #mapList == 1
  381.     currentMap = newMap
  382.    
  383.     tfm_exec_newGame(mapList[newMap])
  384. end
  385.  
  386. function checkShamanMode(name)
  387.     if tfm.get.room.playerList[name].inHardMode == 0 then
  388.         --ui_removeTextArea(10, name)
  389.     else
  390.         sendNotification(name, getTrans().hm_header, getTrans().hm_text,"HTX7faD")
  391.         tfm_exec_killPlayer(name)
  392.     end    
  393. end
  394.  
  395.  
  396. function eventNewGame()
  397.     gameLoaded = true
  398.     gameStarted = false
  399.     gameFinished = false
  400.     killed_afk = false
  401.    
  402.     local xml = tfm.get.room.xmlMapInfo.xml
  403.     xmldom = parseXml(xml)
  404.     gameMode = path(xmldom, "P")[1].attribute.olds or 0
  405.     gameMode = gameMode + 0
  406.     tfm_exec_setGameTime(modos[gameMode].time + 8)
  407.    
  408.     outputMsg("<font color='#29c4d9'><b>~ "..modos[gameMode].name.."</b><N> "..getTrans().introduction[gameMode],nil)
  409.    
  410.     playersAlive = playersInRoom
  411.     miceAlive = {}
  412.     mice_afk = {}
  413.     for name in pairs(data) do
  414.         miceAlive[name] = true
  415.         mice_afk[name] = true
  416.         if gameMode ~= 0 then
  417.             sumarStat(name, "rounds", gameMode)            
  418.             tfm_exec_setNameColor(name,"0")
  419.         end
  420.     end
  421.    
  422.     if gameMode == CLASSIC then
  423.        classic_countdown = false
  424.        classic_winner = 0
  425.        classic_rival = ""
  426.        
  427.     elseif gameMode == TEAMS then
  428.         teams_red = {}
  429.         teams_blue = {}
  430.         teams_red_n = 0
  431.         teams_blue_n = 0
  432.         make_teams()
  433.        
  434.     elseif gameMode == RAIN then
  435.         rain_winner = nil
  436.        
  437.     elseif gameMode == ALLSHAMANS then
  438.         shaman = "All"
  439.         allshamans_winner = nil
  440.        
  441.     elseif gameMode == VAMPIRE then
  442.         vampire_winner = nil
  443.         vampire_normalMice = playersAlive
  444.         vampire = {}
  445.    
  446.     elseif gameMode == GHOST then
  447.         ghost_winner = nil
  448.        
  449.     elseif gameMode == CLICK then
  450.         click_countdown = false
  451.         click_winner = 0
  452.         click_rival = ""
  453.     end
  454. end
  455.  
  456. function modeLoop(time,tr)
  457.     if gameMode == RAIN then
  458.         local objects={5,2,6,3,10,17,23,39,40,17}
  459.         for i=1,4 do
  460.             tfm_exec_addShamanObject(objects[math_random(10)],math_random(800), math_random(-400,-100),0,0,math_random(10,30))
  461.         end        
  462.     elseif gameMode == GHOST then
  463.         local x,y
  464.         for i=1,7 do
  465.             x = math_random(0,800)
  466.             y = math_random(0,400)
  467.             tfm_exec_explosion(x, y, 60, 80, false)
  468.             tfm_exec_displayParticle(3,x, y,3,-9,0,1,nil)
  469.         end
  470.     end
  471. end
  472.  
  473. function getShaman()
  474.     local tchaman = {}
  475.     for name, player in pairs(tfm.get.room.playerList) do
  476.         if not player.isDead then
  477.             table_insert (tchaman, {name=name, score=player.score})
  478.         end
  479.     end
  480.     table_sort(tchaman, function (x,y) return x.score > y.score end)
  481.     return tchaman[1].name
  482. end
  483.  
  484. function getVampire()
  485.     local t = {}
  486.     local c = 0
  487.     for name in pairs(miceAlive) do
  488.         c = c + 1
  489.         t[c] = name
  490.     end
  491.     return t[math_random(c)]
  492. end
  493.  
  494. function make_teams()
  495.     local playerList = {}
  496.     local c = 0
  497.     for n in pairs(data) do
  498.         c = c + 1
  499.         playerList[c] = n
  500.     end
  501.    
  502.     local DS = path(xmldom, "Z","D","DS")[1].attribute
  503.     local DC = path(xmldom, "Z","D","DC")[1].attribute
  504.     local red_x,red_y,blue_x,blue_y = DS.X,DS.Y,DC.X,DC.Y
  505.    
  506.     for i=1,c do
  507.         local index = math_random(c)
  508.         local player = playerList[index]
  509.         if i%2==0 then
  510.             teams_red[player] = true
  511.             teams_red_n = teams_red_n + 1
  512.             tfm_exec_setNameColor(player,"0xEB1D51")
  513.             tfm_exec_movePlayer(player, red_x, red_y)
  514.         else                        
  515.             teams_blue[player] = true
  516.             teams_blue_n = teams_blue_n + 1
  517.             tfm_exec_setNameColor(player,"0x2F7FCC")
  518.             tfm_exec_movePlayer(player, blue_x, blue_y)
  519.         end
  520.         table_remove(playerList, index)
  521.         c = c - 1
  522.     end
  523. end
  524.  
  525. function modeStart()
  526.     outputMsg("<J>¡GO!")
  527.     for name in pairs(miceAlive) do
  528.         checkShamanMode(name)
  529.     end
  530.    
  531.     if gameMode == CLASSIC then
  532.         shaman = getShaman()
  533.         tfm_exec_setShaman(shaman)
  534.         outputMsg(string_format(getTrans().is_shaman,"<CH>"..shaman),nil)
  535.        
  536.     elseif gameMode == ALLSHAMANS then
  537.         for p in pairs(data) do                
  538.             tfm_exec_setShaman(p)
  539.         end
  540.        
  541.     elseif gameMode == VAMPIRE then
  542.         local name = getVampire()
  543.         tfm_exec_setVampirePlayer(name)
  544.         outputMsg(string_format(getTrans().is_vampire,"<CH>"..name),nil)
  545.        
  546.      elseif gameMode == CLICK then
  547.         shaman = getShaman()
  548.         getClicker(shaman)
  549.         tfm_exec_setPlayerScore(shaman, 0)
  550.         outputMsg(string_format(getTrans().is_shaman,"<CH>"..shaman),nil)  
  551.     end
  552. end
  553.  
  554. function getClicker(name)
  555.     system.bindMouse(name,true)
  556.     local DC = path(xmldom, "Z","D","DC")[1].attribute  
  557.     local x,y= DC.X,DC.Y
  558.     tfm_exec_setNameColor(name,"0xEB1D51")
  559.     tfm_exec_movePlayer(name, x, y)
  560. end
  561.  
  562. function sendNotification(name,header,text,img)
  563.     ui_addTextArea(10, "<p align='center'><font size='20'><J>"..header.."\n<font size='10'><BL>"..text.."\n\n<R>[<a href='event:close'>CLOSE</a>]", name,250,185,300,95,0x26353d,0x435e6c,nil,true)
  564.     --imageBox_id[name] = tfm_exec_addImage(img..".png","!1", 320, 85,name)
  565. end
  566.  
  567. function sumarStat(name, s, g)
  568.     local p = playerData[name]
  569.     p[s][g] = p[s][g] + 1
  570.     if s == "rounds" then
  571.         checkAch(name)
  572.     elseif not mice_afk[name] then
  573.         local modo = modos[g]
  574.         getExp(name, modo.exp * p.level * 5)
  575.         getMoney(name, modo.money * 5)
  576.     end
  577. end
  578.  
  579. function getMoney(name, money)
  580.     local p = playerData[name]
  581.     p.money = p.money + money
  582.    
  583.     --debugMsg("<CH>"..name.." has obtenido $"..money.." Musudólares. Dinero total: "..p.money,name)
  584. end
  585.  
  586. function getExp(name, earned, money)
  587.     local p,trans = playerData[name],getTrans()
  588.     p.exp = p.exp + earned
  589.    
  590.     local level = p.level
  591.     local exp_req = level*level*25
  592.     if p.level < s_max_level and p.exp >= exp_req then
  593.         level = level + 1
  594.         p.level = level
  595.         p.exp = p.exp - exp_req
  596.         --debugMsg(name.." ha subido al nivel "..level+1)
  597.         outputMsg("<BL>"..string_format(trans.lvl_up,"<J>"..name,level+1), nil)
  598.     end
  599.    
  600.     --debugMsg(name.." ha obtenido "..earned.." puntos de experiencia.\nExperiencia total: "..p.exp..".\nSiguiente nivel:"..level*level*25 - p.exp,name)
  601. end
  602.  
  603. function modeEnd()
  604.     tfm_exec_setGameTime(5)
  605.     gameFinished = true
  606.    
  607.     local T = getTrans()
  608.     if gameMode == CLASSIC then
  609.         ui_removeTextArea(1,nil)
  610.         if classic_winner == 1 then
  611.             --  todos muertos menos el chami
  612.            outputMsg("<J>"..T.shaman_win,nil)
  613.             sumarStat(shaman,"wins", 1)
  614.         else
  615.             if classic_countdown then
  616.                 --  chamán muerto o tiempo, gana el rival
  617.                 --debugMsg(classic_rival.." ha ganado!")
  618.                  outputMsg("<BL>"..string_format(T.win,"<J>"..classic_rival.."<BL>"),nil)
  619.                 sumarStat(classic_rival, "wins", 1)
  620.             else
  621.                 --  chamán muerto o tiempo, los ratones sobrevivientes ganan
  622.                -- debugMsg("¡Los ratones han ganado!")
  623.                outputMsg(T.mice_win,nil)
  624.                 for name in pairs(miceAlive)   do
  625.                     if name~=shaman then
  626.                         sumarStat(name, "wins", 1)
  627.                     end
  628.                 end
  629.             end
  630.         end
  631.        
  632.     elseif gameMode == TEAMS then
  633.         if teams_blue_n == 0 then
  634.             --  rojo gana
  635.             --debugMsg("El <R>equipo rojo <VP>ha ganado")
  636.             outputMsg("<J>"..string_format(T.team_win,'<R>'..T.red.."<J>"),nil)
  637.             for name in pairs(teams_red) do
  638.                 sumarStat(name, "wins", 2)
  639.             end    
  640.         elseif teams_red_n == 0 then
  641.             --  azul gana
  642.            -- debugMsg("El <BV>equipo azul <VP>ha ganado")
  643.            outputMsg("<J>"..string_format(T.team_win,'<BV>'..T.blue..'<J>'),nil)
  644.             for name in pairs(teams_blue) do
  645.                 sumarStat(name, "wins", 2)
  646.             end
  647.         else
  648.             --  tiempo, ninguno gana
  649.             --debugMsg("Ningún equipo ha ganado")
  650.             outputMsg('<J>'..T.no_win,nil)
  651.         end
  652.        
  653.     elseif gameMode == RAIN then        
  654.         if rain_winner then
  655.            --debugMsg(rain_winner.." ganó")
  656.            outputMsg(string_format(T.win,"<J>"..rain_winner.."<BL>"),nil)
  657.            sumarStat(rain_winner, "wins", 3)
  658.         else
  659.             --debugMsg("Nadie ganó :(")
  660.              outputMsg('<J>'..T.no_win,nil)
  661.         end
  662.        
  663.     elseif gameMode == ALLSHAMANS then
  664.         if allshamans_winner then
  665.            -- debugMsg(allshamans_winner.." ganó")
  666.             outputMsg(string_format(T.win,"<J>"..allshamans_winner.."<BL>"),nil)
  667.             sumarStat(allshamans_winner,"wins", 4)
  668.         else
  669.            -- debugMsg("Nadie ganó :(")
  670.             outputMsg('<J>'..T.no_win,nil)
  671.         end
  672.        
  673.     elseif gameMode == VAMPIRE then
  674.         for name in pairs(vampire) do
  675.             tfm_exec_killPlayer(name)
  676.         end
  677.        
  678.         if vampire_normalMice == 0 then
  679.             --  todos convertidos en vampiros o muertos
  680.             --debugMsg("El conde Drekkemaus ha ganado")
  681.             outputMsg("<J>"..T.vampire_win,nil)
  682.              
  683.         elseif vampire_normalMice == 1 then
  684.             --  se acabó el tiempo y 1 jugador sobreviviente
  685.             for name in pairs(miceAlive) do
  686.                 if not vampire[name] then
  687.                     sumarStat(name, "wins", 5)
  688.                     outputMsg(string_format(T.win,"<J>"..name.."<BL>"),nil)
  689.                     break
  690.                 end
  691.             end
  692.         elseif vampire_normalMice > 1 then
  693.             --  se acabó el tiempo y más de 1 jugador sobreviviente
  694.             --debugMsg("¡Los ratones han ganado!")
  695.             outputMsg("<J>"..T.mice_win,nil)
  696.             --local temp = ""
  697.             for name in pairs(miceAlive)   do
  698.                     --temp = temp..name.." "
  699.                     sumarStat(name,"wins", 5)
  700.             end
  701.             --debugMsg("Ganadores: "..temp)
  702.         end
  703.    
  704.     elseif gameMode == GHOST then
  705.          if ghost_winner then
  706.             --debugMsg(ghost_winner.." ganó")
  707.             outputMsg(string_format(T.win,"<J>"..ghost_winner.."<BL>"),nil)
  708.             sumarStat(ghost_winner,"wins", 6)
  709.         else
  710.              outputMsg('<J>'..T.no_win,nil)
  711.         end
  712.        
  713.     elseif gameMode == CLICK then
  714.         ui_removeTextArea(1,nil)
  715.         system.bindMouse(shaman, false)
  716.         if click_winner == 1 then
  717.             --  todos muertos menos el chami
  718.             --debugMsg("El chamán ganó")
  719.             outputMsg('<J>'..T.shaman_win,nil)
  720.             sumarStat(shaman,"wins", 7)
  721.         else
  722.             if click_countdown then
  723.                 --  chamán muerto o tiempo, gana el rival
  724.                -- debugMsg(click_rival.." ha ganado!")
  725.                outputMsg(string_format(T.win,"<J>"..click_rival.."<BL>"),nil)
  726.                 sumarStat(click_rival,"wins", 7)
  727.             else
  728.                 --  chamán muerto o tiempo, los ratones sobrevivientes ganan
  729.                 --debugMsg("¡Los ratones han ganado!")
  730.                 outputMsg('<J>'..T.mice_win,nil)
  731.                -- local temp = ""
  732.                 for name in pairs(miceAlive) do
  733.                     if name~=shaman then
  734.                       --  temp = temp..name.." "
  735.                         sumarStat(name,"wins", 7)
  736.                     end
  737.                 end
  738.                 --debugMsg("Ganadores: "..temp)
  739.             end
  740.         end
  741.     end
  742.    
  743.     if gameMode ~= LOBBY then
  744.         for name in pairs(data) do
  745.             if not mice_afk[name] then
  746.                 local modo = modos[gameMode]
  747.                 getExp(name, modo.exp * playerData[name].level)
  748.                 getMoney(name, modo.money)
  749.             end    
  750.             if miceAlive[name] then
  751.                 tfm_exec_killPlayer(name)
  752.             end            
  753.         end
  754.     end
  755. end
  756.  
  757. function eventLoop(time,tr)
  758.     if not gameLoaded then return end
  759.     if not gameStarted then
  760.         if time > 8000 then
  761.             gameStarted = true
  762.             modeStart()
  763.         end
  764.         return
  765.     end
  766.    
  767.     if not killed_afk and time >= 30000 then
  768.         for n in pairs(mice_afk) do
  769.             tfm_exec_killPlayer(n)
  770.             killed_afk = true
  771.             --debugMsg(n.." está en modo AFK")
  772.         end
  773.     end
  774.    
  775.     modeLoop(time,tr)
  776.    
  777.     if not gameFinished and tr <= 0 then
  778.         modeEnd()
  779.     elseif gameFinished and tr <=0 then
  780.         startGame()
  781.     end
  782. end
  783.  
  784. function eventKeyboard(name, key, down, x, y)
  785.     if key == 23492 then
  786.         --  ayuda
  787.     elseif miceAlive[name] then
  788.         if mice_afk[name] then mice_afk[name] = nil end
  789.         if gameMode == CLICK or gameMode == TEAMS and not gameFinished then
  790.             if key == 37 or key == 64 or key == 81 then
  791.                 data[name].facing=false
  792.                 return
  793.             elseif key == 39 or key == 68 then
  794.                 data[name].facing=true
  795.                 return
  796.             end
  797.             if gameMode == TEAMS and gameStarted then
  798.                 if (key == 32 or key == 40 or key == 83)  then
  799.                     if data[name].timestamp < os.time() - 1500 then
  800.                         local id
  801.                         if data[name].facing then        
  802.                             id = tfm_exec_addShamanObject(17,x+10,y-15,90)
  803.                         else
  804.                             id = tfm_exec_addShamanObject(17,x-10,y+15,-90)
  805.                         end
  806.                         data[name].timestamp = os.time()
  807.                     end
  808.                 end
  809.             end
  810.         end
  811.     end
  812. end
  813.  
  814. function eventMouse(name, mx, my)  
  815.     if gameMode == CLICK and name == shaman then
  816.         if mice_afk[name] then mice_afk[name] = nil end
  817.         if data[name].timestamp < os.time() - 1500 then
  818.         local id
  819.         if data[name].facing then        
  820.             id = tfm_exec_addShamanObject(17,mx,my,90)
  821.         else
  822.             id = tfm_exec_addShamanObject(17,mx,my,-90)
  823.         end
  824.         data[name].timestamp = os.time()   
  825.         end
  826.     end
  827. end
  828.  
  829. function eventChatCommand(name, com)
  830.     if com:sub(1,7) == "profile" then
  831.         local n = com:sub(9)
  832.         n = data[n] and n or name
  833.         showProfile(name, n)
  834.        
  835.     elseif com:sub(1,5) == "stats" then
  836.         local n = com:sub(7)
  837.         n = data[n] and n or name
  838.        
  839.         local t,p = n.."\n",playerData[n]
  840.         local r,w = p.rounds,p.wins
  841.         for i = 1,7 do
  842.             t=t..modos[i].name.." - rounds: "..r[i].." wins: "..w[i].."\n"
  843.         end
  844.         debugMsg(t)
  845.        
  846.     elseif com:sub(1,6) == "logros" then
  847.         local n = com:sub(8)
  848.         n = data[n] and n or name
  849.        
  850.         local t,p = "Logros de "..n.."\n",playerData[n]
  851.         local l = p.logros
  852.         for i = 1,7 do
  853.             li = l[i]
  854.             t=t..modos[i].name.." - logros ("..li.."): "
  855.             for j = 1,li do
  856.                 t=t..getTrans().logros[i][j]..", "
  857.             end
  858.             t=t.."\n"
  859.         end
  860.         debugMsg("<BL>"..t.."</BL>")
  861.     end
  862. end
  863.  
  864. function eventTextAreaCallback(id, name, cb)
  865.     if id == 10 then
  866.         ui_removeTextArea(10,name)
  867.         if imageBox_id[name] then
  868.             tfm_exec_removeImage(imageBox_id[name],name)
  869.         end
  870.        
  871.     elseif id == 12 then
  872.         local m = data[name]
  873.         if m.win_profile then
  874.             m.win_profile = false
  875.            
  876.             for i=1,22 do
  877.                 ui_removeTextArea(i, name)
  878.             end
  879.         end
  880.    
  881. elseif cb:find("changeProfileTab") then
  882.         if cb:sub(17) then
  883.             id = cb:sub(17)
  884.         end    
  885.         data[name].profileTab = id - 20
  886.         updateProfile(name, data[name].profileUser)
  887.      
  888.     end
  889. end
  890.  
  891. --  name:   nombre del usuario cuyo perfil se muestra
  892. --  target: nombre del usuario al que se le mostrará la ventana
  893. function showProfile(target, name)
  894.     local T = getTrans()
  895.     local m = data[target]
  896.     local p = playerData[name]
  897.    
  898.     m.win_profile = true
  899.     m.profileUser = name
  900.     m.profileTab = 1
  901.    
  902.     ui_addTextArea(11,"",target,230,110,300,270,0x26353d,0x26353d,nil,true);
  903.     ui_addTextArea(13,"<p align='center'><font size='20' face='Arial Black'><CH>"..name,target,210,60,350,40,0x3a4e61,0x26353d,nil,true)
  904.     ui_addTextArea(22,"<p align='center'><N><a href='event:changeProfileTab'><b>Achiev</b></a></p>",target,230,70,nil,16,0x26353d,0x26353d,nil,true)
  905.     --ui_addTextArea(23,"<p align='center'><N><a href='event:changeProfileTab'><b>Modes</b></a></p>",p,550,160,nil,16,0x26353d,0x26353d,nil,true)
  906.     ui_addTextArea(12, "<p align='center'><R><a href='event:close'><b>☓</b></p>",target,530,70,nil,16,0x26353d,0x26353d,nil,true)
  907.    
  908.     updateProfile(target, name)
  909. end
  910.  
  911. function updateProfile(target, name)
  912.     local T = getTrans()
  913.     local m = data[target]
  914.     local p = playerData[name]
  915.     local txt,data,id = "Main page"
  916.    
  917.     if m.profileTab == 2 then
  918.         data,id = achievements(name,1,20), 21
  919.     elseif m.profileTab == 3 then
  920.         data,id = "Modos", 21
  921.     else
  922.         local r,w,wins,rounds= p.rounds,p.wins,0,0
  923.         for i = 1,7 do
  924.             wins= wins + w[i]
  925.             rounds = rounds + r[i]
  926.         end
  927.         mort = rounds - wins
  928.         data = string.format("<p align='center'></p><font size='13'><N>• Nivel:<J> %d</font><G>  <BL><font size='13'><N>\n<BL>• Leaderboard: <J>%s <BL>[%s]</font></BL>\n\n<N>Estadísticas generales\n<BL>• Triunfos: <J>%d<BL>\n• Derrotas: <J>%d\n\n",p.level,"No ranking","No ranking",wins,mort)
  929.         txt = "Achiev"
  930.         id = 22
  931.  
  932. end
  933.     ui_updateTextArea(22,"<p align='center'><N><a href='event:changeProfileTab"..id.."'><b>"..txt.."</b></a></p>",target)
  934.     ui_updateTextArea(11,data,target)
  935. end    
  936.  
  937. function checkAch(name)
  938.     local g,logros = gameMode,playerData[name].logros
  939.     for i=logros[g]+1,#_unlock[g] do
  940.         if playerData[name].rounds[g] >= _unlock[g][i] then
  941.             logros[g] =  logros[g] + 1
  942.             sendNotification(name, getTrans().logros[g][logros[g]], getTrans().ach_unlocked, "HTX7faD")
  943.         end
  944.     end
  945. end
  946.  
  947. function achievements(name,n1,n2)
  948.     local t,logros,achText = "",playerData[name].logros,getTrans().logros
  949.     for i=1,7 do
  950.         for a=n1,n2 do
  951.             if logros[i] >= a then
  952.                 t = t..achText[i][a].." \n"
  953.             end
  954.         end
  955.     end
  956.     return t
  957. end
  958.  
  959. function defaultData()
  960.     local d = {
  961.         level = 100,
  962.         exp = 0,
  963.         money = 0,
  964.         a_shop = 1,
  965.         logros = {},
  966.         rounds = {},
  967.         wins = {},
  968.         shop = {}
  969.     }
  970.     for i=1,7 do
  971.         d.logros[i] = 0
  972.         d.rounds[i] = 0
  973.         d.wins[i] = 0
  974.     end
  975.     d.shop[0] = true
  976.     for i=1,42 do
  977.         d.shop[i] = false
  978.     end
  979.     return d
  980. end
  981.  
  982. local statGroup = {"rounds","wins","logros"}
  983. local statGroup_size = {3,3,1}
  984.  
  985.  
  986.  
  987. function string_replace(s, i, j, t)
  988.     return s:sub(1,i-1)..t..s:sub(j+1)
  989. end
  990.  
  991.  
  992.  
  993. function getTrans()
  994.    return text[tfm_get_room_community] or text['es']
  995. end
  996.  
  997. function debugMsg(msg,target)
  998.     outputMsg("<VP>"..msg, target)
  999.     if target then
  1000.         sendNotification(name,msg,"","HTX7faD")
  1001.     end
  1002. end
  1003.  
  1004. --  Makinit's xml library
  1005. do
  1006.     local namePattern = "[%a_:][%w%.%-_:]*"
  1007.     function parseXml(xml)
  1008.         local root = {}
  1009.         local parents = {}
  1010.         local element = root
  1011.         for closing, name, attributes, empty, text in string_gmatch(xml, "<(/?)(" .. namePattern .. ")(.-)(/?)>%s*([^<]*)%s*") do
  1012.              if closing == "/" then
  1013.                 local parent = parents[element]
  1014.                 if parent and name == element.name then
  1015.                     element = parent
  1016.                 end
  1017.                    
  1018.             else
  1019.                 if name ~= "L" then
  1020.                     local child = {name = name, attribute = {}}
  1021.                     table_insert(element, child)
  1022.                     parents[child] = element
  1023.                     if empty ~= "/" then
  1024.                         element = child
  1025.                     end
  1026.                     for name, value in string_gmatch(attributes, "(" .. namePattern .. ")%s*=%s*\"(.-)\"") do
  1027.                         child.attribute[name] = value
  1028.                     end
  1029.                 end
  1030.             end
  1031.             if text ~= "" then
  1032.                 local child = {text = text}
  1033.                 table_insert(element, child)
  1034.                 parents[child] = element
  1035.             end
  1036.         end
  1037.         return root[1]
  1038.     end
  1039.  
  1040.     function path(nodes, ...)
  1041.         nodes = {nodes}
  1042.         for i, name in ipairs(arg) do
  1043.             local match = {}
  1044.             for i, node in ipairs(nodes) do
  1045.                 for i, child in ipairs(node) do
  1046.                     if child.name == name then
  1047.                         table_insert(match, child)
  1048.                     end
  1049.                 end
  1050.             end
  1051.             nodes = match
  1052.         end
  1053.         return nodes
  1054.     end
  1055. end
  1056.  
  1057. loadGame()
  1058.  
  1059.  
  1060.  
  1061. -- MUSUGAS AND HINAKAGIYAMA
Advertisement
Add Comment
Please, Sign In to add comment