Advertisement
BotchyKOTCHA

Untitled

Nov 20th, 2018
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.81 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. text = lang.en
  44.  
  45. players = {}
  46. master = ""
  47.  
  48. letters = {}
  49. invertLetters = {}
  50.  
  51. word = ""
  52. hasDefinedWord = false
  53.  
  54. timer = 0
  55. bestPlayer = ""
  56. pendu_level = 0
  57.  
  58. beginReset = false
  59. hasToReset = false
  60. resetTimer = 0
  61.  
  62. isTimeOut = false
  63. hasWon = false
  64. hasLost = false
  65. hasSkipped = false
  66. hasQuit = false
  67.  
  68. lettersEntered = {}
  69.  
  70. id = {}
  71.  
  72. id["ask_word_main"] = 1
  73. id["ask_word_button"] = 2
  74. id["ask_word_popup"] = 3
  75. id["pendu"] = 4
  76. id["reset_timer"] = 5
  77. id["reset_timer_label"] = 6
  78. id["turn"] = 7
  79. id["turn_label"] = 8
  80. id["one_player"] = 9
  81. id["one_player_label"] = 10
  82.  
  83. function eventNewGame()
  84. updatePlayersList()
  85.  
  86. ui.removeTextArea(id["one_player"])
  87. ui.removeTextArea(id["one_player_label"])
  88.  
  89. letters = {}
  90. invertLetters = {}
  91. word = ""
  92. hasDefinedWord = false
  93. timer = 0
  94.  
  95. if getNbPlayers() > 1 then
  96. master = randomPlayer()
  97. tfm.exec.movePlayer(master, 400, 90, false, 0, 0, false)
  98.  
  99. askWord()
  100. drawPendu()
  101. else
  102. removeAll()
  103.  
  104. ui.addTextArea(id["one_player"], "", nil, 5, 110, 790, 25, 0xC0C0C0, 0x595959, 1f)
  105. 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)
  106.  
  107. drawWord()
  108. drawPendu()
  109. end
  110. end
  111.  
  112. function eventPlayerDied(playerName)
  113. tfm.exec.respawnPlayer(playerName)
  114. end
  115.  
  116. function eventNewPlayer(playerName)
  117. table.insert(players, playerName)
  118.  
  119. if getNbPlayers() == 2 then
  120. tfm.exec.newGame("@531495")
  121. else
  122. tfm.exec.respawnPlayer(playerName)
  123. drawWord()
  124. drawPendu()
  125. end
  126. end
  127.  
  128. function eventPlayerLeft(playerName)
  129. local toRemove = 0
  130.  
  131. for i,p in pairs(players) do
  132. if p==playerName then
  133. toRemove = i
  134. end
  135. end
  136.  
  137. table.remove(players, toRemove)
  138.  
  139. if getNbPlayers() == 1 then
  140. tfm.exec.newGame("@531495")
  141. else
  142. if playerName==master then
  143. hasQuit = true
  144. reset()
  145. end
  146. end
  147. end
  148.  
  149. function eventLoop(currentTime, timeRemaining)
  150. timer = timer + 0.5
  151. if beginReset then
  152. ui.removeTextArea(id["ask_word_main"])
  153. ui.removeTextArea(id["ask_word_button"])
  154.  
  155. resetTimer = resetTimer + 0.5
  156.  
  157. ui.addTextArea(id["reset_timer"], "", nil, 5, 110, 790, 25, 0xC0C0C0, 0x595959, 1f)
  158. 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
  159. 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
  160. 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
  161. 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
  162. 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
  163. end
  164.  
  165. checkBestPlayer()
  166.  
  167. if timer==25 and not hasDefinedWord and getNbPlayers() > 1 then
  168. isTimeOut = true
  169. reset()
  170. end
  171.  
  172. if resetTimer==10 then
  173. isTimeOut = false
  174. hasWon = false
  175. hasLost = false
  176. hasSkiped = false
  177. hasQuit = false
  178.  
  179. hasToReset = true
  180.  
  181. reset()
  182. end
  183. end
  184.  
  185. function eventChatCommand(playerName, message)
  186. local args = {}
  187.  
  188. for arg in message:gmatch("[^%s]+") do
  189. table.insert(args, arg:lower())
  190. end
  191.  
  192. if not hasLost and not hasSkiped and not hasQuit and args[1] ~= nil then
  193. if args[1]==word and playerName ~= master and not hasWon then
  194. local score = 0
  195.  
  196. for _,letter in pairs(letters) do
  197. if letter=="_" then score = score + 1 end
  198. end
  199.  
  200. tfm.exec.setPlayerScore(playerName, score, true)
  201.  
  202. local i = 1
  203.  
  204. while i <= word:len() do
  205. if letters[i]~="_" then
  206. invertLetters[i] = letters[i]
  207. letters[i] = "_"
  208. end
  209.  
  210. i = i + 1
  211. end
  212.  
  213. drawWord()
  214. hasWon = true
  215. reset()
  216. end
  217.  
  218. if args[1]=="skip" and playerName==master and not hasWon and not hasLost and not isTimeOut then
  219. hasSkiped = true
  220. reset()
  221. end
  222.  
  223. if args[1]:len()==1 and hasDefinedWord and args[1]~= "_" and args[1]~="-" and args[1]~="'" and playerName ~= master then
  224. local isEntered = false
  225.  
  226. for _,letter in pairs(lettersEntered) do
  227. if letter==args[1] then
  228. isEntered = true
  229. end
  230. end
  231.  
  232. if not isEntered then
  233. local score = 0
  234. local idsToRemove = {}
  235. local isFalse = true
  236.  
  237. table.insert(lettersEntered, args[1])
  238.  
  239. for id,letter in pairs(letters) do
  240. if letter==args[1] then
  241. table.insert(idsToRemove, id)
  242. isFalse = false
  243. end
  244. end
  245.  
  246. for _,idToRemove in pairs(idsToRemove) do
  247. invertLetters[idToRemove] = letters[idToRemove]
  248. letters[idToRemove] = "_"
  249. end
  250.  
  251. score = #idsToRemove
  252.  
  253. if isFalse then
  254. if tfm.get.room.playerList[playerName].score > 0 then score = -1 end
  255. pendu_level = pendu_level + 1
  256. end
  257.  
  258. tfm.exec.setPlayerScore(playerName, score, true)
  259.  
  260. drawWord()
  261. drawPendu()
  262. end
  263. end
  264. end
  265. end
  266.  
  267. function eventTextAreaCallback(textAreaId, playerName, callback)
  268. if callback=="callbackAskWord" then
  269. ui.addPopup(id["ask_word_popup"], 2, text.choose_word, master, 300, 175, 200)
  270. end
  271. end
  272.  
  273. function eventPopupAnswer(popupId, playerName, answer)
  274. if popupId==id["ask_word_popup"] and not isTimeOut and master==playerName then
  275. local choosedWord = tostring(answer)
  276.  
  277. if checkWord(choosedWord) then
  278. defineWord(choosedWord)
  279. hasDefinedWord = true
  280.  
  281. askWord()
  282.  
  283. ui.removeTextArea(id["turn"])
  284. ui.removeTextArea(id["turn_label"])
  285. end
  286. end
  287. end
  288.  
  289. function askWord()
  290. ui.removeTextArea(id["reset_timer"])
  291. ui.removeTextArea(id["reset_timer_label"])
  292. ui.removeTextArea(id["ask_word_main"])
  293. ui.removeTextArea(id["ask_word_button"])
  294.  
  295. if not hasDefinedWord then
  296. ui.addTextArea(id["ask_word_main"], "", master, 5, 110, 790, 35, 0xC0C0C0, 0x595959, 1f)
  297. 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)
  298.  
  299. for p,_ in pairs(tfm.get.room.playerList) do
  300. if p~=master then
  301. ui.addTextArea(id["turn"], "", p, 5, 110, 790, 25, 0xC0C0C0, 0x595959, 1f)
  302. 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)
  303. end
  304. end
  305. end
  306. end
  307.  
  308. function defineWord(new_word)
  309. word = string.lower(string.gsub(new_word, " ", "-"))
  310.  
  311. letters = {}
  312.  
  313. local i = 36
  314.  
  315. while i < 50 do
  316. ui.removeTextArea(i)
  317. i = i + 1
  318. end
  319.  
  320. for letter in new_word:gmatch"." do
  321. if letter==" " or letter=="-" then
  322. table.insert(invertLetters, "-")
  323. table.insert(letters, "_")
  324. elseif letter=="'" then
  325. table.insert(invertLetters, "'")
  326. table.insert(letters, "_")
  327. else
  328. table.insert(letters, letter:lower())
  329. table.insert(invertLetters, "_")
  330. end
  331. end
  332.  
  333. drawWord()
  334. drawPendu()
  335. end
  336.  
  337. function drawWord()
  338. local textId = 36
  339. local i = 1
  340. local ancreX = 40
  341.  
  342. if #word==0 then
  343. local i = 36
  344.  
  345. while i < 50 do
  346. ui.removeTextArea(i)
  347. i = i + 1
  348. end
  349. else
  350. while i <= word:len() do
  351. ui.addTextArea(textId, "<p align='center'><font size='40' color='#000000'>"..invertLetters[i]:upper().."</font></p>", nil, ancreX, 150, 40, 60, 0xC0C0C0, 0xC0C0C0, 1f)
  352. ancreX = ancreX + 60
  353. textId = textId + 1
  354. i = i + 1
  355. end
  356.  
  357. local finished = true
  358. local j = 1
  359.  
  360. while j <= word:len() do
  361. if invertLetters[j]=="_" then finished = false end
  362. j = j + 1
  363. end
  364.  
  365. if finished then
  366. hasWon = true
  367. reset()
  368. end
  369. end
  370. end
  371.  
  372. function drawPendu()
  373. local pendu = ""
  374.  
  375. if pendu_level==1 then
  376. pendu = pendu.."<br /><br /><br /><br /><br /><br /><br /><br /><br /> _________"
  377.  
  378. elseif pendu_level==2 then
  379. pendu = pendu.."<br />"
  380. pendu = pendu.." |<br />"
  381. pendu = pendu.." |<br />"
  382. pendu = pendu.." |<br />"
  383. pendu = pendu.." |<br />"
  384. pendu = pendu.." |<br />"
  385. pendu = pendu.." |<br />"
  386. pendu = pendu.." |<br />"
  387. pendu = pendu.." |<br />"
  388. pendu = pendu.." ____|____"
  389.  
  390. elseif pendu_level==3 then
  391. pendu = pendu.." __________.__<br />"
  392. pendu = pendu.." |<br />"
  393. pendu = pendu.." |<br />"
  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.." ____|____"
  401.  
  402. elseif pendu_level==4 then
  403. pendu = pendu.." __________.__<br />"
  404. pendu = pendu.." | /<br />"
  405. pendu = pendu.." |/<br />"
  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.." ____|____"
  413.  
  414. elseif pendu_level==5 then
  415. pendu = pendu.." __________.__<br />"
  416. pendu = pendu.." | / |<br />"
  417. pendu = pendu.." |/<br />"
  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.." ____|____"
  425.  
  426. elseif pendu_level==6 then
  427. pendu = pendu.." __________.__<br />"
  428. pendu = pendu.." | / |<br />"
  429. pendu = pendu.." |/ O<br />"
  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.." ____|____"
  437.  
  438. elseif pendu_level==7 then
  439. pendu = pendu.." __________.__<br />"
  440. pendu = pendu.." | / |<br />"
  441. pendu = pendu.." |/ O<br />"
  442. pendu = pendu.." | /|<br />"
  443. pendu = pendu.." |<br />"
  444. pendu = pendu.." |<br />"
  445. pendu = pendu.." |<br />"
  446. pendu = pendu.." |<br />"
  447. pendu = pendu.." |<br />"
  448. pendu = pendu.." ____|____"
  449.  
  450. elseif pendu_level==8 then
  451. pendu = pendu.." __________.__<br />"
  452. pendu = pendu.." | / |<br />"
  453. pendu = pendu.." |/ O<br />"
  454. pendu = pendu.." | /|\<br />"
  455. pendu = pendu.." |<br />"
  456. pendu = pendu.." |<br />"
  457. pendu = pendu.." |<br />"
  458. pendu = pendu.." |<br />"
  459. pendu = pendu.." |<br />"
  460. pendu = pendu.." ____|____"
  461.  
  462. elseif pendu_level==9 then
  463. pendu = pendu.." __________.__<br />"
  464. pendu = pendu.." | / |<br />"
  465. pendu = pendu.." |/ O<br />"
  466. pendu = pendu.." | /|\\<br />"
  467. pendu = pendu.." | |<br />"
  468. pendu = pendu.." |<br />"
  469. pendu = pendu.." |<br />"
  470. pendu = pendu.." |<br />"
  471. pendu = pendu.." |<br />"
  472. pendu = pendu.." ____|____"
  473.  
  474. elseif pendu_level==10 then
  475. pendu = pendu.." __________.__<br />"
  476. pendu = pendu.." | / |<br />"
  477. pendu = pendu.." |/ O<br />"
  478. pendu = pendu.." | /|\\<br />"
  479. pendu = pendu.." | |<br />"
  480. pendu = pendu.." | /<br />"
  481. pendu = pendu.." |<br />"
  482. pendu = pendu.." |<br />"
  483. pendu = pendu.." |<br />"
  484. pendu = pendu.." ____|____"
  485.  
  486. elseif pendu_level==11 then
  487. pendu = pendu.." __________.__<br />"
  488. pendu = pendu.." | / | <br />"
  489. pendu = pendu.." |/ O <br />"
  490. pendu = pendu.." | /|\\ <br />"
  491. pendu = pendu.." | | <br />"
  492. pendu = pendu.." | / \\ <br />"
  493. pendu = pendu.." | <br />"
  494. pendu = pendu.." | <br />"
  495. pendu = pendu.." | <br />"
  496. pendu = pendu.." ____|____"
  497.  
  498. hasLost = true
  499. reset()
  500. end
  501.  
  502. ui.addTextArea(id["pendu"], pendu, nil, 323, 235, 135, 138, 0x010101, 0xFFFFFF, 0.5f)
  503. end
  504.  
  505. function reset()
  506. beginReset = true
  507.  
  508. if hasToReset then
  509. if getNbPlayers() < 2 then
  510. tfm.exec.newGame("@4488917")
  511. else
  512. letters = {}
  513. invertLetters = {}
  514. word = ""
  515. hasDefinedWord = false
  516. pendu_level = 0
  517. beginReset = false
  518. hasToReset = false
  519. resetTimer = 0
  520. lettersEntered = {}
  521.  
  522. drawWord()
  523. drawPendu()
  524.  
  525. local randX = math.random(799)
  526. tfm.exec.movePlayer(master, randX, 385, false, 0, 0, false)
  527.  
  528. local oldMaster = master
  529.  
  530. if getNbPlayers()~=1 then
  531. if bestPlayer==oldMaster then
  532. while master==oldMaster do
  533. master = randomPlayer()
  534. end
  535. else
  536. master = bestPlayer
  537. end
  538. else
  539. master = bestPlayer
  540. end
  541.  
  542. randX = math.random(799)
  543.  
  544. tfm.exec.movePlayer(master, randX, 90, false, 0, 0, false)
  545. tfm.exec.setPlayerScore(master, 0, false)
  546.  
  547. timer = 0
  548.  
  549. askWord()
  550. end
  551. end
  552. end
  553.  
  554. function removeAll()
  555. ui.removeTextArea(id["ask_word_main"])
  556. ui.removeTextArea(id["ask_word_button"])
  557. ui.removeTextArea(id["ask_word_popup"])
  558. ui.removeTextArea(id["pendu"])
  559. ui.removeTextArea(id["reset_timer"])
  560. ui.removeTextArea(id["reset_timer_label"])
  561. ui.removeTextArea(id["turn"])
  562. ui.removeTextArea(id["turn_label"])
  563. ui.removeTextArea(id["one_player"])
  564. ui.removeTextArea(id["one_player_label"])
  565. end
  566.  
  567. function checkWord(word_arg)
  568. if word_arg:len() >= 2 and word_arg:len() <= 12 then
  569. for _,c in pairs(chars) do
  570. if string.match(word_arg, c) then
  571. return false
  572. end
  573. end
  574.  
  575. return true
  576. else
  577. return false
  578. end
  579. end
  580.  
  581. function checkBestPlayer()
  582. topScore = 0
  583. bestPlayer = randomPlayer()
  584.  
  585. for name,player in pairs(tfm.get.room.playerList) do
  586. if player.score >= topScore then
  587. topScore = player.score
  588. bestPlayer = name
  589. end
  590. end
  591. end
  592.  
  593. function getNbPlayers()
  594. return #players
  595. end
  596.  
  597. function updatePlayersList()
  598. players = {}
  599.  
  600. for p,_ in pairs(tfm.get.room.playerList) do
  601. table.insert(players, p)
  602. end
  603. end
  604.  
  605. function randomPlayer()
  606. return players[math.random(1,#players)]
  607. end
  608.  
  609. for name,player in pairs(tfm.get.room.playerList) do
  610. tfm.exec.setPlayerScore(name, 0, false)
  611. end
  612.  
  613. updatePlayersList()
  614. bestPlayer = randomPlayer()
  615. tfm.exec.newGame("@531495")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement