buttons.txt 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. sign.started(gamesignloc);
  2. rankingtable = "buttonranks";
  3. game_short = "button";
  4. event.load("block_click");
  5. event.load("player_logout");
  6. event.load("player_giveup");
  7. event.load("player_join");
  8. event.load("living_pre_hurt");
  9. clicked = 0;
  10. checked = 0;
  11. tfn = 5; //timeForNext in sec
  12. factor = 0.98; //Faktor, um den tfn vermindert wird
  13. sgoto(tfn * 20, "gameover");
  14. gamename = "§2Buttons";
  15. @wait
  16. wait();
  17. if(event == "living_pre_hurt") {
  18. if(!isPlayer(living_entity)) {
  19. goto("wait");
  20. }
  21. player = living_entity;
  22. }
  23. if(player.hasMinigameId(player, script_id)) {
  24. ignoreGoto(event);
  25. }
  26. goto("wait");
  27. @nextbutton
  28. while(toclick == lastclick) {
  29. toclick = list.getIndex(buttons, math.random(0, list.getSize(buttons) - 1));
  30. }
  31. if(direction == "x") {
  32. markedloc = loc.mod(toclick, number, 0, 0);
  33. block.set(markedloc, markblock);
  34. } elseif(direction == "z") {
  35. markedloc = loc.mod(toclick, 0, 0, number);
  36. block.set(markedloc, markblock);
  37. }
  38. goto("wait");
  39. @player_join
  40. entity.teleport(player, spawn_loc);
  41. living.setHealth(player, 20);
  42. player.setHunger(player, 20);
  43. player.setSaturation(player, 5);
  44. player.clearInventory(player);
  45. display.reset(player);
  46. display.add(player, 1, gamename);
  47. display.add(player, 2, "Time for next click:");
  48. display.add(player, 3, math.roundComma(tfn, 2));
  49. status.addTimed(player, 0, tfn * 20, "Timer");
  50. display.add(player, 4, "Points: ", text.number(clicked));
  51. msg.prefix(player, "§2Buttons", "Click the correct button in time.");
  52. gameover_player = player;
  53. goto("nextbutton");
  54. @living_pre_hurt
  55. cancel = true;
  56. goto("wait");
  57. @block_click
  58. cancel = true;
  59. if(block_loc == toclick) {
  60. tfn *= factor;
  61. tfn = math.roundComma(tfn, 2);
  62. display.add(player, 3, tfn);
  63. status.addTimed(player, 0, tfn * 20, "Timer");
  64. display.add(player, 4, "Points: ", text.number(++clicked));
  65. sgoto(tfn * 20, "gameover");
  66. block.set(markedloc, originblock);
  67. lastclick = toclick;
  68. goto("nextbutton");
  69. } else {
  70. msg.prefix(player, gamename, "You clicked the wrong button.");
  71. goto("coregameover");
  72. }
  73. goto("wait");
  74. @gameover
  75. player = gameover_player;
  76. if(++checked > clicked) {
  77. msg.prefix(player, gamename, "You were too slow.");
  78. goto("coregameover");
  79. }
  80. goto("wait");
  81. @coregameover
  82. player_id = player.getId(player);
  83. playedgames = minigame.getPlayed(player_id, game_short) + 1;
  84. minigame.setPlayed(player_id, game_short, playedgames);
  85. last_record = ranking.getPoints(rankingtable, player_id);
  86. if(last_record < clicked) {
  87. record = clicked;
  88. diff = clicked - last_record;
  89. } else {
  90. record = last_record;
  91. }
  92. ranking.setPoints(rankingtable, player_id, record);
  93. minigame.statsHeader(player, gamename, "§e");
  94. minigame.statsLine(player, "§e", "Points", text.number(clicked));
  95. minigame.statsLine(player, "§e", "Your record", text.number(last_record));
  96. if(diff != null) {
  97. msg(player, " §e- §rBeat own record by §e", text.number(diff));
  98. }
  99. minigame.statsLine(player, "§e", "Played games", text.number(playedgames));
  100. money.addBoost(player, math.round(clicked));
  101. @player_giveup
  102. @player_logout
  103. block.set(markedloc, originblock);
  104. script = script.getFromId(script_id);
  105. minigame.kickPlayer(script, player);
  106. minigame.term(script, gamesignloc);
  107. term();