Advertisement
Math_TM

Tribewar V1.2a

Mar 5th, 2017
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.94 KB | None | 0 0
  1. --[[    Module Tribewar    ]]--
  2. --[[  Créé par Athesdrake  ]]--
  3.  
  4. function main()
  5.         chefs  = {"Chef1", "Chef2"} -- Vous pouvez rajouter plus de tribus en rajoutant un chef en plus !
  6.         colors = {0xFF0000, 0xFF, 0x1} -- Vous pouvez changer les couleurs. La première couleur est associée à la première personne juste au-dessus
  7.         bannis = {}
  8.         maps = {0,1,2,3,4,5,6,10,11,14,16,17,18,19,20,21,22,24,25,26,27,28,29,31,32,36,39,40,41,42,44,45,46,47,48,49,50,51,52,53,54,55,57,58,60,61,62,66,67,69,70,71,72,73,74,75,7,77,79,80,85,86,90,91,93,96,97,98,99,100,109,115,119,122,123,127,128,129,130,131,133,134,138,139,140,142,143,144,145,146,147,150}
  9.     -- NE RIEN MODIFIER EN DESSOUS !! --
  10.         players = {}
  11.         tribu = {}
  12.         game = {}
  13.         list_map = {}
  14.         after_tbl = {}
  15.     --vars:
  16.         currentMap = 0
  17.         version = "1.2a"
  18.     --ids:
  19.         id_annonce = 1
  20.         id_scoreboard = 2
  21.         id_quest = 3
  22.     --sytème:
  23.         table.foreach({"AutoNewGame", "AutoShaman", "AutoTimeLeft", "AfkDeath", "DebugCommand", "PhysicalConsumables"}, function(_,v) tfm.exec["disable"..v](true) end)
  24.         tfm.exec.setAutoMapFlipMode(false)
  25.         table.foreach({"next", "ban", "score"}, function(_,v) system.disableChatCommandDisplay(v, true) end)
  26.         table.foreach(tfm.get.room.playerList, function(v) eventNewPlayer(v) end)
  27.         --tfm.exec.newGame([[<C><P /><Z><S><S L="800" o="324650" H="30" X="400" Y="385" T="12" P="0,0,0.3,0.2,0,0,0,0" /></S><D><DS Y="357" X="322" /></D><O /></Z></C>]])
  28.         --currentMap = -1
  29.         setup()
  30. end
  31.  
  32. function setup()
  33.     if checkChefs() then
  34.         if checkChefs()==1 then
  35.             ui.removeTextArea(id_annonce)
  36.             for key,chef in pairs(chefs) do
  37.                 if type(chef)=="string" then
  38.                     table.insert(tribu, {chefs = chef, nom = tfm.get.room.playerList[chef].tribeName, players = {}, score = 0})
  39.                     chefs[chef] = key
  40.                 end
  41.             end
  42.             table.insert(tribu, {nom="None", players = {}, score = 0})
  43.             table.foreach(tfm.get.room.playerList, function(v) eventNewPlayer(v) end)
  44.             table.foreach({"AutoShaman", "AutoTimeLeft", "AfkDeath"}, function(_,v) tfm.exec["disable"..v](false) end)
  45.             for i=1,30 do
  46.                 local map = 0
  47.                 repeat
  48.                     map = maps[math.random(#maps)]
  49.                 until (not inTable(list_map, map))
  50.                 table.insert(list_map, map)
  51.             end
  52.             table.sort(list_map)
  53.             after(5, newMap())
  54.         else
  55.             ui.annonce("Les Représentant de Tribu ne sont pas encore présents dans le salon !")
  56.             after(5, setup)
  57.         end
  58.     else
  59.         ui.annonce("Les Représentant de Tribu ne sont pas référencés (ou mal) !")
  60.     end
  61. end
  62.  
  63. function eventNewPlayer(name)
  64.     if not players[name] then
  65.         players[name] = {score = 0}
  66.     end
  67.     if tribu[1] then
  68.         local tp = tfm.get.room.playerList[name].tribeName
  69.         tp = (tp==tribu[1].nom and 1 or (tp==tribu[2].nom and 2 or 3))
  70.         tfm.exec.setNameColor(name, colors[tp])
  71.         if not table.isIn(tribu[tp].players, name) then
  72.             table.insert(tribu[tp].players, name)
  73.         end
  74.         players[name].tribe = tp
  75.     end
  76.     if currentMap==-1 then
  77.         tfm.exec.respawnPlayer(name)
  78.     end
  79.     system.bindKeyboard(name, 17, true, true)
  80.     system.bindKeyboard(name, 17, false, true)
  81. end
  82.  
  83. function eventPlayerLeft(name) eventPlayerDied(name) end
  84.  
  85. function eventPlayerDied(name)
  86.     if countPlayer(true)<=2 then
  87.         tfm.exec.setGameTime(20)
  88.     end
  89.     if countPlayer(true)<=0 then
  90.         newMap()
  91.     end
  92.     if currentMap==-1 then
  93.         tfm.exec.respawnPlayer(name)
  94.     end
  95. end
  96.  
  97. function eventPlayerWon(name)
  98.     if game.enter and players[name].tribe~=3 then
  99.         if not game.winners then
  100.             game.winners = {}
  101.         end
  102.         table.insert(game.winners, name)
  103.         players[name].score = players[name].score +game.enter
  104.         tribu[players[name].tribe].score = tribu[players[name].tribe].score +game.enter
  105.         ui.annonce(string.format("%s vient de marquer %d point%s pour sa tribu, %s", name, game.enter, game.enter==1 and "" or "s", tribu[players[name].tribe].nom), true)
  106.         game.enter = game.enter -1
  107.         if game.enter==0 then
  108.             game.enter = nil
  109.         end
  110.     end
  111.     eventPlayerDied(name)
  112. end
  113.  
  114. function eventTextAreaCallback(id, name, call)
  115.     if call:sub(0,4)=="next" then
  116.         ui.removeTextArea(id_quest, name)
  117.         if call:sub(6)=="accept" then
  118.             newMap()
  119.         else
  120.             ui.addTextArea(id_quest, name.." a refuser de passer cette map.", chefs[chef[1]==name and 2 or 1], 6, 200, nil, nil, nil, 0xff, 0.5, true)
  121.             after(5, function() ui.removeTextArea(id_quest) end)
  122.         end
  123.     end
  124.     if call:sub(0,3)=="ban" then
  125.         ui.removeTextArea(id_quest, name)
  126.         if call:sub(5,11)=="accept" then
  127.             ban(call:sub(13))
  128.         else
  129.             ui.addTextArea(id_quest, name.." a refuser de bannir "..call:sub(13), chefs[chef[1]==name and 2 or 1], 6, 200, nil, nil, nil, 0xff, 0.5, true)
  130.         end
  131.     end
  132. end
  133.  
  134. function eventChatCommand(name, cmd)
  135.     if cmd=="score" then
  136.         eventKeyboard(name, 1, true)
  137.     end
  138.     if chefs[name] and false then
  139.         if cmd=="next" then
  140.             ui.addTextArea(id_quest, string.format("%s, le représentant de la tribu %s, souhaite passer cette map.\n<p align='center'><a href='event:next accept'>Accepter</a>\t\t<a href='event:next refuse'>Refuser</a>", name, tribu[players[name].tribe].nom), chefs[chefs[1]==name and 2 or 1], 6, 200, nil, nil, nil, 0xff, 0.5, true)
  141.         end
  142.         if cmd:sub(0,3)=="ban" then
  143.             if cmd:sub(5)~="" and tfm.get.room.playerList[cmd:sub(5)] then
  144.                 ui.addTextArea(id_quest, string.format("%s, le représentant de la tribu %s, souaite bannir %s.\n<p align='center'><a href='event:ban accept %s'>Accepter</a>\t\t<a href='event:ban refuse %s'>Refuser</a>", name, tribu[players[name].tribe].nom, call:sub(5), call:sub(5), call:sub(5)), chefs[1], 6, 200, nil, nil, nil, 0xff, 0.5, true)
  145.             end
  146.         end
  147.     end
  148. end
  149.  
  150. function eventKeyboard(name, key, down, x, y)
  151.     if down and tribu[1] then
  152.         local txt = "<p align='center'><font size='30'><u>Scoreboard</u></font></p>\n"
  153.         for k,data in pairs(tribu) do
  154.             if data.nom~="None" then
  155.                 txt = txt..("<font size='20'><u><b>%s</b></u></font>\t\t%s points<font face='Lucida Console'><r>\n\tn. joueur           points\n</r>"):format(data.nom, data.score)
  156.                 table.sort(data.players, function(a,b) return players[a].score>players[b].score end)
  157.                 for key,pl in pairs(data.players) do
  158.                     txt = txt..("   <n>%0d. <v>%s<n><j>%d</j></n></v></n>\n"):format(key, pl..(" "):rep(20 -#pl), players[pl].score)
  159.                 end
  160.                 txt = txt.."</font>"
  161.             end
  162.         end
  163.         ui.addBox(id_scoreboard, txt, name, 50, 27, 700, 350)
  164.         ui.addTextArea(id_scoreboard*100+6, "<b>"..string.char(77, 111, 100, 117, 108, 101, 32, 99, 114, 195, 169, 101, 32, 112, 97, 114, 32, 65, 116, 104, 101, 115, 100, 114, 97, 107, 101), name, 57, 357, nil, nil, 0x0, 0x0, 0, true)
  165.         ui.addTextArea(id_scoreboard*100+7, "<b>V"..version, name, 707, 357, nil, nil, 0x0, 0x0, 0, true)
  166.     else
  167.         ui.removeBox(id_scoreboard, name)
  168.     end
  169. end
  170.  
  171. function eventNewGame()
  172.     if game.winners then
  173.         local tribu1, tribu2, point1, nbrwin1, point2, nbrwin2 = tribu[1], tribu[2], countPoint(1), countPoint(2)
  174.         if tribu1.score==tribu2.score then
  175.             ui.annonce(("La tribu %s et la tribu %s sont à ex-aequo! Serrez les fesses pour démarquer votre tribu !"):format(tribu[1].nom, tribu[2].nom), true)
  176.         elseif nbrwin1==3 then
  177.             ui.annonce(("La tribu %s a mis la patate, elle remporte les 3 firsts!"):format(tribu1.nom), true)
  178.         elseif nbrwin2==3 then
  179.             ui.annonce(("La tribu %s a mis la patate, elle remporte les 3 firsts!"):format(tribu2.nom), true)
  180.         else
  181.             ui.annonce(("La tribu %s a mis %s point%s et %s en a mis %s"):format(tribu1.nom, point1, point1==1 and "" or "s", tribu2.nom, point2), true)
  182.         end
  183.         game.winners = {}
  184.         for _,pl in pairs(bannis) do
  185.             tfm.exec.killPlayer(name)
  186.         end
  187.     end
  188.     game.enter = 3
  189. end
  190.  
  191. function eventLoop(t1, t2)
  192.     if after_tbl then
  193.         for k,v in ipairs(after_tbl) do
  194.             if v.time<=os.time() then
  195.                 v.fonction()
  196.                 table.remove(after_tbl, k)
  197.             end
  198.         end
  199.     end
  200.     if t2<0 and currentMap~=-1 then
  201.         newMap()
  202.     end
  203. end
  204.  
  205. function countPlayer(bool)
  206.     local nbr = 0
  207.     for k,v in pairs(tfm.get.room.playerList) do
  208.         if (not bool) or (not v.isDead) then
  209.             nbr = nbr +1
  210.         end
  211.     end
  212.     return nbr
  213. end
  214.  
  215. function countPoint(n)
  216.     local tbl, points, pl = {3,2,1}, 0, 0
  217.     table.foreach(game.winners, function(k,v) if players[v] and players[v].tribe==n then points = points +tbl[k];pl = pl +1 end end)
  218.     return points, pl
  219. end
  220.  
  221. function after(temps, fonction)
  222.     if fonction then
  223.         table.insert(after_tbl ,{time = os.time()+temps*1000, fonction = fonction})
  224.     end
  225. end
  226.  
  227. function inTable(tbl, cherche)
  228.     for k,v in pairs(tbl) do
  229.         if v==cherche then
  230.             return true
  231.         end
  232.     end
  233.     return false
  234. end
  235.  
  236. function newMap()
  237.     currentMap = currentMap +1
  238.     if list_map[currentMap] then
  239.         tfm.exec.newGame(list_map[currentMap], (not list_map[currentMap]) and math.random(10)==3)
  240.         table.remove(list_map, currentMap)
  241.         table.sort(list_map)
  242.     else
  243.         table.foreach({"AutoNewGame", "AutoShaman", "AutoTimeLeft", "AfkDeath", "DebugCommand", "PhysicalConsumables"}, function(_,v) tfm.exec["disable"..v](true) end)
  244.         currentMap = -1
  245.         tfm.exec.newGame([[<C><P /><Z><S><S L="800" o="324650" H="30" X="400" Y="385" T="12" P="0,0,0.3,0.2,0,0,0,0" /></S><D><DS Y="357" X="322" /></D><O /></Z></C>]])
  246.         eventKeyboard(name, 1, true)
  247.     end
  248. end
  249.  
  250. function table.isIn(tbl, var)
  251.     if not type(tbl)=="table" then
  252.         return false
  253.     end
  254.     for k,v in pairs(tbl) do
  255.         if v==var then
  256.             return true
  257.         end
  258.     end
  259.     return false
  260. end
  261.  
  262. function ban(name)
  263.     ui.addTextArea(id_ban, "Banni !", name, -10^4, -10^4, 2*10^4, 2*10^4, 0x0, 0x0, 1, true)
  264.     tfm.exec.killPlayer(name)
  265.     table.insert(bannis, name)
  266. end
  267.  
  268. function checkChefs()
  269.     for key,chef in pairs(chefs) do
  270.         if type(chef)=="string" then
  271.             for key2,chef2 in pairs(chefs) do
  272.                 if key~=key2 and chef==chef2 then
  273.                     return false
  274.                 end
  275.             end
  276.             if not tfm.get.room.playerList[chef] then
  277.                 return true
  278.             end
  279.         end
  280.     end
  281.     return 1
  282. end
  283.  
  284. ui.annonce = function(txt, supp)
  285.     ui.addTextArea(id_annonce, "<p align='center'><font size='15'>"..txt, nil, 50, 25, 700, 50, nil, 0xff, 0.5, true)
  286.     if supp then
  287.         after(7, function() ui.removeTextArea(id_annonce) end)
  288.     end
  289. end
  290.  
  291. ui.addBox = function(id, txt, name, x, y, largeur, hauteur)
  292.     if (not txt) then txt = "" end
  293.     if (not x) then x = 100 end
  294.     if (not y) then y = 100 end
  295.     if (not hauteur) then hauteur = 200 end
  296.     if (not largeur) then largeur = 200 end
  297.     ui.addTextArea(id*100+0 ," ", name, x+0, y+0, largeur     , hauteur   , 0x2D211A, 0x2D211A, 0.8, true)
  298.     ui.addTextArea(id*100+1 ," ", name, x+1, y+1, largeur-2   , hauteur-2 , 0x986742, 0x986742, 1  , true)
  299.     ui.addTextArea(id*100+2 ," ", name, x+4, y+4, largeur-8   , hauteur-8 , 0x171311, 0x171311, 1  , true)
  300.     ui.addTextArea(id*100+3 ," ", name, x+5, y+5, largeur-10  , hauteur-10, 0x0C191C, 0x0C191C, 1  , true)
  301.     ui.addTextArea(id*100+4 ," ", name, x+6, y+6, largeur-12  , hauteur-12, 0x24474D, 0x24474D, 1  , true)
  302.     ui.addTextArea(id*100+5 ," ", name, x+7, y+7, largeur-14  , hauteur-14, 0x183337, 0x183337, 1  , true)
  303.     ui.addTextArea(id       ,txt, name, x+8, y+8, largeur-16  , hauteur-16, 0x122528, 0x122528, 1  , true)
  304. end
  305.  
  306. ui.removeBox = function(id, name)
  307.     if id then
  308.         ui.removeTextArea(id, name)
  309.         for i=id*100, id*100+15 do
  310.             ui.removeTextArea(i, name)
  311.         end
  312.     end
  313. end
  314.  
  315. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement