Advertisement
Eliaseeg

OldSurvivor Last release

Mar 29th, 2015 (edited)
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 44.45 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.     system.loadPlayerData(name)
  254.    
  255.     if gameLoaded and playersInRoom == s_min_players then
  256.         modeEnd()
  257.     end
  258.     tfm_exec_chatMessage("<ROSE><b>"..getTrans().welcome.."</b>",name)
  259. end
  260.  
  261. function eventPlayerLeft(name)
  262.     playersInRoom = playersInRoom - 1
  263.     data[name] = nil
  264. end
  265.  
  266. function eventPlayerDied(name)
  267.     if gameFinished or not gameLoaded then return end
  268.     miceAlive[name] = nil
  269.     playersAlive = playersAlive - 1
  270.     checkPlayers()
  271.    
  272.     if gameMode == CLASSIC then
  273.         if classic_countdown then
  274.             if name == shaman then
  275.                 classic_winner = 2
  276.             else
  277.                 classic_winner = 1
  278.             end
  279.             modeEnd()
  280.         else
  281.             if name==shaman then
  282.                 classic_winner = 2
  283.                 modeEnd()
  284.             else
  285.                 if playersAlive == 2 and classic_winner == 0 then
  286.                     tfm_exec_setGameTime(20)
  287.                     classic_countdown = true
  288.                    
  289.                     for m in pairs(miceAlive) do
  290.                         if m ~= shaman then
  291.                             classic_rival = m
  292.                             break
  293.                         end
  294.                     end
  295.                     --debugMsg(shaman.." tiene 20 segundos para matar a "..classic_rival)
  296.                     tfm_exec_chatMessage("<J>"..string_format(getTrans().countdown,"<CH>"..classic_rival),name)
  297.        
  298.                 end
  299.             end
  300.         end
  301.    
  302.  
  303.        
  304.     elseif gameMode == GHOST then
  305.         if playersAlive == 1 then
  306.             for m in pairs(miceAlive) do
  307.                ghost_winner = m
  308.             end
  309.             modeEnd()
  310.         end
  311.     elseif gameMode == CLICK then
  312.         if click_countdown then
  313.             if name == shaman then
  314.                 click_winner = 2
  315.             else
  316.                 click_winner = 1
  317.             end
  318.             modeEnd()
  319.         else
  320.             if name==shaman then
  321.                 click_winner = 2
  322.                 modeEnd()
  323.             else
  324.                 if playersAlive == 2 and click_winner == 0 then
  325.                     tfm_exec_setGameTime(20)
  326.                     click_countdown = true
  327.                     for m in pairs(miceAlive) do
  328.                         if m ~= shaman then
  329.                             click_rival = m
  330.                             break
  331.                         end
  332.                     end
  333.                     tfm_exec_chatMessage("<BL>"..string_format(getTrans().countdown,"<J>"..click_rival),name)
  334.  
  335.        
  336.                 end
  337.             end
  338.         end
  339.    
  340.     end
  341. end
  342.  
  343. function checkPlayers()
  344.     if playersAlive == 0 and not gameFinished then
  345.         modeEnd()
  346.     end
  347. end
  348.  
  349. function eventPlayerVampire(name)
  350.     if gameFinished then return end
  351.     vampire[name] = true
  352.     miceAlive[name] = nil
  353.     vampire_normalMice = vampire_normalMice - 1
  354.     if vampire_normalMice == 0 then
  355.         modeEnd()
  356.     end    
  357. end
  358.  
  359. function startGame()
  360.     local players_easy = 0
  361.     inEasyMode = {}
  362.     for name in pairs(data) do
  363.         if tfm.get.room.playerList[name] and tfm.get.room.playerList[name].inHardMode == 0 then
  364.             players_easy = players_easy + 1
  365.        end
  366.     end
  367.    
  368.     local mapList
  369.     if players_easy >= s_min_players then
  370.         mapList = maps
  371.     else
  372.         mapList = lobby
  373.     end
  374.    
  375.     local newMap
  376.     repeat
  377.         newMap = math_random(#mapList)
  378.     until newMap ~= currentMap or #mapList == 1
  379.     currentMap = newMap
  380.    
  381.     tfm_exec_newGame(mapList[newMap])
  382. end
  383.  
  384. function checkShamanMode(name)
  385.     if tfm.get.room.playerList[name].inHardMode == 0 then
  386.         --ui_removeTextArea(10, name)
  387.     else
  388.         sendNotification(name, getTrans().hm_header, getTrans().hm_text,"HTX7faD")
  389.         tfm_exec_killPlayer(name)
  390.     end    
  391. end
  392.  
  393.  
  394. function eventNewGame()
  395.     gameLoaded = true
  396.     gameStarted = false
  397.     gameFinished = false
  398.     killed_afk = false
  399.    
  400.     local xml = tfm.get.room.xmlMapInfo.xml
  401.     xmldom = parseXml(xml)
  402.     gameMode = path(xmldom, "P")[1].attribute.olds or 0
  403.     gameMode = gameMode + 0
  404.     tfm_exec_setGameTime(modos[gameMode].time + 8)
  405.    
  406.     tfm_exec_chatMessage("<font color='#29c4d9'><b>~ "..modos[gameMode].name.."</b><N> "..getTrans().introduction[gameMode],nil)
  407.    
  408.     playersAlive = playersInRoom
  409.     miceAlive = {}
  410.     mice_afk = {}
  411.     for name in pairs(data) do
  412.         miceAlive[name] = true
  413.         mice_afk[name] = true
  414.         if gameMode ~= 0 then
  415.             sumarStat(name, "rounds", gameMode)
  416.             saveData(name)
  417.             tfm_exec_setNameColor(name,"0")
  418.         end
  419.     end
  420.    
  421.     if gameMode == CLASSIC then
  422.        classic_countdown = false
  423.        classic_winner = 0
  424.        classic_rival = ""
  425.        
  426.     elseif gameMode == TEAMS then
  427.         teams_red = {}
  428.         teams_blue = {}
  429.         teams_red_n = 0
  430.         teams_blue_n = 0
  431.         make_teams()
  432.        
  433.     elseif gameMode == RAIN then
  434.         rain_winner = nil
  435.        
  436.     elseif gameMode == ALLSHAMANS then
  437.         shaman = "All"
  438.         allshamans_winner = nil
  439.        
  440.     elseif gameMode == VAMPIRE then
  441.         vampire_winner = nil
  442.         vampire_normalMice = playersAlive
  443.         vampire = {}
  444.    
  445.     elseif gameMode == GHOST then
  446.         ghost_winner = nil
  447.        
  448.     elseif gameMode == CLICK then
  449.         click_countdown = false
  450.         click_winner = 0
  451.         click_rival = ""
  452.     end
  453. end
  454.  
  455. function modeLoop(time,tr)
  456.     if gameMode == RAIN then
  457.         local objects={5,2,6,3,10,17,23,39,40,17}
  458.         for i=1,4 do
  459.             tfm_exec_addShamanObject(objects[math_random(10)],math_random(800), math_random(-400,-100),0,0,math_random(10,30))
  460.         end        
  461.     elseif gameMode == GHOST then
  462.         local x,y
  463.         for i=1,7 do
  464.             x = math_random(0,800)
  465.             y = math_random(0,400)
  466.             tfm_exec_explosion(x, y, 60, 80, false)
  467.             tfm_exec_displayParticle(3,x, y,3,-9,0,1,nil)
  468.         end
  469.     end
  470. end
  471.  
  472. function getShaman()
  473.     local tchaman = {}
  474.     for name, player in pairs(tfm.get.room.playerList) do
  475.         if not player.isDead then
  476.             table_insert (tchaman, {name=name, score=player.score})
  477.         end
  478.     end
  479.     table_sort(tchaman, function (x,y) return x.score > y.score end)
  480.     return tchaman[1].name
  481. end
  482.  
  483. function getVampire()
  484.     local t = {}
  485.     local c = 0
  486.     for name in pairs(miceAlive) do
  487.         c = c + 1
  488.         t[c] = name
  489.     end
  490.     return t[math_random(c)]
  491. end
  492.  
  493. function make_teams()
  494.     local playerList = {}
  495.     local c = 0
  496.     for n in pairs(data) do
  497.         c = c + 1
  498.         playerList[c] = n
  499.     end
  500.    
  501.     local DS = path(xmldom, "Z","D","DS")[1].attribute
  502.     local DC = path(xmldom, "Z","D","DC")[1].attribute
  503.     local red_x,red_y,blue_x,blue_y = DS.X,DS.Y,DC.X,DC.Y
  504.    
  505.     for i=1,c do
  506.         local index = math_random(c)
  507.         local player = playerList[index]
  508.         if i%2==0 then
  509.             teams_red[player] = true
  510.             teams_red_n = teams_red_n + 1
  511.             tfm_exec_setNameColor(player,"0xEB1D51")
  512.             tfm_exec_movePlayer(player, red_x, red_y)
  513.         else                        
  514.             teams_blue[player] = true
  515.             teams_blue_n = teams_blue_n + 1
  516.             tfm_exec_setNameColor(player,"0x2F7FCC")
  517.             tfm_exec_movePlayer(player, blue_x, blue_y)
  518.         end
  519.         table_remove(playerList, index)
  520.         c = c - 1
  521.     end
  522. end
  523.  
  524. function modeStart()
  525.     tfm_exec_chatMessage("<J>¡GO!")
  526.     for name in pairs(miceAlive) do
  527.         checkShamanMode(name)
  528.     end
  529.    
  530.     if gameMode == CLASSIC then
  531.         shaman = getShaman()
  532.         tfm_exec_setShaman(shaman)
  533.         tfm_exec_chatMessage(string_format(getTrans().is_shaman,"<CH>"..shaman),nil)
  534.        
  535.     elseif gameMode == ALLSHAMANS then
  536.         for p in pairs(data) do                
  537.             tfm_exec_setShaman(p)
  538.         end
  539.        
  540.     elseif gameMode == VAMPIRE then
  541.         local name = getVampire()
  542.         tfm_exec_setVampirePlayer(name)
  543.         tfm_exec_chatMessage(string_format(getTrans().is_vampire,"<CH>"..name),nil)
  544.        
  545.      elseif gameMode == CLICK then
  546.         shaman = getShaman()
  547.         getClicker(shaman)
  548.         tfm_exec_setPlayerScore(shaman, 0)
  549.         tfm_exec_chatMessage(string_format(getTrans().is_shaman,"<CH>"..shaman),nil)  
  550.     end
  551. end
  552.  
  553. function getClicker(name)
  554.     system.bindMouse(name,true)
  555.     local DC = path(xmldom, "Z","D","DC")[1].attribute  
  556.     local x,y= DC.X,DC.Y
  557.     tfm_exec_setNameColor(name,"0xEB1D51")
  558.     tfm_exec_movePlayer(name, x, y)
  559. end
  560.  
  561. function sendNotification(name,header,text,img)
  562.     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)
  563.     imageBox_id[name] = tfm_exec_addImage(img..".png","!1", 320, 85,name)
  564. end
  565.  
  566. function sumarStat(name, s, g)
  567.     local p = playerData[name]
  568.     p[s][g] = p[s][g] + 1
  569.     if s == "rounds" then
  570.         checkAch(name)
  571.     elseif not mice_afk[name] then
  572.         local modo = modos[g]
  573.         getExp(name, modo.exp * p.level * 5)
  574.         getMoney(name, modo.money * 5)
  575.     end
  576. end
  577.  
  578. function getMoney(name, money)
  579.     local p = playerData[name]
  580.     p.money = p.money + money
  581.    
  582.     --debugMsg("<CH>"..name.." has obtenido $"..money.." Musudólares. Dinero total: "..p.money,name)
  583. end
  584.  
  585. function getExp(name, earned, money)
  586.     local p,trans = playerData[name],getTrans()
  587.     p.exp = p.exp + earned
  588.    
  589.     local level = p.level
  590.     local exp_req = level*level*25
  591.     if p.level < s_max_level and p.exp >= exp_req then
  592.         level = level + 1
  593.         p.level = level
  594.         p.exp = p.exp - exp_req
  595.         --debugMsg(name.." ha subido al nivel "..level+1)
  596.         tfm_exec_chatMessage("<BL>"..string_format(trans.lvl_up,"<J>"..name,level+1), nil)
  597.     end
  598.    
  599.     --debugMsg(name.." ha obtenido "..earned.." puntos de experiencia.\nExperiencia total: "..p.exp..".\nSiguiente nivel:"..level*level*25 - p.exp,name)
  600. end
  601.  
  602. function modeEnd()
  603.     tfm_exec_setGameTime(5)
  604.     gameFinished = true
  605.    
  606.     local T = getTrans()
  607.     if gameMode == CLASSIC then
  608.         ui_removeTextArea(1,nil)
  609.         if classic_winner == 1 then
  610.             --  todos muertos menos el chami
  611.            tfm_exec_chatMessage("<J>"..T.shaman_win,nil)
  612.             sumarStat(shaman,"wins", 1)
  613.         else
  614.             if classic_countdown then
  615.                 --  chamán muerto o tiempo, gana el rival
  616.                 --debugMsg(classic_rival.." ha ganado!")
  617.                  tfm_exec_chatMessage("<BL>"..string_format(T.win,"<J>"..classic_rival.."<BL>"),nil)
  618.                 sumarStat(classic_rival, "wins", 1)
  619.             else
  620.                 --  chamán muerto o tiempo, los ratones sobrevivientes ganan
  621.                -- debugMsg("¡Los ratones han ganado!")
  622.                tfm_exec_chatMessage(T.mice_win,nil)
  623.                 for name in pairs(miceAlive)   do
  624.                     if name~=shaman then
  625.                         sumarStat(name, "wins", 1)
  626.                     end
  627.                 end
  628.             end
  629.         end
  630.        
  631.     elseif gameMode == TEAMS then
  632.         if teams_blue_n == 0 then
  633.             --  rojo gana
  634.             --debugMsg("El <R>equipo rojo <VP>ha ganado")
  635.             tfm_exec_chatMessage("<J>"..string_format(T.team_win,'<R>'..T.red.."<J>"),nil)
  636.             for name in pairs(teams_red) do
  637.                 sumarStat(name, "wins", 2)
  638.             end    
  639.         elseif teams_red_n == 0 then
  640.             --  azul gana
  641.            -- debugMsg("El <BV>equipo azul <VP>ha ganado")
  642.            tfm_exec_chatMessage("<J>"..string_format(T.team_win,'<BV>'..T.blue..'<J>'),nil)
  643.             for name in pairs(teams_blue) do
  644.                 sumarStat(name, "wins", 2)
  645.             end
  646.         else
  647.             --  tiempo, ninguno gana
  648.             --debugMsg("Ningún equipo ha ganado")
  649.             tfm_exec_chatMessage('<J>'..T.no_win,nil)
  650.         end
  651.        
  652.     elseif gameMode == RAIN then        
  653.         if rain_winner then
  654.            --debugMsg(rain_winner.." ganó")
  655.            tfm_exec_chatMessage(string_format(T.win,"<J>"..rain_winner.."<BL>"),nil)
  656.            sumarStat(rain_winner, "wins", 3)
  657.         else
  658.             --debugMsg("Nadie ganó :(")
  659.              tfm_exec_chatMessage('<J>'..T.no_win,nil)
  660.         end
  661.        
  662.     elseif gameMode == ALLSHAMANS then
  663.         if allshamans_winner then
  664.            -- debugMsg(allshamans_winner.." ganó")
  665.             tfm_exec_chatMessage(string_format(T.win,"<J>"..allshamans_winner.."<BL>"),nil)
  666.             sumarStat(allshamans_winner,"wins", 4)
  667.         else
  668.            -- debugMsg("Nadie ganó :(")
  669.             tfm_exec_chatMessage('<J>'..T.no_win,nil)
  670.         end
  671.        
  672.     elseif gameMode == VAMPIRE then
  673.         for name in pairs(vampire) do
  674.             tfm_exec_killPlayer(name)
  675.         end
  676.        
  677.         if vampire_normalMice == 0 then
  678.             --  todos convertidos en vampiros o muertos
  679.             --debugMsg("El conde Drekkemaus ha ganado")
  680.             tfm_exec_chatMessage("<J>"..T.vampire_win,nil)
  681.              
  682.         elseif vampire_normalMice == 1 then
  683.             --  se acabó el tiempo y 1 jugador sobreviviente
  684.             for name in pairs(miceAlive) do
  685.                 if not vampire[name] then
  686.                     sumarStat(name, "wins", 5)
  687.                     tfm_exec_chatMessage(string_format(T.win,"<J>"..name.."<BL>"),nil)
  688.                     break
  689.                 end
  690.             end
  691.         elseif vampire_normalMice > 1 then
  692.             --  se acabó el tiempo y más de 1 jugador sobreviviente
  693.             --debugMsg("¡Los ratones han ganado!")
  694.             tfm_exec_chatMessage("<J>"..T.mice_win,nil)
  695.             --local temp = ""
  696.             for name in pairs(miceAlive)   do
  697.                     --temp = temp..name.." "
  698.                     sumarStat(name,"wins", 5)
  699.             end
  700.             --debugMsg("Ganadores: "..temp)
  701.         end
  702.    
  703.     elseif gameMode == GHOST then
  704.          if ghost_winner then
  705.             --debugMsg(ghost_winner.." ganó")
  706.             tfm_exec_chatMessage(string_format(T.win,"<J>"..ghost_winner.."<BL>"),nil)
  707.             sumarStat(ghost_winner,"wins", 6)
  708.         else
  709.              tfm_exec_chatMessage('<J>'..T.no_win,nil)
  710.         end
  711.        
  712.     elseif gameMode == CLICK then
  713.         ui_removeTextArea(1,nil)
  714.         system.bindMouse(shaman, false)
  715.         if click_winner == 1 then
  716.             --  todos muertos menos el chami
  717.             --debugMsg("El chamán ganó")
  718.             tfm_exec_chatMessage('<J>'..T.shaman_win,nil)
  719.             sumarStat(shaman,"wins", 7)
  720.         else
  721.             if click_countdown then
  722.                 --  chamán muerto o tiempo, gana el rival
  723.                -- debugMsg(click_rival.." ha ganado!")
  724.                tfm_exec_chatMessage(string_format(T.win,"<J>"..click_rival.."<BL>"),nil)
  725.                 sumarStat(click_rival,"wins", 7)
  726.             else
  727.                 --  chamán muerto o tiempo, los ratones sobrevivientes ganan
  728.                 --debugMsg("¡Los ratones han ganado!")
  729.                 tfm_exec_chatMessage('<J>'..T.mice_win,nil)
  730.                -- local temp = ""
  731.                 for name in pairs(miceAlive) do
  732.                     if name~=shaman then
  733.                       --  temp = temp..name.." "
  734.                         sumarStat(name,"wins", 7)
  735.                     end
  736.                 end
  737.                 --debugMsg("Ganadores: "..temp)
  738.             end
  739.         end
  740.     end
  741.    
  742.     if gameMode ~= LOBBY then
  743.         for name in pairs(data) do
  744.             if not mice_afk[name] then
  745.                 local modo = modos[gameMode]
  746.                 getExp(name, modo.exp * playerData[name].level)
  747.                 getMoney(name, modo.money)
  748.             end    
  749.             if miceAlive[name] then
  750.                 tfm_exec_killPlayer(name)
  751.             end
  752.             saveData(name)
  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 = 1,
  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. function dataToFile(d)
  986.     local f,l,n = "",4
  987.     for i=1,stats_n do
  988.         n = stats_size[i]
  989.         f=f..numberToBytes(d[stats_name[i]], n)
  990.         l = l + n
  991.     end
  992.     for i=1,3 do
  993.         for j=1,7 do
  994.             f=f..numberToBytes(d[statGroup[i]][j], statGroup_size[i])
  995.             l = l + statGroup_size[i]
  996.         end
  997.     end
  998.     for i=1,5 do
  999.         local chunk = 0
  1000.         for j=1,7 do
  1001.             local k = (i-1)*7 + j
  1002.             local c = d.shop[k] and 1 or 0
  1003.             chunk = chunk + 2^(j-1) * c
  1004.         end
  1005.         f=f..numberToBytes(chunk,1)
  1006.         l = l + 1
  1007.     end
  1008.     f = numberToBytes(l, 2)..numberToBytes(game_id, 1)..numberToBytes(game_data_version, 1)..f
  1009.     return f,l
  1010. end
  1011.  
  1012. function fileToData(f)
  1013.     local d,s,l,n = {},5,bytesToNumber(f:sub(1,2))
  1014.     for i=1,stats_n do
  1015.         n = stats_size[i]
  1016.         d[stats_name[i]] = bytesToNumber(f:sub(s,s+n-1))
  1017.         s = s + n
  1018.     end
  1019.     for i=1,3 do
  1020.         d[statGroup[i]] = {}
  1021.         for j=1,7 do
  1022.             n = statGroup_size[i]
  1023.             d[statGroup[i]][j] = bytesToNumber(f:sub(s,s+n-1))
  1024.             s = s + n
  1025.         end
  1026.     end
  1027.     d.shop = {[0]=true}
  1028.     for i=1,5 do
  1029.         local chunk = bytesToNumber(f:sub(s,s))
  1030.         for j=1,7 do
  1031.             local r = chunk % 2
  1032.             local k = (i-1)*7 + j
  1033.             d.shop[k] = r
  1034.             chunk = (chunk - r)/2
  1035.         end
  1036.         s = s + 1
  1037.     end
  1038.     return d
  1039. end
  1040.  
  1041. function fileToData_v2(f)
  1042.     local d,s,l,n = {},5,bytesToNumber(f:sub(1,2))
  1043.     for i=1,stats_n do
  1044.         n = stats_size[i]
  1045.         d[stats_name[i]] = bytesToNumber(f:sub(s,s+n-1))
  1046.         s = s + n
  1047.     end
  1048.     for i=1,3 do
  1049.         d[statGroup[i]] = {}
  1050.         for j=1,7 do
  1051.             n = statGroup_size[i]
  1052.             d[statGroup[i]][j] = bytesToNumber(f:sub(s,s+n-1))
  1053.             s = s + n
  1054.         end
  1055.     end
  1056.     d.shop = {[0]=true}
  1057.     for i=1,5 do
  1058.         local chunk = bytesToNumber(f:sub(s,s))
  1059.         for j=1,7 do
  1060.             local r = chunk % 2
  1061.             local k = (i-1)*7 + j
  1062.             d.shop[k] = r
  1063.             chunk = (chunk - r)/2
  1064.         end
  1065.         s = s + 1
  1066.     end
  1067.     d[1] = false
  1068.     return d
  1069. end
  1070.  
  1071. function fileToData_v1(f)
  1072.     local d,s,l,n = defaultData(),5,bytesToNumber(f:sub(1,2))
  1073.     for i=1,stats_n do
  1074.         n = stats_size[i]
  1075.         d[stats_name[i]] = bytesToNumber(f:sub(s,s+n-1))
  1076.         s = s + n
  1077.     end
  1078.     for i=1,3 do
  1079.         d[statGroup[i]] = {}
  1080.         for j=1,7 do
  1081.             n = statGroup_size[i]
  1082.             d[statGroup[i]][j] = bytesToNumber(f:sub(s,s+n-1))
  1083.             s = s + n
  1084.         end
  1085.     end
  1086.     return d
  1087. end
  1088.  
  1089. function eventPlayerDataLoaded(name, file)
  1090.     local header,s,l,z,game_found,f,id,pfile = file:sub(1,8),9,0,file:len()
  1091.    
  1092.     if header == data_header then
  1093.         while s <= z do
  1094.             l = bytesToNumber(file:sub(s,s+1))
  1095.             id = bytesToNumber(file:sub(s+2,s+2))
  1096.             if id == game_id then
  1097.                 game_found = true
  1098.                 break
  1099.             end
  1100.             s = s+l
  1101.         end
  1102.     else
  1103.         file = data_header
  1104.     end
  1105.    
  1106.     if game_found then
  1107.         f = file:sub(s,s+l-1)
  1108.         local v = bytesToNumber(f:sub(4,4))
  1109.         if v == game_data_version then
  1110.             playerData[name] = fileToData(f)
  1111.             --debugMsg(name.." <BL> - Datos cargados ")
  1112.         else
  1113.             --  version migration
  1114.             -------------------------------------------------
  1115.             if v == 1 then
  1116.                 --debugMsg(name.." <BL> - Versión antigua, actualizando datos")
  1117.                 d = fileToData_v1(f)
  1118.             else
  1119.                 debugMsg(name.." <BL> - Versión muy antigua, reiniciando datos")
  1120.                 local d = defaultData()
  1121.             end
  1122.             -------------------------------------------------
  1123.            
  1124.             playerData[name] = d
  1125.             local old_l = l
  1126.             f,l = dataToFile(d)
  1127.             file = string_replace(file, s, s+old_l-1, f)
  1128.             system.savePlayerData(name, file)
  1129.         end
  1130.     else
  1131.         f,l = dataToFile(playerData[name])
  1132.         file = file..f
  1133.         system.savePlayerData(name, file)
  1134.         debugMsg(name.." <BL> - Datos creados con tamaño: "..l)
  1135.     end
  1136.    
  1137.     pfile = {file=file, start=s, lenght=l}
  1138.     playerFile[name] = pfile
  1139. end
  1140.  
  1141. function saveData(name)
  1142.     local pfile = playerFile[name]
  1143.     if not pfile then return end
  1144.     local f = dataToFile(playerData[name])
  1145.     pfile.file = string_replace(pfile.file, pfile.start, pfile.start + pfile.lenght - 1, f)
  1146.     system.savePlayerData(name, pfile.file)
  1147. end
  1148.  
  1149. function string_replace(s, i, j, t)
  1150.     return s:sub(1,i-1)..t..s:sub(j+1)
  1151. end
  1152.  
  1153. function bytesToNumber(s)
  1154.     local n = 0
  1155.     local l = string.len(s)
  1156.     for i = 1, l do
  1157.         n = n + (string.byte(s, i) % 128) * 128 ^ (l - i)
  1158.     end
  1159.     return n
  1160. end
  1161.  
  1162. function numberToBytes(n, l)
  1163.     n = math.floor(math.abs(n))
  1164.     l = l or 1
  1165.     local s = ""
  1166.     for i = 1, l do
  1167.         local e = 128 ^ (l - i)
  1168.         local p = math.floor(n / e)
  1169.         s = s .. string.char(p)
  1170.         n = n - p * e
  1171.     end
  1172.     return s
  1173. end
  1174.  
  1175. function getTrans()
  1176.    return text[tfm_get_room_community] or text['es']
  1177. end
  1178.  
  1179. function debugMsg(msg,target)
  1180.     tfm_exec_chatMessage("<VP>"..msg, target)
  1181.     if target then
  1182.         sendNotification(name,msg,"","HTX7faD")
  1183.     end
  1184. end
  1185.  
  1186. --  Makinit's xml library
  1187. do
  1188.     local namePattern = "[%a_:][%w%.%-_:]*"
  1189.     function parseXml(xml)
  1190.         local root = {}
  1191.         local parents = {}
  1192.         local element = root
  1193.         for closing, name, attributes, empty, text in string_gmatch(xml, "<(/?)(" .. namePattern .. ")(.-)(/?)>%s*([^<]*)%s*") do
  1194.              if closing == "/" then
  1195.                 local parent = parents[element]
  1196.                 if parent and name == element.name then
  1197.                     element = parent
  1198.                 end
  1199.                    
  1200.             else
  1201.                 if name ~= "L" then
  1202.                     local child = {name = name, attribute = {}}
  1203.                     table_insert(element, child)
  1204.                     parents[child] = element
  1205.                     if empty ~= "/" then
  1206.                         element = child
  1207.                     end
  1208.                     for name, value in string_gmatch(attributes, "(" .. namePattern .. ")%s*=%s*\"(.-)\"") do
  1209.                         child.attribute[name] = value
  1210.                     end
  1211.                 end
  1212.             end
  1213.             if text ~= "" then
  1214.                 local child = {text = text}
  1215.                 table_insert(element, child)
  1216.                 parents[child] = element
  1217.             end
  1218.         end
  1219.         return root[1]
  1220.     end
  1221.  
  1222.     function path(nodes, ...)
  1223.         nodes = {nodes}
  1224.         for i, name in ipairs(arg) do
  1225.             local match = {}
  1226.             for i, node in ipairs(nodes) do
  1227.                 for i, child in ipairs(node) do
  1228.                     if child.name == name then
  1229.                         table_insert(match, child)
  1230.                     end
  1231.                 end
  1232.             end
  1233.             nodes = match
  1234.         end
  1235.         return nodes
  1236.     end
  1237. end
  1238.  
  1239. loadGame()
  1240.  
  1241.  
  1242.  
  1243.  
  1244. --[[
  1245. args_game = {"name","timestamp"}
  1246.  
  1247. function copy.table(tbl,to,arg)
  1248.     to[arg] = {}
  1249.     for i=1,#args_game do
  1250.          to[args][i] = tbl[arg][i]
  1251.          debugMsg("[Copia] Se ha copiado a la tabla "..tbl[arg].name.." el valor de "..tbl[arg][i].." Correspondiente al valor "..args_game[i])
  1252.     end
  1253. end  
  1254.  
  1255. function table.copy(t, d)
  1256.     d = d or false
  1257.     local t2 = {}
  1258.     for k, v in pairs(t) do
  1259.         if d then
  1260.             if type(k) == "table" then
  1261.                 k = table.copy(k, true)
  1262.             end
  1263.             if type(v) == "table" then
  1264.                 v = table.copy(v, true)
  1265.             end
  1266.         end
  1267.         t2[k] = v
  1268.     end
  1269.     return t2
  1270. end
  1271.  
  1272. playerData.logros = {3,1,4,2,2,0,1}
  1273. playerData.wins = {0,0,0,0,0,0,0}
  1274. playerData.rounds = {0,0,0,0,0,0,0}
  1275. playerData.money = 0
  1276. playerData.level = 1
  1277. playerData.exp = 0
  1278. playerData.shop = {true,false,false...}
  1279.  
  1280.  
  1281. ]]
  1282.  
  1283. --[[
  1284. bit = Unidad de memoria que almacena datos en caracteres
  1285.  
  1286.     1 byte  128
  1287.     2 bytes 128*128-1 = 16383
  1288.     3 bytes 128^3 - 1 = 2097151
  1289.    
  1290.     stats por minijuego:
  1291.         rondas      3 bytes     max 2097151
  1292.         victorias   3 bytes     max 2097151
  1293.         total       6 bytes
  1294.        
  1295.     * 7 minijuegos  42 bytes
  1296.     logros          7 bytes     max 127 logros por juego
  1297.     nivel           1 byte
  1298.     exp             3 bytes
  1299.     dinero          2 byte
  1300.     tienda actual   1 byte
  1301.     tienda          2 bytes
  1302.    
  1303.     total           58 bytes
  1304.    
  1305.    
  1306.    
  1307.     46 ---> "n"
  1308.     "n___________________________________"
  1309.    
  1310.    
  1311. ]]
  1312.  
  1313. --[[^ este ratón tendría:
  1314.         los 3 primeros títulos classic
  1315.         1 título en teams
  1316.         4 títulos en rain
  1317.         2 en allshamans
  1318.         etc
  1319. ]]
  1320. --[[
  1321. logros = {"Iniciado","Sobreviviente","Cañón","Hábil","Ratón de acero","I am Legend","Maestro del Cañón","Ratón clásico","Ratón antiguo","Viejos tiempos","Chamán antiguo","Caballero clásico","En equipos","Azul - Rojo","Karma","¡Ganamos Equipo!","Maestro del aire","Camper","Iluminado","Granja de ovejas","Manzana *-*","Tormeeenta","Huracán","Anti-Gravedad","Chamán","Chamán múltiple","Chamán sagrado","Chamán Honorable","Maestro chamán","Guerrero","Condenado","Dracula","Ataque zombie","Anti Cristo","Epidemia","Rey vampiro","Guesped demoniaco","Caza-fantasma","¡Qué susto!","I'm top 1"};   
  1322.  
  1323. local titles_all = {
  1324.         ["None"]= {2,3,4,5,6,7};
  1325.         ["Clasic"]={8,9,10,11,12};
  1326.         ["Teams"]={13,14,15,16,17};
  1327.         ["Rain"]={18,19,20,21,22,13,24};
  1328.         ["Allshamans"]={25,26,27,28,29,30};
  1329.         ["Ghost"]={38,39};
  1330.         ["Vampire"]={31,32,33,34,35,36,37};    
  1331. }
  1332. local titles_dictionary = {
  1333.     ["None"] = {1,5,20,35,60,100};
  1334.     ["Clasic"] = {1,5,10,30,60};
  1335.     ["Teams"] = {1,6,20,50,110};
  1336.     ["Rain"] = {1,4,15,35,70,80,99};
  1337.     ["Allshamans"] = {1,5,10,20,52,60};
  1338.     ["Ghost"]={2,10};
  1339.     ["Vampire"] = {1,5,15,26,45,35,60};
  1340.    
  1341. }
  1342.  
  1343. function getUTitle(p,t,m)  
  1344.     mode = modos[tonumber(m)].name
  1345.     datas = data[p][mode]
  1346.     a = titles_all[modos[tonumber(m)].name]
  1347.     asd = data[p]
  1348.     for i,uloe in ipairs(titles_dictionary["None"]) do 
  1349.         if asd.total == uloe then              
  1350.             desbtitle(p,titles_all["None"][data[p].ntitles],"All")
  1351.             asd.ntitles = asd.total + 1
  1352.         end
  1353.     end
  1354.     for i,ulo in ipairs(titles_dictionary[modos[tonumber(current_mode_number)].name]) do   
  1355.         if asd[modos[m].name][1] == ulo then
  1356.             desbtitle(p,titles_all[modos[tonumber(m)].name][datas[4]]--[[,modos[tonumber(m)].name)
  1357.             asd[modos[m].name][4] = asd[modos[m].name][1] + 1
  1358.         end
  1359.     end
  1360. end
  1361. data[name].titles = {true}for i=2,#texts[data[name].cmm].titles do data[name].titles[i]=false; end
  1362.  
  1363.  
  1364. exp = 4350 * n
  1365. exp = 160*n
  1366. nivel   exp para subir al siguiente
  1367.  
  1368. 1       4350        160
  1369. 2       4350*2
  1370. 3       4350*3
  1371.  
  1372. 99      430650
  1373. 100     435000      16000
  1374.  
  1375.  
  1376. exp = 100 * (n^2)/2
  1377.  
  1378. 1   100
  1379. 2   200
  1380. 3   450
  1381.  
  1382. 100 500.000
  1383.  
  1384. ===============================
  1385. exp = 100 * (n^2)/4
  1386. = (n^2) * 25
  1387.  
  1388. n   exp req.    ronda   win     victorias para next level
  1389.                 6*n     30*n
  1390. --------------------------------------------------
  1391. 1   25          6       30      0.6
  1392. 2   100         12      60      1.25
  1393. 3   225         18      90     1.875
  1394. 4   400         24      120
  1395. 5   625         30      150     3
  1396. 6   900         36      180
  1397. 7   1225        42      210
  1398. 8   1600        48      240
  1399. 9   2025        54      270
  1400. 10  2500        60      300     6
  1401. 20  10000       120     600
  1402. 30  22500       180     900
  1403. 40  40000       240     1200
  1404. 50  62500       300     1500
  1405. 60  90000       360     1800    
  1406. 70  122500      420     2100    58,33333333333333
  1407. 80  160000      480     2400    66,66666666666667
  1408. 90  202500      540     2700    75
  1409. 99  245025      594     2970    82,5
  1410.  
  1411. 100 250.000    
  1412. 119 354025      714     3570    99,16666666666667
  1413. 120 :) propro friki sin vida
  1414. ===============================
  1415.  
  1416.  
  1417.     1 byte  128
  1418.     2 bytes 128*128-1 = 16383
  1419.     3 bytes 128^3 - 1 = 2097151
  1420.    
  1421.    
  1422.     local canons = {
  1423.     [0] = {
  1424.         name = "";
  1425.         img = "";
  1426.         }, 
  1427.         {name = "Default cannon";img = "g9zpdwV";price = 0;}
  1428.     }
  1429.    
  1430. function getShop(x,y,a,name)
  1431.     for x,y in pairs(data[name].images) do
  1432.         tfm.exec.removeImage(y)    
  1433.     end
  1434.     local x_c,y_c,a_c = 0,160,320
  1435.     texta(851,"<p align='center'><font size='30' face='Soopafresh'><CH>Shop",name,120,40,530,50,0x26353d,0x26353d,nil,true);
  1436.     texta(852,"",name,150,90,150,250,0x3a4e61,0x2a3c45,nil,true)
  1437.     texta(853,"",name,470,90,150,250,0x3a4e61,0x2a3c45,nil,true)
  1438.     texta(854,"",name,310,90,150,250,0x3a4e61,0x2a3c45,nil,true)
  1439.        
  1440.     if canons[x] then
  1441.         get_shop_date(855,x,150,200,190,90,140,115,name)
  1442.     end
  1443.     if canons[y] then
  1444.         get_shop_date(858,y,150+y_c,200+y_c,190+y_c,90,140,115,name)
  1445.     end
  1446.     if canons[a] then
  1447.         get_shop_date(861,a,150+a_c,200+a_c,190+a_c,90,140,115,name)
  1448.     end
  1449.     if canons[x+3] then
  1450.         get_shop_date(864,x+3,150+x_c,200+x_c,190+x_c,210,260,235,name)    
  1451.     end
  1452.     if canons[y+3] then
  1453.         get_shop_date(867,y+3,150+y_c,200+y_c,190+y_c,210,260,235,name)    
  1454.     end
  1455.     if canons[a+3] then
  1456.         get_shop_date(890,a+3,150+a_c,200+a_c,190+a_c,210,260,235,name)
  1457.     end
  1458.     texta(893,"",name,120,340,530,50,0x26353d,0x26353d,nil,true);
  1459.     texta(894,"<p align='center'><J>Equiped: <BL>"..canons[data[name].shop].name.."</p>",name,120,365,nil,16,0x26353d,0x26353d,nil,true);
  1460.     texta(895,"<p align='center'><J><a href='event:prevshop'><B>←</B> <G>(Prev)</p>",name,330,365,nil,16,0x26353d,0x26353d,nil,true);
  1461.     texta(896,"<p align='center'><G><a href='event:nextshop'>(Next) <J><B>→</B></a></p>",name,400,365,nil,16,0x26353d,0x26353d,nil,true);
  1462.     texta(897,"<BL>Money: <J>§"..data[name].money.."",name,550,365,nil,16,0x26353d,0x3a4e61,nil,true);
  1463.     texta(898,"<p align='center'><R><a href='event:closeshop'><b>☓</b></a> <G>(Close)</p>",name,580,50,nil,16,0x26353d,0x26353d,nil,true);
  1464. end
  1465.  
  1466. function get_shop_date(aid,id,x1,x2,x3,y1,y2,y3,name)
  1467.     texta(aid,"<p align='center'><FONT SIZE='10' color='#26353d'><B>"..canons[id].name,name,x1,y1,150,nil,'0x' .. shop_have(id,name),0x26353d,nil,true);
  1468.     texta(aid+1,"<p align='center'><font size='20'><J>",name,x2,y2,40,40,'0x' .. shop_have(id,name),0x26353d,0.2,true);
  1469.     texta(aid+2,"<p align='center'><font size='10' color='#000000'><a href='event:getSe"..id .."'>"..shop_have(id,name,'1'),name,x3,y3,60,nil,'0x' .. shop_have(id,name),0x26353d,0.5,true);
  1470.     id = tfm.exec.addImage(canons[id].img..".png", "&1", x2, y2-5, name)
  1471.     table.insert(data[name].images,id)
  1472. end
  1473.  
  1474. function shop_have(n,p,a)
  1475.     t="Buy %s"
  1476.     l = ''
  1477.     if  tonumber(data[p].money) >= tonumber(canons[n].price) and not table.find(data[p].shops,n) then  
  1478.         l = '★'
  1479.     end
  1480.     if a == nil then
  1481.         if n == data[p].shop then
  1482.             args = '7fe8ad'
  1483.         elseif table.find(data[p].shops,n) then
  1484.             args= "cdd408"
  1485.         elseif  tonumber(data[p].money) >= tonumber(canons[n].price) and not table.find(data[p].shops,n) then
  1486.             args= "78caf0"     
  1487.             l = '•'
  1488.         else
  1489.             args = 'f2536d'        
  1490.         end    
  1491.     elseif a then
  1492.         if n == data[p].shop then
  1493.             args = 'Unequip'
  1494.         elseif table.find(data[p].shops,n) then
  1495.             args= "Equip"
  1496.         else           
  1497.             args = l..string.format(t,canons[n].price)
  1498.         end
  1499.     end
  1500.     return args
  1501. end
  1502.  
  1503. function table.find(tbl, element)
  1504.   if type(tbl) == "table" then
  1505.     for x, y in pairs(tbl) do if element == y then return true end end
  1506.     return false
  1507.   end
  1508. end
  1509.  
  1510. ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement