1. -- The command used to open the gossip window.
  2. -- Defaut: gossiploop (use '.gossiploop' ingame).
  3. local gossipCommand = "gossiploop";
  4. -- Messages
  5. local messages = {
  6. 'This is message one',
  7. 'This is message two',
  8. 'This is message three',
  9. 'This is message four',
  10. 'This is message five'
  11. };
  12. -- Delay between messages (in miliseconds)
  13. local DELAY = 1000;
  14. -- Event constants
  15. local EVENT_ON_SELECT = 2;
  16. local EVENT_ON_COMMAND = 42;
  17. -- Menu id, needed for player gossip.
  18. local MENU_ID = 100;
  19. -- Menu that shows up when the player opens the gossip
  20. -- using the command.
  21. local function onPlayerGossipTalk(_, player)
  22. player:GossipClearMenu();
  23. player:GossipMenuAddItem(0, "Start the loop.", 1, 1);
  24. player:GossipSendMenu(1, player, MENU_ID);
  25. end
  26. -- Menu that shows up after the player selected to start
  27. -- the loop.
  28. local function onPlayerGossipSelect(_, player, _, _, intid)
  29. if intid == 1 then
  30. for index, message in ipairs(messages) do
  31. player:RegisterEvent(function(_, _, _, player)
  32. player:GossipClearMenu();
  33. player:GossipMenuAddItem(0, message, 1, 0);
  34. player:GossipSendMenu(1, player, MENU_ID);
  35. end, DELAY * index, 1);
  36. end
  37. end
  38. end
  39. -- Function to handle the command.
  40. local function onGossipCommand(_, player, command)
  41. if command:lower() == gossipCommand:lower() then
  42. onPlayerGossipTalk(_, player, player);
  43. return false;
  44. end
  45. end
  46. -- Registering the events.
  47. RegisterPlayerEvent(EVENT_ON_COMMAND, onGossipCommand)
  48. RegisterPlayerGossipEvent(MENU_ID, EVENT_ON_SELECT, onPlayerGossipSelect)