Advertisement
Guest User

Ahorcado

a guest
Oct 16th, 2019
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.41 KB | None | 0 0
  1. tfm.exec.disableAfkDeath(true)
  2. tfm.exec.disableAutoShaman(true)
  3. tfm.exec.disableAutoNewGame(true)
  4. tfm.exec.disableAutoScore(true)
  5. tfm.exec.disableAutoTimeLeft(true)
  6.  
  7. chars = {"&","é","~","\"","{","|","è","`","_","à","@","]","+","=","}","¨","ë","ä","ü","ö","£","<",">","0","1","2","3","4","5","6","7","8","9"}
  8.  
  9. lang = {}
  10.  
  11. lang.fr = {
  12. ask_word = "Définir le mot à trouver",
  13. choose_word = "Choisissez un mot : (entre 2 et 12 caractères inclus, aucun accent)",
  14. more_players = "Vous devez être au moins <font color='#FF0000'>2</font> joueurs pour jouer au pendu.",
  15. next_turn_1 = "Le prochain tour débutera dans ",
  16. next_turn_2 = " seconde(s).",
  17. turn_of_1 = "C'est le tour de ",
  18. turn_of_2 = " ! ",
  19. patientez = "Patientez pendant qu'il choisir son mot...",
  20. word_found = "Le mot a été trouvé !",
  21. word_not_found = "Pas de chance ! Le mot était ",
  22. time_out = "Temps écoulé !",
  23. pass_turn = "Le maître du jeu a passé son tour !",
  24. quit = "Le maître du jeu a quitté !"
  25. }
  26.  
  27. lang.en = {
  28. ask_word = "Define the word to find",
  29. choose_word = "Choose a word : (between 2 and 12 characters)",
  30. more_players = "You have to be at least <font color='#FF0000'>2</font> players to play Hangman.",
  31. next_turn_1 = "Next turn in ",
  32. next_turn_2 = " second(s).",
  33. turn_of_1 = "It's ",
  34. turn_of_2 = "'s turn ! ",
  35. patientez = "Wait while he's choosing a word...",
  36. word_found = "The word was found !",
  37. word_not_found = "No luck! The word was ",
  38. time_out = "Time out !",
  39. pass_turn = "The game master has passed his turn !",
  40. quit = "The game master has quit."
  41. }
  42.  
  43. lang.br = {
  44. ask_word = "Escoja una palabra",
  45. choose_word = "Escoja una palabra : (entre 2 e 12 caracteres)",
  46. more_players = "Debe ser al menos <font color='#FF0000'>2</font> jugadores del ahorcado.",
  47. next_turn_1 = "Próximo turno en ",
  48. next_turn_2 = " segundo(s).",
  49. turn_of_1 = "Turno de ",
  50. turn_of_2 = " ! ",
  51. patientez = "Espera mientras escoje una palabra",
  52. word_found = "La palabra fue encontrada!",
  53. word_not_found = "Que pena! la palabra era ",
  54. time_out = "Tiempo agotado !",
  55. pass_turn = "El maestro del juego paso turno !",
  56. quit = "El maestro del juego se fue."
  57. }
  58. text = lang.br
  59.  
  60. players = {}
  61. master = ""
  62.  
  63. letters = {}
  64. invertLetters = {}
  65.  
  66. word = ""
  67. hasDefinedWord = false
  68.  
  69. timer = 0
  70. bestPlayer = ""
  71. pendu_level = 0
  72.  
  73. beginReset = false
  74. hasToReset = false
  75. resetTimer = 0
  76.  
  77. isTimeOut = false
  78. hasWon = false
  79. hasLost = false
  80. hasSkipped = false
  81. hasQuit = false
  82.  
  83. lettersEntered = {}
  84.  
  85. id = {}
  86.  
  87. id["ask_word_main"] = 1
  88. id["ask_word_button"] = 2
  89. id["ask_word_popup"] = 3
  90. id["pendu"] = 4
  91. id["reset_timer"] = 5
  92. id["reset_timer_label"] = 6
  93. id["turn"] = 7
  94. id["turn_label"] = 8
  95. id["one_player"] = 9
  96. id["one_player_label"] = 10
  97.  
  98. function eventNewGame()
  99. updatePlayersList()
  100.  
  101. ui.removeTextArea(id["one_player"])
  102. ui.removeTextArea(id["one_player_label"])
  103.  
  104. letters = {}
  105. invertLetters = {}
  106. word = ""
  107. hasDefinedWord = false
  108. timer = 0
  109.  
  110. if getNbPlayers() > 1 then
  111. master = randomPlayer()
  112. tfm.exec.movePlayer(master, 400, 90, false, 0, 0, false)
  113.  
  114. askWord()
  115. drawPendu()
  116. else
  117. removeAll()
  118.  
  119. ui.addTextArea(id["one_player"], "", nil, 5, 110, 790, 25, 0xC0C0C0, 0x595959, 1f)
  120. ui.addTextArea(id["one_player_label"], "<p align='center'><BL><font color='#000000'>"..text.more_players.."</font></p>", nil, 25, 115, 750, 30, 0xC0C0C0, 0xC0C0C0, 0f)
  121.  
  122. drawWord()
  123. drawPendu()
  124. end
  125. end
  126.  
  127. function eventPlayerDied(playerName)
  128. tfm.exec.respawnPlayer(playerName)
  129. end
  130.  
  131. function eventNewPlayer(playerName)
  132. table.insert(players, playerName)
  133.  
  134. if getNbPlayers() == 2 then
  135. tfm.exec.newGame("@4488917")
  136. else
  137. tfm.exec.respawnPlayer(playerName)
  138. drawWord()
  139. drawPendu()
  140. end
  141. end
  142.  
  143. function eventPlayerLeft(playerName)
  144. local toRemove = 0
  145.  
  146. for i,p in pairs(players) do
  147. if p==playerName then
  148. toRemove = i
  149. end
  150. end
  151.  
  152. table.remove(players, toRemove)
  153.  
  154. if getNbPlayers() == 1 then
  155. tfm.exec.newGame("@4488917")
  156. else
  157. if playerName==master then
  158. hasQuit = true
  159. reset()
  160. end
  161. end
  162. end
  163.  
  164. function eventLoop(currentTime, timeRemaining)
  165. timer = timer + 0.5
  166. if beginReset then
  167. ui.removeTextArea(id["ask_word_main"])
  168. ui.removeTextArea(id["ask_word_button"])
  169.  
  170. resetTimer = resetTimer + 0.5
  171.  
  172. ui.addTextArea(id["reset_timer"], "", nil, 5, 110, 790, 25, 0xC0C0C0, 0x595959, 1f)
  173. if isTimeOut then ui.addTextArea(id["reset_timer_label"], "<p align='center'><BL>"..text.time_out.." <font color='#000000'>"..text.next_turn_1.."<font color='#FF0000'>"..math.floor(10 - resetTimer).."</font>"..text.next_turn_2.."</font></p>", nil, 25, 115, 750, 30, 0xC0C0C0, 0xC0C0C0, 0f) end
  174. if hasWon then ui.addTextArea(id["reset_timer_label"], "<p align='center'><BL>"..text.word_found.." <font color='#000000'>"..text.next_turn_1.."<font color='#FF0000'>"..math.floor(10 - resetTimer).."</font>"..text.next_turn_2.."</font></p>", nil, 25, 115, 750, 30, 0xC0C0C0, 0xC0C0C0, 0f) end
  175. if hasLost then ui.addTextArea(id["reset_timer_label"], "<p align='center'><font color='#000000'>"..text.word_not_found.."</font><BL>"..word:gsub("^%l", string.upper).."<font color='#000000'> ! "..text.next_turn_1.."<font color='#FF0000'>"..math.floor(10 - resetTimer).."</font>"..text.next_turn_2.."</font></p>", nil, 25, 115, 750, 30, 0xC0C0C0, 0xC0C0C0, 0f) end
  176. if hasSkiped then ui.addTextArea(id["reset_timer_label"], "<p align='center'><BL>"..text.pass_turn.."<font color='#000000'> "..text.next_turn_1.."<font color='#FF0000'>"..math.floor(10 - resetTimer).."</font>"..text.next_turn_2.."</font></p>", nil, 25, 115, 750, 30, 0xC0C0C0, 0xC0C0C0, 0f) end
  177. if hasQuit then ui.addTextArea(id["reset_timer_label"], "<p align='center'><BL>"..text.quit.."<font color='#000000'> "..text.next_turn_1.."<font color='#FF0000'>"..math.floor(10 - resetTimer).."</font>"..text.next_turn_2.."</font></p>", nil, 25, 115, 750, 30, 0xC0C0C0, 0xC0C0C0, 0f) end
  178. end
  179.  
  180. checkBestPlayer()
  181.  
  182. if timer==25 and not hasDefinedWord and getNbPlayers() > 1 then
  183. isTimeOut = true
  184. reset()
  185. end
  186.  
  187. if resetTimer==10 then
  188. isTimeOut = false
  189. hasWon = false
  190. hasLost = false
  191. hasSkiped = false
  192. hasQuit = false
  193.  
  194. hasToReset = true
  195.  
  196. reset()
  197. end
  198. end
  199.  
  200. function eventChatCommand(playerName, message)
  201. local args = {}
  202.  
  203. for arg in message:gmatch("[^%s]+") do
  204. table.insert(args, arg:lower())
  205. end
  206.  
  207. if not hasLost and not hasSkiped and not hasQuit and args[1] ~= nil then
  208. if args[1]==word and playerName ~= master and not hasWon then
  209. local score = 0
  210.  
  211. for _,letter in pairs(letters) do
  212. if letter=="_" then score = score + 1 end
  213. end
  214.  
  215. tfm.exec.setPlayerScore(playerName, score, true)
  216.  
  217. local i = 1
  218.  
  219. while i <= word:len() do
  220. if letters[i]~="_" then
  221. invertLetters[i] = letters[i]
  222. letters[i] = "_"
  223. end
  224.  
  225. i = i + 1
  226. end
  227.  
  228. drawWord()
  229. hasWon = true
  230. reset()
  231. end
  232.  
  233. if args[1]=="skip" and playerName==master and not hasWon and not hasLost and not isTimeOut then
  234. hasSkiped = true
  235. reset()
  236. end
  237.  
  238. if args[1]:len()==1 and hasDefinedWord and args[1]~= "_" and args[1]~="-" and args[1]~="'" and playerName ~= master then
  239. local isEntered = false
  240.  
  241. for _,letter in pairs(lettersEntered) do
  242. if letter==args[1] then
  243. isEntered = true
  244. end
  245. end
  246.  
  247. if not isEntered then
  248. local score = 0
  249. local idsToRemove = {}
  250. local isFalse = true
  251.  
  252. table.insert(lettersEntered, args[1])
  253.  
  254. for id,letter in pairs(letters) do
  255. if letter==args[1] then
  256. table.insert(idsToRemove, id)
  257. isFalse = false
  258. end
  259. end
  260.  
  261. for _,idToRemove in pairs(idsToRemove) do
  262. invertLetters[idToRemove] = letters[idToRemove]
  263. letters[idToRemove] = "_"
  264. end
  265.  
  266. score = #idsToRemove
  267.  
  268. if isFalse then
  269. if tfm.get.room.playerList[playerName].score > 0 then score = -1 end
  270. pendu_level = pendu_level + 1
  271. end
  272.  
  273. tfm.exec.setPlayerScore(playerName, score, true)
  274.  
  275. drawWord()
  276. drawPendu()
  277. end
  278. end
  279. end
  280. end
  281.  
  282. function eventTextAreaCallback(textAreaId, playerName, callback)
  283. if callback=="callbackAskWord" then
  284. ui.addPopup(id["ask_word_popup"], 2, text.choose_word, master, 300, 175, 200)
  285. end
  286. end
  287.  
  288. function eventPopupAnswer(popupId, playerName, answer)
  289. if popupId==id["ask_word_popup"] and not isTimeOut and master==playerName then
  290. local choosedWord = tostring(answer)
  291.  
  292. if checkWord(choosedWord) then
  293. defineWord(choosedWord)
  294. hasDefinedWord = true
  295.  
  296. askWord()
  297.  
  298. ui.removeTextArea(id["turn"])
  299. ui.removeTextArea(id["turn_label"])
  300. end
  301. end
  302. end
  303.  
  304. function askWord()
  305. ui.removeTextArea(id["reset_timer"])
  306. ui.removeTextArea(id["reset_timer_label"])
  307. ui.removeTextArea(id["ask_word_main"])
  308. ui.removeTextArea(id["ask_word_button"])
  309.  
  310. if not hasDefinedWord then
  311. ui.addTextArea(id["ask_word_main"], "", master, 5, 110, 790, 35, 0xC0C0C0, 0x595959, 1f)
  312. ui.addTextArea(id["ask_word_button"], "<p align='center'><a href='event:callbackAskWord'>"..text.ask_word.."</a></p>", master, 300, 120, 190, 16, 0x595959, 0x595959, 1f)
  313.  
  314. for p,_ in pairs(tfm.get.room.playerList) do
  315. if p~=master then
  316. ui.addTextArea(id["turn"], "", p, 5, 110, 790, 25, 0xC0C0C0, 0x595959, 1f)
  317. ui.addTextArea(id["turn_label"], "<p align='center'><font color='#000000'>"..text.turn_of_1.."</font><BL>"..master.."<font color='#000000'>"..text.turn_of_2..text.patientez.."</font></p>", p, 25, 115, 750, 30, 0xC0C0C0, 0xC0C0C0, 0f)
  318. end
  319. end
  320. end
  321. end
  322.  
  323. function defineWord(new_word)
  324. word = string.lower(string.gsub(new_word, " ", "-"))
  325.  
  326. letters = {}
  327.  
  328. local i = 36
  329.  
  330. while i < 50 do
  331. ui.removeTextArea(i)
  332. i = i + 1
  333. end
  334.  
  335. for letter in new_word:gmatch"." do
  336. if letter==" " or letter=="-" then
  337. table.insert(invertLetters, "-")
  338. table.insert(letters, "_")
  339. elseif letter=="'" then
  340. table.insert(invertLetters, "'")
  341. table.insert(letters, "_")
  342. else
  343. table.insert(letters, letter:lower())
  344. table.insert(invertLetters, "_")
  345. end
  346. end
  347.  
  348. drawWord()
  349. drawPendu()
  350. end
  351.  
  352. function drawWord()
  353. local textId = 36
  354. local i = 1
  355. local ancreX = 40
  356.  
  357. if #word==0 then
  358. local i = 36
  359.  
  360. while i < 50 do
  361. ui.removeTextArea(i)
  362. i = i + 1
  363. end
  364. else
  365. while i <= word:len() do
  366. ui.addTextArea(textId, "<p align='center'><font size='40' color='#000000'>"..invertLetters[i]:upper().."</font></p>", nil, ancreX, 150, 40, 60, 0xC0C0C0, 0xC0C0C0, 1f)
  367. ancreX = ancreX + 60
  368. textId = textId + 1
  369. i = i + 1
  370. end
  371.  
  372. local finished = true
  373. local j = 1
  374.  
  375. while j <= word:len() do
  376. if invertLetters[j]=="_" then finished = false end
  377. j = j + 1
  378. end
  379.  
  380. if finished then
  381. hasWon = true
  382. reset()
  383. end
  384. end
  385. end
  386.  
  387. function drawPendu()
  388. local pendu = ""
  389.  
  390. if pendu_level==1 then
  391. pendu = pendu.."<br /><br /><br /><br /><br /><br /><br /><br /><br /> _________"
  392.  
  393. elseif pendu_level==2 then
  394. pendu = pendu.."<br />"
  395. pendu = pendu.." |<br />"
  396. pendu = pendu.." |<br />"
  397. pendu = pendu.." |<br />"
  398. pendu = pendu.." |<br />"
  399. pendu = pendu.." |<br />"
  400. pendu = pendu.." |<br />"
  401. pendu = pendu.." |<br />"
  402. pendu = pendu.." |<br />"
  403. pendu = pendu.." ____|____"
  404.  
  405. elseif pendu_level==3 then
  406. pendu = pendu.." __________.__<br />"
  407. pendu = pendu.." |<br />"
  408. pendu = pendu.." |<br />"
  409. pendu = pendu.." |<br />"
  410. pendu = pendu.." |<br />"
  411. pendu = pendu.." |<br />"
  412. pendu = pendu.." |<br />"
  413. pendu = pendu.." |<br />"
  414. pendu = pendu.." |<br />"
  415. pendu = pendu.." ____|____"
  416.  
  417. elseif pendu_level==4 then
  418. pendu = pendu.." __________.__<br />"
  419. pendu = pendu.." | /<br />"
  420. pendu = pendu.." |/<br />"
  421. pendu = pendu.." |<br />"
  422. pendu = pendu.." |<br />"
  423. pendu = pendu.." |<br />"
  424. pendu = pendu.." |<br />"
  425. pendu = pendu.." |<br />"
  426. pendu = pendu.." |<br />"
  427. pendu = pendu.." ____|____"
  428.  
  429. elseif pendu_level==5 then
  430. pendu = pendu.." __________.__<br />"
  431. pendu = pendu.." | / |<br />"
  432. pendu = pendu.." |/<br />"
  433. pendu = pendu.." |<br />"
  434. pendu = pendu.." |<br />"
  435. pendu = pendu.." |<br />"
  436. pendu = pendu.." |<br />"
  437. pendu = pendu.." |<br />"
  438. pendu = pendu.." |<br />"
  439. pendu = pendu.." ____|____"
  440.  
  441. elseif pendu_level==6 then
  442. pendu = pendu.." __________.__<br />"
  443. pendu = pendu.." | / |<br />"
  444. pendu = pendu.." |/ O<br />"
  445. pendu = pendu.." |<br />"
  446. pendu = pendu.." |<br />"
  447. pendu = pendu.." |<br />"
  448. pendu = pendu.." |<br />"
  449. pendu = pendu.." |<br />"
  450. pendu = pendu.." |<br />"
  451. pendu = pendu.." ____|____"
  452.  
  453. elseif pendu_level==7 then
  454. pendu = pendu.." __________.__<br />"
  455. pendu = pendu.." | / |<br />"
  456. pendu = pendu.." |/ O<br />"
  457. pendu = pendu.." | /|<br />"
  458. pendu = pendu.." |<br />"
  459. pendu = pendu.." |<br />"
  460. pendu = pendu.." |<br />"
  461. pendu = pendu.." |<br />"
  462. pendu = pendu.." |<br />"
  463. pendu = pendu.." ____|____"
  464.  
  465. elseif pendu_level==8 then
  466. pendu = pendu.." __________.__<br />"
  467. pendu = pendu.." | / |<br />"
  468. pendu = pendu.." |/ O<br />"
  469. pendu = pendu.." | /|\<br />"
  470. pendu = pendu.." |<br />"
  471. pendu = pendu.." |<br />"
  472. pendu = pendu.." |<br />"
  473. pendu = pendu.." |<br />"
  474. pendu = pendu.." |<br />"
  475. pendu = pendu.." ____|____"
  476.  
  477. elseif pendu_level==9 then
  478. pendu = pendu.." __________.__<br />"
  479. pendu = pendu.." | / |<br />"
  480. pendu = pendu.." |/ O<br />"
  481. pendu = pendu.." | /|\\<br />"
  482. pendu = pendu.." | |<br />"
  483. pendu = pendu.." |<br />"
  484. pendu = pendu.." |<br />"
  485. pendu = pendu.." |<br />"
  486. pendu = pendu.." |<br />"
  487. pendu = pendu.." ____|____"
  488.  
  489. elseif pendu_level==10 then
  490. pendu = pendu.." __________.__<br />"
  491. pendu = pendu.." | / |<br />"
  492. pendu = pendu.." |/ O<br />"
  493. pendu = pendu.." | /|\\<br />"
  494. pendu = pendu.." | |<br />"
  495. pendu = pendu.." | /<br />"
  496. pendu = pendu.." |<br />"
  497. pendu = pendu.." |<br />"
  498. pendu = pendu.." |<br />"
  499. pendu = pendu.." ____|____"
  500.  
  501. elseif pendu_level==11 then
  502. pendu = pendu.." __________.__<br />"
  503. pendu = pendu.." | / | <br />"
  504. pendu = pendu.." |/ O <br />"
  505. pendu = pendu.." | /|\\ <br />"
  506. pendu = pendu.." | | <br />"
  507. pendu = pendu.." | / \\ <br />"
  508. pendu = pendu.." | <br />"
  509. pendu = pendu.." | <br />"
  510. pendu = pendu.." | <br />"
  511. pendu = pendu.." ____|____"
  512.  
  513. hasLost = true
  514. reset()
  515. end
  516.  
  517. ui.addTextArea(id["pendu"], pendu, nil, 323, 235, 135, 138, 0x010101, 0xFFFFFF, 0.5f)
  518. end
  519.  
  520. function reset()
  521. beginReset = true
  522.  
  523. if hasToReset then
  524. if getNbPlayers() < 2 then
  525. tfm.exec.newGame("@4488917")
  526. else
  527. letters = {}
  528. invertLetters = {}
  529. word = ""
  530. hasDefinedWord = false
  531. pendu_level = 0
  532. beginReset = false
  533. hasToReset = false
  534. resetTimer = 0
  535. lettersEntered = {}
  536.  
  537. drawWord()
  538. drawPendu()
  539.  
  540. local randX = math.random(799)
  541. tfm.exec.movePlayer(master, randX, 385, false, 0, 0, false)
  542.  
  543. local oldMaster = master
  544.  
  545. if getNbPlayers()~=1 then
  546. if bestPlayer==oldMaster then
  547. while master==oldMaster do
  548. master = randomPlayer()
  549. end
  550. else
  551. master = bestPlayer
  552. end
  553. else
  554. master = bestPlayer
  555. end
  556.  
  557. randX = math.random(799)
  558.  
  559. tfm.exec.movePlayer(master, randX, 90, false, 0, 0, false)
  560. tfm.exec.setPlayerScore(master, 0, false)
  561.  
  562. timer = 0
  563.  
  564. askWord()
  565. end
  566. end
  567. end
  568.  
  569. function removeAll()
  570. ui.removeTextArea(id["ask_word_main"])
  571. ui.removeTextArea(id["ask_word_button"])
  572. ui.removeTextArea(id["ask_word_popup"])
  573. ui.removeTextArea(id["pendu"])
  574. ui.removeTextArea(id["reset_timer"])
  575. ui.removeTextArea(id["reset_timer_label"])
  576. ui.removeTextArea(id["turn"])
  577. ui.removeTextArea(id["turn_label"])
  578. ui.removeTextArea(id["one_player"])
  579. ui.removeTextArea(id["one_player_label"])
  580. end
  581.  
  582. function checkWord(word_arg)
  583. if word_arg:len() >= 2 and word_arg:len() <= 12 then
  584. for _,c in pairs(chars) do
  585. if string.match(word_arg, c) then
  586. return false
  587. end
  588. end
  589.  
  590. return true
  591. else
  592. return false
  593. end
  594. end
  595.  
  596. function checkBestPlayer()
  597. topScore = 0
  598. bestPlayer = randomPlayer()
  599.  
  600. for name,player in pairs(tfm.get.room.playerList) do
  601. if player.score >= topScore then
  602. topScore = player.score
  603. bestPlayer = name
  604. end
  605. end
  606. end
  607.  
  608. function getNbPlayers()
  609. return #players
  610. end
  611.  
  612. function updatePlayersList()
  613. players = {}
  614.  
  615. for p,_ in pairs(tfm.get.room.playerList) do
  616. table.insert(players, p)
  617. end
  618. end
  619.  
  620. function randomPlayer()
  621. return players[math.random(1,#players)]
  622. end
  623.  
  624. for name,player in pairs(tfm.get.room.playerList) do
  625. tfm.exec.setPlayerScore(name, 0, false)
  626. end
  627.  
  628. updatePlayersList()
  629. bestPlayer = randomPlayer()
  630. tfm.exec.newGame("@4488917")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement