Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- OldSurvivor #2
- --[[ ID list
- textArea
- 1 debug(?) classic
- 10 notifications - cerrar (hardmode, achievements)
- 11 perfil - ventana principal
- 12 perfil - cerrar
- 21+ perfil - pestañas
- popUp
- ]]
- do
- function flattenFunctionTree(tree, path)
- for name, value in pairs(tree) do
- if type(value) == "table" then
- flattenFunctionTree(value, path .. name .. "_")
- elseif type(value) == "function" then
- _G[path .. name] = value
- end
- end
- end
- local temp = {}
- for name, value in pairs(_G) do
- if value ~= _G then
- temp[name] = value
- end
- end
- flattenFunctionTree(temp, "")
- end
- local game_name = "new old new old new survivor"
- local game_owner = "Musugas"
- local game_id = 101
- local game_data_version = 3
- local data_header = "PATO0003"
- local stats_name = {"level","exp","money","a_shop"}
- local stats_size = {1,3,3,1}
- local stats_n = 4
- local playerData = {}
- local playerFile = {}
- -- settings
- local s_min_players = 3
- local s_max_level = 100
- local imgs = {
- logo = "";
- logros = {},
- win ="",
- no_shamanModes="",
- windows = {"","",""}, -- Shop, Ranking, Logros
- profile = {} -- Random imgs
- }
- local _unlock = {
- {1,3,5,10,20,40},
- {1,2},
- {1,2},
- {1},
- {1},
- {1},
- {1}
- }
- local text = {
- es = {
- logros = {
- {"Ratón Clásico","a2","a3","a4","a5","a6"},
- {"En equipos","Patata"},
- {"Granja de ovejas","Ponquesito"},
- {"Chamán unitario"},
- {"Conde Drekkemaus"},
- {"Caza fantasmas"},
- {"Cursor"}
- },
- welcome = "Bienvenido a #OldSurvivor. Estamos en fase de pruebas, todo lo hecho, será borrado despues.",
- ach_unlocked = "Nuevo logro desbloqueado",
- hm_header = "Desactiva Hard Mode o Divine Mode para jugar",
- hm_text = "Al hacerlo, reaparecerás",
- lvl_up = "%s <BL>ha subido al nivel %d",
- team_win = "El equipo %s ha ganado",
- shaman_win = "¡El chamán ha ganado!",
- mice_win = "¡Los ratones han ganado!",
- no_win = "Nadie ganó :[",
- countdown = "<BL>El chamán tiene 20 segundos para matar a %s",
- is_shaman = "%s <BL>es ahora el chamán ¡Cuidado!",
- is_vampire = "%s es ahora Drekkemaus",
- blue = "Azul",
- red = "Rojo",
- win = "%s ha ganado",
- vampire_win = "Los sirvientes del conde Drekkemaus, han ganado",
- introduction = {
- [0] = "Se necesitan 3 ratones para jugar",
- "Sobrevive al ataque del todopoderoso chamán",
- "¡Derrota al otro equipo!",
- "Abre el paraguas, y cubrete de la lluvia de objetos",
- "Derrota a los demás chamanes",
- "Muerde a los demás",
- "¡BUU! Cuidado con los fantasmas",
- "El mundo informatico le dió el poder del Mouse a un raton"
- }
- },
- en = {
- logros = {
- {"Ratón Clásico","a2","a3","a4","a5","a6"},
- {"En equipos","Patata"},
- {"Granja de ovejas","Ponquesito"},
- {"Chamán unitario"},
- {"Conde Drekkemaus"},
- {"Caza fantasmas"},
- {"Cursor"}
- },
- welcome = "Welcome to #OldSurvivor. We are in testings, everything done, will be deleted later.",
- ach_unlocked = "New achievement unlocked",
- hm_header = "Disable Hard Mode or Divine Mode to play",
- hm_text = "Once disabled, you'll reappear",
- lvl_up = "%s is now level %d",
- team_win = "%s team has won",
- shaman_win = "The Shaman has won!",
- mice_win = "The mice have won!",
- no_win = "No contest :[",
- countdown = "The Shaman's got 20 seconds to kill %s",
- is_shaman = "%s is now the Shaman. Watch out!",
- is_vampire = "%s is now Drekkemaus",
- blue = "Blue",
- red = "Red",
- win = "%s has won",
- vampire_win = "Count Drekkemaus' servants have won",
- introduction = {
- [0] = "3 mice are needed in order to play",
- "Survive the attack of the almighty Shaman",
- "Defeat the other team!",
- "Open the umbrella, and cover yourself from the rain of objects",
- "Defeat the other shamans",
- "Bite the other mice",
- "BOO! Watch out for the ghosts",
- "Computer science gave a mouse the power of the Click"
- }
- }
- }
- -- const
- local LOBBY,CLASSIC,TEAMS,RAIN,ALLSHAMANS,VAMPIRE,GHOST,CLICK = 0,1,2,3,4,5,6,7
- -- datos
- --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}
- local maps = {5355152,5445280,5346896,5393409,5445181,5445572,5445400}
- local lobby = {5468613,5468613}
- --local maps = {5355152,5355152} --CLASSIC
- --local maps = {5445280,5445280} --TEAMS
- --local maps = {5346896,5346896} --RAIN
- --local maps = {5393409,5393409} --AllSHAMANS
- --local maps = {5445181,5445181} --VAMPIRE
- --local maps = 55445262,5445262} --GHOST
- --local maps = {5445572,5445572} -- Ghost ~viprin
- --local maps = {5445400,5445400} -- Clicker
- local keys = {37,64,81,39,68,32,40,83}
- local _modos = {
- {"Lobby",30,0,0},
- {"Classic",120,30,10},
- {"Teams",130,30,10},
- {"Rain",60,25,10},
- {"Allshamans",130,35,20},
- {"Vampire",120,35,20},
- {"Ghost",60,25,10},
- {"Click",130,30,20},
- }
- local modos = {}
- 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
- -- variables del juego
- local playersInRoom = 0
- local playersAlive = 99
- local shaman
- local vampire = {}
- local miceAlive = {}
- local currentMap
- local gameMode
- local gameLoaded
- local gameStarted
- local gameFinished
- local blue = {}
- local red = {}
- local startMode = false
- local xmldom
- local data = {}
- local imageBox_id = {}
- local inEasyMode = {}
- local mice_afk = {}
- local killed_afk
- -- variables específicas de minijuegos
- -- classic
- local classic_countdown
- local classic_winner
- local classic_rival
- -- teams
- local teams_red = {}
- local teams_blue = {}
- local teams_blue_n = 0
- local teams_red_n = 0
- -- rain
- local rain_winner
- -- allshamans
- local allshamans_winner
- -- vampire
- local vampire_winner
- local vampire_normalMice
- -- ghost
- local ghost_winner
- -- click
- local click_countdown
- local click_winner
- local click_rival
- function loadGame()
- tfm.exec.disableAutoNewGame(true)
- tfm.exec.disableAutoTimeLeft(true)
- tfm.exec.disableAllShamanSkills(true)
- tfm.exec.disableAutoShaman (true)
- tfm.exec.disableAutoTimeLeft (true)
- math_randomseed(os.time())
- for _,com in ipairs({"comando","comandu"}) do
- system_disableChatCommandDisplay(com, true)
- end
- for name in pairs(tfm.get.room.playerList) do
- eventNewPlayer(name)
- end
- startGame()
- end
- function eventNewPlayer(name)
- data[name] = {
- name = name,
- timestamp = 0,
- facing = true,
- win_profile = false,
- profileUser = nil,
- profileTab = 1
- }
- playersInRoom = playersInRoom + 1
- for _,k in pairs(keys) do
- tfm_exec_bindKeyboard(name, k, true)
- end
- playerData[name] = defaultData()
- system.loadPlayerData(name)
- if gameLoaded and playersInRoom == s_min_players then
- modeEnd()
- end
- tfm_exec_chatMessage("<ROSE><b>"..getTrans().welcome.."</b>",name)
- end
- function eventPlayerLeft(name)
- playersInRoom = playersInRoom - 1
- data[name] = nil
- end
- function eventPlayerDied(name)
- if gameFinished or not gameLoaded then return end
- miceAlive[name] = nil
- playersAlive = playersAlive - 1
- checkPlayers()
- if gameMode == CLASSIC then
- if classic_countdown then
- if name == shaman then
- classic_winner = 2
- else
- classic_winner = 1
- end
- modeEnd()
- else
- if name==shaman then
- classic_winner = 2
- modeEnd()
- else
- if playersAlive == 2 and classic_winner == 0 then
- tfm_exec_setGameTime(20)
- classic_countdown = true
- for m in pairs(miceAlive) do
- if m ~= shaman then
- classic_rival = m
- break
- end
- end
- --debugMsg(shaman.." tiene 20 segundos para matar a "..classic_rival)
- tfm_exec_chatMessage("<J>"..string_format(getTrans().countdown,"<CH>"..classic_rival),name)
- end
- end
- end
- elseif gameMode == GHOST then
- if playersAlive == 1 then
- for m in pairs(miceAlive) do
- ghost_winner = m
- end
- modeEnd()
- end
- elseif gameMode == CLICK then
- if click_countdown then
- if name == shaman then
- click_winner = 2
- else
- click_winner = 1
- end
- modeEnd()
- else
- if name==shaman then
- click_winner = 2
- modeEnd()
- else
- if playersAlive == 2 and click_winner == 0 then
- tfm_exec_setGameTime(20)
- click_countdown = true
- for m in pairs(miceAlive) do
- if m ~= shaman then
- click_rival = m
- break
- end
- end
- tfm_exec_chatMessage("<BL>"..string_format(getTrans().countdown,"<J>"..click_rival),name)
- end
- end
- end
- end
- end
- function checkPlayers()
- if playersAlive == 0 and not gameFinished then
- modeEnd()
- end
- end
- function eventPlayerVampire(name)
- if gameFinished then return end
- vampire[name] = true
- miceAlive[name] = nil
- vampire_normalMice = vampire_normalMice - 1
- if vampire_normalMice == 0 then
- modeEnd()
- end
- end
- function startGame()
- local players_easy = 0
- inEasyMode = {}
- for name in pairs(data) do
- if tfm.get.room.playerList[name] and tfm.get.room.playerList[name].inHardMode == 0 then
- players_easy = players_easy + 1
- end
- end
- local mapList
- if players_easy >= s_min_players then
- mapList = maps
- else
- mapList = lobby
- end
- local newMap
- repeat
- newMap = math_random(#mapList)
- until newMap ~= currentMap or #mapList == 1
- currentMap = newMap
- tfm_exec_newGame(mapList[newMap])
- end
- function checkShamanMode(name)
- if tfm.get.room.playerList[name].inHardMode == 0 then
- --ui_removeTextArea(10, name)
- else
- sendNotification(name, getTrans().hm_header, getTrans().hm_text,"HTX7faD")
- tfm_exec_killPlayer(name)
- end
- end
- function eventNewGame()
- gameLoaded = true
- gameStarted = false
- gameFinished = false
- killed_afk = false
- local xml = tfm.get.room.xmlMapInfo.xml
- xmldom = parseXml(xml)
- gameMode = path(xmldom, "P")[1].attribute.olds or 0
- gameMode = gameMode + 0
- tfm_exec_setGameTime(modos[gameMode].time + 8)
- tfm_exec_chatMessage("<font color='#29c4d9'><b>~ "..modos[gameMode].name.."</b><N> "..getTrans().introduction[gameMode],nil)
- playersAlive = playersInRoom
- miceAlive = {}
- mice_afk = {}
- for name in pairs(data) do
- miceAlive[name] = true
- mice_afk[name] = true
- if gameMode ~= 0 then
- sumarStat(name, "rounds", gameMode)
- saveData(name)
- tfm_exec_setNameColor(name,"0")
- end
- end
- if gameMode == CLASSIC then
- classic_countdown = false
- classic_winner = 0
- classic_rival = ""
- elseif gameMode == TEAMS then
- teams_red = {}
- teams_blue = {}
- teams_red_n = 0
- teams_blue_n = 0
- make_teams()
- elseif gameMode == RAIN then
- rain_winner = nil
- elseif gameMode == ALLSHAMANS then
- shaman = "All"
- allshamans_winner = nil
- elseif gameMode == VAMPIRE then
- vampire_winner = nil
- vampire_normalMice = playersAlive
- vampire = {}
- elseif gameMode == GHOST then
- ghost_winner = nil
- elseif gameMode == CLICK then
- click_countdown = false
- click_winner = 0
- click_rival = ""
- end
- end
- function modeLoop(time,tr)
- if gameMode == RAIN then
- local objects={5,2,6,3,10,17,23,39,40,17}
- for i=1,4 do
- tfm_exec_addShamanObject(objects[math_random(10)],math_random(800), math_random(-400,-100),0,0,math_random(10,30))
- end
- elseif gameMode == GHOST then
- local x,y
- for i=1,7 do
- x = math_random(0,800)
- y = math_random(0,400)
- tfm_exec_explosion(x, y, 60, 80, false)
- tfm_exec_displayParticle(3,x, y,3,-9,0,1,nil)
- end
- end
- end
- function getShaman()
- local tchaman = {}
- for name, player in pairs(tfm.get.room.playerList) do
- if not player.isDead then
- table_insert (tchaman, {name=name, score=player.score})
- end
- end
- table_sort(tchaman, function (x,y) return x.score > y.score end)
- return tchaman[1].name
- end
- function getVampire()
- local t = {}
- local c = 0
- for name in pairs(miceAlive) do
- c = c + 1
- t[c] = name
- end
- return t[math_random(c)]
- end
- function make_teams()
- local playerList = {}
- local c = 0
- for n in pairs(data) do
- c = c + 1
- playerList[c] = n
- end
- local DS = path(xmldom, "Z","D","DS")[1].attribute
- local DC = path(xmldom, "Z","D","DC")[1].attribute
- local red_x,red_y,blue_x,blue_y = DS.X,DS.Y,DC.X,DC.Y
- for i=1,c do
- local index = math_random(c)
- local player = playerList[index]
- if i%2==0 then
- teams_red[player] = true
- teams_red_n = teams_red_n + 1
- tfm_exec_setNameColor(player,"0xEB1D51")
- tfm_exec_movePlayer(player, red_x, red_y)
- else
- teams_blue[player] = true
- teams_blue_n = teams_blue_n + 1
- tfm_exec_setNameColor(player,"0x2F7FCC")
- tfm_exec_movePlayer(player, blue_x, blue_y)
- end
- table_remove(playerList, index)
- c = c - 1
- end
- end
- function modeStart()
- tfm_exec_chatMessage("<J>¡GO!")
- for name in pairs(miceAlive) do
- checkShamanMode(name)
- end
- if gameMode == CLASSIC then
- shaman = getShaman()
- tfm_exec_setShaman(shaman)
- tfm_exec_chatMessage(string_format(getTrans().is_shaman,"<CH>"..shaman),nil)
- elseif gameMode == ALLSHAMANS then
- for p in pairs(data) do
- tfm_exec_setShaman(p)
- end
- elseif gameMode == VAMPIRE then
- local name = getVampire()
- tfm_exec_setVampirePlayer(name)
- tfm_exec_chatMessage(string_format(getTrans().is_vampire,"<CH>"..name),nil)
- elseif gameMode == CLICK then
- shaman = getShaman()
- getClicker(shaman)
- tfm_exec_setPlayerScore(shaman, 0)
- tfm_exec_chatMessage(string_format(getTrans().is_shaman,"<CH>"..shaman),nil)
- end
- end
- function getClicker(name)
- system.bindMouse(name,true)
- local DC = path(xmldom, "Z","D","DC")[1].attribute
- local x,y= DC.X,DC.Y
- tfm_exec_setNameColor(name,"0xEB1D51")
- tfm_exec_movePlayer(name, x, y)
- end
- function sendNotification(name,header,text,img)
- 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)
- imageBox_id[name] = tfm_exec_addImage(img..".png","!1", 320, 85,name)
- end
- function sumarStat(name, s, g)
- local p = playerData[name]
- p[s][g] = p[s][g] + 1
- if s == "rounds" then
- checkAch(name)
- elseif not mice_afk[name] then
- local modo = modos[g]
- getExp(name, modo.exp * p.level * 5)
- getMoney(name, modo.money * 5)
- end
- end
- function getMoney(name, money)
- local p = playerData[name]
- p.money = p.money + money
- --debugMsg("<CH>"..name.." has obtenido $"..money.." Musudólares. Dinero total: "..p.money,name)
- end
- function getExp(name, earned, money)
- local p,trans = playerData[name],getTrans()
- p.exp = p.exp + earned
- local level = p.level
- local exp_req = level*level*25
- if p.level < s_max_level and p.exp >= exp_req then
- level = level + 1
- p.level = level
- p.exp = p.exp - exp_req
- --debugMsg(name.." ha subido al nivel "..level+1)
- tfm_exec_chatMessage("<BL>"..string_format(trans.lvl_up,"<J>"..name,level+1), nil)
- end
- --debugMsg(name.." ha obtenido "..earned.." puntos de experiencia.\nExperiencia total: "..p.exp..".\nSiguiente nivel:"..level*level*25 - p.exp,name)
- end
- function modeEnd()
- tfm_exec_setGameTime(5)
- gameFinished = true
- local T = getTrans()
- if gameMode == CLASSIC then
- ui_removeTextArea(1,nil)
- if classic_winner == 1 then
- -- todos muertos menos el chami
- tfm_exec_chatMessage("<J>"..T.shaman_win,nil)
- sumarStat(shaman,"wins", 1)
- else
- if classic_countdown then
- -- chamán muerto o tiempo, gana el rival
- --debugMsg(classic_rival.." ha ganado!")
- tfm_exec_chatMessage("<BL>"..string_format(T.win,"<J>"..classic_rival.."<BL>"),nil)
- sumarStat(classic_rival, "wins", 1)
- else
- -- chamán muerto o tiempo, los ratones sobrevivientes ganan
- -- debugMsg("¡Los ratones han ganado!")
- tfm_exec_chatMessage(T.mice_win,nil)
- for name in pairs(miceAlive) do
- if name~=shaman then
- sumarStat(name, "wins", 1)
- end
- end
- end
- end
- elseif gameMode == TEAMS then
- if teams_blue_n == 0 then
- -- rojo gana
- --debugMsg("El <R>equipo rojo <VP>ha ganado")
- tfm_exec_chatMessage("<J>"..string_format(T.team_win,'<R>'..T.red.."<J>"),nil)
- for name in pairs(teams_red) do
- sumarStat(name, "wins", 2)
- end
- elseif teams_red_n == 0 then
- -- azul gana
- -- debugMsg("El <BV>equipo azul <VP>ha ganado")
- tfm_exec_chatMessage("<J>"..string_format(T.team_win,'<BV>'..T.blue..'<J>'),nil)
- for name in pairs(teams_blue) do
- sumarStat(name, "wins", 2)
- end
- else
- -- tiempo, ninguno gana
- --debugMsg("Ningún equipo ha ganado")
- tfm_exec_chatMessage('<J>'..T.no_win,nil)
- end
- elseif gameMode == RAIN then
- if rain_winner then
- --debugMsg(rain_winner.." ganó")
- tfm_exec_chatMessage(string_format(T.win,"<J>"..rain_winner.."<BL>"),nil)
- sumarStat(rain_winner, "wins", 3)
- else
- --debugMsg("Nadie ganó :(")
- tfm_exec_chatMessage('<J>'..T.no_win,nil)
- end
- elseif gameMode == ALLSHAMANS then
- if allshamans_winner then
- -- debugMsg(allshamans_winner.." ganó")
- tfm_exec_chatMessage(string_format(T.win,"<J>"..allshamans_winner.."<BL>"),nil)
- sumarStat(allshamans_winner,"wins", 4)
- else
- -- debugMsg("Nadie ganó :(")
- tfm_exec_chatMessage('<J>'..T.no_win,nil)
- end
- elseif gameMode == VAMPIRE then
- for name in pairs(vampire) do
- tfm_exec_killPlayer(name)
- end
- if vampire_normalMice == 0 then
- -- todos convertidos en vampiros o muertos
- --debugMsg("El conde Drekkemaus ha ganado")
- tfm_exec_chatMessage("<J>"..T.vampire_win,nil)
- elseif vampire_normalMice == 1 then
- -- se acabó el tiempo y 1 jugador sobreviviente
- for name in pairs(miceAlive) do
- if not vampire[name] then
- sumarStat(name, "wins", 5)
- tfm_exec_chatMessage(string_format(T.win,"<J>"..name.."<BL>"),nil)
- break
- end
- end
- elseif vampire_normalMice > 1 then
- -- se acabó el tiempo y más de 1 jugador sobreviviente
- --debugMsg("¡Los ratones han ganado!")
- tfm_exec_chatMessage("<J>"..T.mice_win,nil)
- --local temp = ""
- for name in pairs(miceAlive) do
- --temp = temp..name.." "
- sumarStat(name,"wins", 5)
- end
- --debugMsg("Ganadores: "..temp)
- end
- elseif gameMode == GHOST then
- if ghost_winner then
- --debugMsg(ghost_winner.." ganó")
- tfm_exec_chatMessage(string_format(T.win,"<J>"..ghost_winner.."<BL>"),nil)
- sumarStat(ghost_winner,"wins", 6)
- else
- tfm_exec_chatMessage('<J>'..T.no_win,nil)
- end
- elseif gameMode == CLICK then
- ui_removeTextArea(1,nil)
- system.bindMouse(shaman, false)
- if click_winner == 1 then
- -- todos muertos menos el chami
- --debugMsg("El chamán ganó")
- tfm_exec_chatMessage('<J>'..T.shaman_win,nil)
- sumarStat(shaman,"wins", 7)
- else
- if click_countdown then
- -- chamán muerto o tiempo, gana el rival
- -- debugMsg(click_rival.." ha ganado!")
- tfm_exec_chatMessage(string_format(T.win,"<J>"..click_rival.."<BL>"),nil)
- sumarStat(click_rival,"wins", 7)
- else
- -- chamán muerto o tiempo, los ratones sobrevivientes ganan
- --debugMsg("¡Los ratones han ganado!")
- tfm_exec_chatMessage('<J>'..T.mice_win,nil)
- -- local temp = ""
- for name in pairs(miceAlive) do
- if name~=shaman then
- -- temp = temp..name.." "
- sumarStat(name,"wins", 7)
- end
- end
- --debugMsg("Ganadores: "..temp)
- end
- end
- end
- if gameMode ~= LOBBY then
- for name in pairs(data) do
- if not mice_afk[name] then
- local modo = modos[gameMode]
- getExp(name, modo.exp * playerData[name].level)
- getMoney(name, modo.money)
- end
- if miceAlive[name] then
- tfm_exec_killPlayer(name)
- end
- saveData(name)
- end
- end
- end
- function eventLoop(time,tr)
- if not gameLoaded then return end
- if not gameStarted then
- if time > 8000 then
- gameStarted = true
- modeStart()
- end
- return
- end
- if not killed_afk and time >= 30000 then
- for n in pairs(mice_afk) do
- tfm_exec_killPlayer(n)
- killed_afk = true
- --debugMsg(n.." está en modo AFK")
- end
- end
- modeLoop(time,tr)
- if not gameFinished and tr <= 0 then
- modeEnd()
- elseif gameFinished and tr <=0 then
- startGame()
- end
- end
- function eventKeyboard(name, key, down, x, y)
- if key == 23492 then
- -- ayuda
- elseif miceAlive[name] then
- if mice_afk[name] then mice_afk[name] = nil end
- if gameMode == CLICK or gameMode == TEAMS and not gameFinished then
- if key == 37 or key == 64 or key == 81 then
- data[name].facing=false
- return
- elseif key == 39 or key == 68 then
- data[name].facing=true
- return
- end
- if gameMode == TEAMS and gameStarted then
- if (key == 32 or key == 40 or key == 83) then
- if data[name].timestamp < os.time() - 1500 then
- local id
- if data[name].facing then
- id = tfm_exec_addShamanObject(17,x+10,y-15,90)
- else
- id = tfm_exec_addShamanObject(17,x-10,y+15,-90)
- end
- data[name].timestamp = os.time()
- end
- end
- end
- end
- end
- end
- function eventMouse(name, mx, my)
- if gameMode == CLICK and name == shaman then
- if mice_afk[name] then mice_afk[name] = nil end
- if data[name].timestamp < os.time() - 1500 then
- local id
- if data[name].facing then
- id = tfm_exec_addShamanObject(17,mx,my,90)
- else
- id = tfm_exec_addShamanObject(17,mx,my,-90)
- end
- data[name].timestamp = os.time()
- end
- end
- end
- function eventChatCommand(name, com)
- if com:sub(1,7) == "profile" then
- local n = com:sub(9)
- n = data[n] and n or name
- showProfile(name, n)
- elseif com:sub(1,5) == "stats" then
- local n = com:sub(7)
- n = data[n] and n or name
- local t,p = n.."\n",playerData[n]
- local r,w = p.rounds,p.wins
- for i = 1,7 do
- t=t..modos[i].name.." - rounds: "..r[i].." wins: "..w[i].."\n"
- end
- debugMsg(t)
- elseif com:sub(1,6) == "logros" then
- local n = com:sub(8)
- n = data[n] and n or name
- local t,p = "Logros de "..n.."\n",playerData[n]
- local l = p.logros
- for i = 1,7 do
- li = l[i]
- t=t..modos[i].name.." - logros ("..li.."): "
- for j = 1,li do
- t=t..getTrans().logros[i][j]..", "
- end
- t=t.."\n"
- end
- debugMsg("<BL>"..t.."</BL>")
- end
- end
- function eventTextAreaCallback(id, name, cb)
- if id == 10 then
- ui_removeTextArea(10,name)
- if imageBox_id[name] then
- tfm_exec_removeImage(imageBox_id[name],name)
- end
- elseif id == 12 then
- local m = data[name]
- if m.win_profile then
- m.win_profile = false
- for i=1,22 do
- ui_removeTextArea(i, name)
- end
- end
- elseif cb:find("changeProfileTab") then
- if cb:sub(17) then
- id = cb:sub(17)
- end
- data[name].profileTab = id - 20
- updateProfile(name, data[name].profileUser)
- end
- end
- -- name: nombre del usuario cuyo perfil se muestra
- -- target: nombre del usuario al que se le mostrará la ventana
- function showProfile(target, name)
- local T = getTrans()
- local m = data[target]
- local p = playerData[name]
- m.win_profile = true
- m.profileUser = name
- m.profileTab = 1
- ui_addTextArea(11,"",target,230,110,300,270,0x26353d,0x26353d,nil,true);
- ui_addTextArea(13,"<p align='center'><font size='20' face='Arial Black'><CH>"..name,target,210,60,350,40,0x3a4e61,0x26353d,nil,true)
- 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)
- --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)
- ui_addTextArea(12, "<p align='center'><R><a href='event:close'><b>☓</b></p>",target,530,70,nil,16,0x26353d,0x26353d,nil,true)
- updateProfile(target, name)
- end
- function updateProfile(target, name)
- local T = getTrans()
- local m = data[target]
- local p = playerData[name]
- local txt,data,id = "Main page"
- if m.profileTab == 2 then
- data,id = achievements(name,1,20), 21
- elseif m.profileTab == 3 then
- data,id = "Modos", 21
- else
- local r,w,wins,rounds= p.rounds,p.wins,0,0
- for i = 1,7 do
- wins= wins + w[i]
- rounds = rounds + r[i]
- end
- mort = rounds - wins
- 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)
- txt = "Achiev"
- id = 22
- end
- ui_updateTextArea(22,"<p align='center'><N><a href='event:changeProfileTab"..id.."'><b>"..txt.."</b></a></p>",target)
- ui_updateTextArea(11,data,target)
- end
- function checkAch(name)
- local g,logros = gameMode,playerData[name].logros
- for i=logros[g]+1,#_unlock[g] do
- if playerData[name].rounds[g] >= _unlock[g][i] then
- logros[g] = logros[g] + 1
- sendNotification(name, getTrans().logros[g][logros[g]], getTrans().ach_unlocked, "HTX7faD")
- end
- end
- end
- function achievements(name,n1,n2)
- local t,logros,achText = "",playerData[name].logros,getTrans().logros
- for i=1,7 do
- for a=n1,n2 do
- if logros[i] >= a then
- t = t..achText[i][a].." \n"
- end
- end
- end
- return t
- end
- function defaultData()
- local d = {
- level = 1,
- exp = 0,
- money = 0,
- a_shop = 1,
- logros = {},
- rounds = {},
- wins = {},
- shop = {}
- }
- for i=1,7 do
- d.logros[i] = 0
- d.rounds[i] = 0
- d.wins[i] = 0
- end
- d.shop[0] = true
- for i=1,42 do
- d.shop[i] = false
- end
- return d
- end
- local statGroup = {"rounds","wins","logros"}
- local statGroup_size = {3,3,1}
- function dataToFile(d)
- local f,l,n = "",4
- for i=1,stats_n do
- n = stats_size[i]
- f=f..numberToBytes(d[stats_name[i]], n)
- l = l + n
- end
- for i=1,3 do
- for j=1,7 do
- f=f..numberToBytes(d[statGroup[i]][j], statGroup_size[i])
- l = l + statGroup_size[i]
- end
- end
- for i=1,5 do
- local chunk = 0
- for j=1,7 do
- local k = (i-1)*7 + j
- local c = d.shop[k] and 1 or 0
- chunk = chunk + 2^(j-1) * c
- end
- f=f..numberToBytes(chunk,1)
- l = l + 1
- end
- f = numberToBytes(l, 2)..numberToBytes(game_id, 1)..numberToBytes(game_data_version, 1)..f
- return f,l
- end
- function fileToData(f)
- local d,s,l,n = {},5,bytesToNumber(f:sub(1,2))
- for i=1,stats_n do
- n = stats_size[i]
- d[stats_name[i]] = bytesToNumber(f:sub(s,s+n-1))
- s = s + n
- end
- for i=1,3 do
- d[statGroup[i]] = {}
- for j=1,7 do
- n = statGroup_size[i]
- d[statGroup[i]][j] = bytesToNumber(f:sub(s,s+n-1))
- s = s + n
- end
- end
- d.shop = {[0]=true}
- for i=1,5 do
- local chunk = bytesToNumber(f:sub(s,s))
- for j=1,7 do
- local r = chunk % 2
- local k = (i-1)*7 + j
- d.shop[k] = r
- chunk = (chunk - r)/2
- end
- s = s + 1
- end
- return d
- end
- function fileToData_v2(f)
- local d,s,l,n = {},5,bytesToNumber(f:sub(1,2))
- for i=1,stats_n do
- n = stats_size[i]
- d[stats_name[i]] = bytesToNumber(f:sub(s,s+n-1))
- s = s + n
- end
- for i=1,3 do
- d[statGroup[i]] = {}
- for j=1,7 do
- n = statGroup_size[i]
- d[statGroup[i]][j] = bytesToNumber(f:sub(s,s+n-1))
- s = s + n
- end
- end
- d.shop = {[0]=true}
- for i=1,5 do
- local chunk = bytesToNumber(f:sub(s,s))
- for j=1,7 do
- local r = chunk % 2
- local k = (i-1)*7 + j
- d.shop[k] = r
- chunk = (chunk - r)/2
- end
- s = s + 1
- end
- d[1] = false
- return d
- end
- function fileToData_v1(f)
- local d,s,l,n = defaultData(),5,bytesToNumber(f:sub(1,2))
- for i=1,stats_n do
- n = stats_size[i]
- d[stats_name[i]] = bytesToNumber(f:sub(s,s+n-1))
- s = s + n
- end
- for i=1,3 do
- d[statGroup[i]] = {}
- for j=1,7 do
- n = statGroup_size[i]
- d[statGroup[i]][j] = bytesToNumber(f:sub(s,s+n-1))
- s = s + n
- end
- end
- return d
- end
- function eventPlayerDataLoaded(name, file)
- local header,s,l,z,game_found,f,id,pfile = file:sub(1,8),9,0,file:len()
- if header == data_header then
- while s <= z do
- l = bytesToNumber(file:sub(s,s+1))
- id = bytesToNumber(file:sub(s+2,s+2))
- if id == game_id then
- game_found = true
- break
- end
- s = s+l
- end
- else
- file = data_header
- end
- if game_found then
- f = file:sub(s,s+l-1)
- local v = bytesToNumber(f:sub(4,4))
- if v == game_data_version then
- playerData[name] = fileToData(f)
- --debugMsg(name.." <BL> - Datos cargados ")
- else
- -- version migration
- -------------------------------------------------
- if v == 1 then
- --debugMsg(name.." <BL> - Versión antigua, actualizando datos")
- d = fileToData_v1(f)
- else
- debugMsg(name.." <BL> - Versión muy antigua, reiniciando datos")
- local d = defaultData()
- end
- -------------------------------------------------
- playerData[name] = d
- local old_l = l
- f,l = dataToFile(d)
- file = string_replace(file, s, s+old_l-1, f)
- system.savePlayerData(name, file)
- end
- else
- f,l = dataToFile(playerData[name])
- file = file..f
- system.savePlayerData(name, file)
- debugMsg(name.." <BL> - Datos creados con tamaño: "..l)
- end
- pfile = {file=file, start=s, lenght=l}
- playerFile[name] = pfile
- end
- function saveData(name)
- local pfile = playerFile[name]
- if not pfile then return end
- local f = dataToFile(playerData[name])
- pfile.file = string_replace(pfile.file, pfile.start, pfile.start + pfile.lenght - 1, f)
- system.savePlayerData(name, pfile.file)
- end
- function string_replace(s, i, j, t)
- return s:sub(1,i-1)..t..s:sub(j+1)
- end
- function bytesToNumber(s)
- local n = 0
- local l = string.len(s)
- for i = 1, l do
- n = n + (string.byte(s, i) % 128) * 128 ^ (l - i)
- end
- return n
- end
- function numberToBytes(n, l)
- n = math.floor(math.abs(n))
- l = l or 1
- local s = ""
- for i = 1, l do
- local e = 128 ^ (l - i)
- local p = math.floor(n / e)
- s = s .. string.char(p)
- n = n - p * e
- end
- return s
- end
- function getTrans()
- return text[tfm_get_room_community] or text['es']
- end
- function debugMsg(msg,target)
- tfm_exec_chatMessage("<VP>"..msg, target)
- if target then
- sendNotification(name,msg,"","HTX7faD")
- end
- end
- -- Makinit's xml library
- do
- local namePattern = "[%a_:][%w%.%-_:]*"
- function parseXml(xml)
- local root = {}
- local parents = {}
- local element = root
- for closing, name, attributes, empty, text in string_gmatch(xml, "<(/?)(" .. namePattern .. ")(.-)(/?)>%s*([^<]*)%s*") do
- if closing == "/" then
- local parent = parents[element]
- if parent and name == element.name then
- element = parent
- end
- else
- if name ~= "L" then
- local child = {name = name, attribute = {}}
- table_insert(element, child)
- parents[child] = element
- if empty ~= "/" then
- element = child
- end
- for name, value in string_gmatch(attributes, "(" .. namePattern .. ")%s*=%s*\"(.-)\"") do
- child.attribute[name] = value
- end
- end
- end
- if text ~= "" then
- local child = {text = text}
- table_insert(element, child)
- parents[child] = element
- end
- end
- return root[1]
- end
- function path(nodes, ...)
- nodes = {nodes}
- for i, name in ipairs(arg) do
- local match = {}
- for i, node in ipairs(nodes) do
- for i, child in ipairs(node) do
- if child.name == name then
- table_insert(match, child)
- end
- end
- end
- nodes = match
- end
- return nodes
- end
- end
- loadGame()
- --[[
- args_game = {"name","timestamp"}
- function copy.table(tbl,to,arg)
- to[arg] = {}
- for i=1,#args_game do
- to[args][i] = tbl[arg][i]
- debugMsg("[Copia] Se ha copiado a la tabla "..tbl[arg].name.." el valor de "..tbl[arg][i].." Correspondiente al valor "..args_game[i])
- end
- end
- function table.copy(t, d)
- d = d or false
- local t2 = {}
- for k, v in pairs(t) do
- if d then
- if type(k) == "table" then
- k = table.copy(k, true)
- end
- if type(v) == "table" then
- v = table.copy(v, true)
- end
- end
- t2[k] = v
- end
- return t2
- end
- playerData.logros = {3,1,4,2,2,0,1}
- playerData.wins = {0,0,0,0,0,0,0}
- playerData.rounds = {0,0,0,0,0,0,0}
- playerData.money = 0
- playerData.level = 1
- playerData.exp = 0
- playerData.shop = {true,false,false...}
- ]]
- --[[
- bit = Unidad de memoria que almacena datos en caracteres
- 1 byte 128
- 2 bytes 128*128-1 = 16383
- 3 bytes 128^3 - 1 = 2097151
- stats por minijuego:
- rondas 3 bytes max 2097151
- victorias 3 bytes max 2097151
- total 6 bytes
- * 7 minijuegos 42 bytes
- logros 7 bytes max 127 logros por juego
- nivel 1 byte
- exp 3 bytes
- dinero 2 byte
- tienda actual 1 byte
- tienda 2 bytes
- total 58 bytes
- 46 ---> "n"
- "n___________________________________"
- ]]
- --[[^ este ratón tendría:
- los 3 primeros títulos classic
- 1 título en teams
- 4 títulos en rain
- 2 en allshamans
- etc
- ]]
- --[[
- 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"};
- local titles_all = {
- ["None"]= {2,3,4,5,6,7};
- ["Clasic"]={8,9,10,11,12};
- ["Teams"]={13,14,15,16,17};
- ["Rain"]={18,19,20,21,22,13,24};
- ["Allshamans"]={25,26,27,28,29,30};
- ["Ghost"]={38,39};
- ["Vampire"]={31,32,33,34,35,36,37};
- }
- local titles_dictionary = {
- ["None"] = {1,5,20,35,60,100};
- ["Clasic"] = {1,5,10,30,60};
- ["Teams"] = {1,6,20,50,110};
- ["Rain"] = {1,4,15,35,70,80,99};
- ["Allshamans"] = {1,5,10,20,52,60};
- ["Ghost"]={2,10};
- ["Vampire"] = {1,5,15,26,45,35,60};
- }
- function getUTitle(p,t,m)
- mode = modos[tonumber(m)].name
- datas = data[p][mode]
- a = titles_all[modos[tonumber(m)].name]
- asd = data[p]
- for i,uloe in ipairs(titles_dictionary["None"]) do
- if asd.total == uloe then
- desbtitle(p,titles_all["None"][data[p].ntitles],"All")
- asd.ntitles = asd.total + 1
- end
- end
- for i,ulo in ipairs(titles_dictionary[modos[tonumber(current_mode_number)].name]) do
- if asd[modos[m].name][1] == ulo then
- desbtitle(p,titles_all[modos[tonumber(m)].name][datas[4]]--[[,modos[tonumber(m)].name)
- asd[modos[m].name][4] = asd[modos[m].name][1] + 1
- end
- end
- end
- data[name].titles = {true}for i=2,#texts[data[name].cmm].titles do data[name].titles[i]=false; end
- exp = 4350 * n
- exp = 160*n
- nivel exp para subir al siguiente
- 1 4350 160
- 2 4350*2
- 3 4350*3
- 99 430650
- 100 435000 16000
- exp = 100 * (n^2)/2
- 1 100
- 2 200
- 3 450
- 100 500.000
- ===============================
- exp = 100 * (n^2)/4
- = (n^2) * 25
- n exp req. ronda win victorias para next level
- 6*n 30*n
- --------------------------------------------------
- 1 25 6 30 0.6
- 2 100 12 60 1.25
- 3 225 18 90 1.875
- 4 400 24 120
- 5 625 30 150 3
- 6 900 36 180
- 7 1225 42 210
- 8 1600 48 240
- 9 2025 54 270
- 10 2500 60 300 6
- 20 10000 120 600
- 30 22500 180 900
- 40 40000 240 1200
- 50 62500 300 1500
- 60 90000 360 1800
- 70 122500 420 2100 58,33333333333333
- 80 160000 480 2400 66,66666666666667
- 90 202500 540 2700 75
- 99 245025 594 2970 82,5
- 100 250.000
- 119 354025 714 3570 99,16666666666667
- 120 :) propro friki sin vida
- ===============================
- 1 byte 128
- 2 bytes 128*128-1 = 16383
- 3 bytes 128^3 - 1 = 2097151
- local canons = {
- [0] = {
- name = "";
- img = "";
- },
- {name = "Default cannon";img = "g9zpdwV";price = 0;}
- }
- function getShop(x,y,a,name)
- for x,y in pairs(data[name].images) do
- tfm.exec.removeImage(y)
- end
- local x_c,y_c,a_c = 0,160,320
- texta(851,"<p align='center'><font size='30' face='Soopafresh'><CH>Shop",name,120,40,530,50,0x26353d,0x26353d,nil,true);
- texta(852,"",name,150,90,150,250,0x3a4e61,0x2a3c45,nil,true)
- texta(853,"",name,470,90,150,250,0x3a4e61,0x2a3c45,nil,true)
- texta(854,"",name,310,90,150,250,0x3a4e61,0x2a3c45,nil,true)
- if canons[x] then
- get_shop_date(855,x,150,200,190,90,140,115,name)
- end
- if canons[y] then
- get_shop_date(858,y,150+y_c,200+y_c,190+y_c,90,140,115,name)
- end
- if canons[a] then
- get_shop_date(861,a,150+a_c,200+a_c,190+a_c,90,140,115,name)
- end
- if canons[x+3] then
- get_shop_date(864,x+3,150+x_c,200+x_c,190+x_c,210,260,235,name)
- end
- if canons[y+3] then
- get_shop_date(867,y+3,150+y_c,200+y_c,190+y_c,210,260,235,name)
- end
- if canons[a+3] then
- get_shop_date(890,a+3,150+a_c,200+a_c,190+a_c,210,260,235,name)
- end
- texta(893,"",name,120,340,530,50,0x26353d,0x26353d,nil,true);
- texta(894,"<p align='center'><J>Equiped: <BL>"..canons[data[name].shop].name.."</p>",name,120,365,nil,16,0x26353d,0x26353d,nil,true);
- texta(895,"<p align='center'><J><a href='event:prevshop'><B>←</B> <G>(Prev)</p>",name,330,365,nil,16,0x26353d,0x26353d,nil,true);
- 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);
- texta(897,"<BL>Money: <J>§"..data[name].money.."",name,550,365,nil,16,0x26353d,0x3a4e61,nil,true);
- 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);
- end
- function get_shop_date(aid,id,x1,x2,x3,y1,y2,y3,name)
- 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);
- texta(aid+1,"<p align='center'><font size='20'><J>",name,x2,y2,40,40,'0x' .. shop_have(id,name),0x26353d,0.2,true);
- 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);
- id = tfm.exec.addImage(canons[id].img..".png", "&1", x2, y2-5, name)
- table.insert(data[name].images,id)
- end
- function shop_have(n,p,a)
- t="Buy %s"
- l = ''
- if tonumber(data[p].money) >= tonumber(canons[n].price) and not table.find(data[p].shops,n) then
- l = '★'
- end
- if a == nil then
- if n == data[p].shop then
- args = '7fe8ad'
- elseif table.find(data[p].shops,n) then
- args= "cdd408"
- elseif tonumber(data[p].money) >= tonumber(canons[n].price) and not table.find(data[p].shops,n) then
- args= "78caf0"
- l = '•'
- else
- args = 'f2536d'
- end
- elseif a then
- if n == data[p].shop then
- args = 'Unequip'
- elseif table.find(data[p].shops,n) then
- args= "Equip"
- else
- args = l..string.format(t,canons[n].price)
- end
- end
- return args
- end
- function table.find(tbl, element)
- if type(tbl) == "table" then
- for x, y in pairs(tbl) do if element == y then return true end end
- return false
- end
- end
- ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement