- -- The command used to open the gossip window.
- -- Defaut: gossiploop (use '.gossiploop' ingame).
- local gossipCommand = "gossiploop";
- -- Messages
- local messages = {
- 'This is message one',
- 'This is message two',
- 'This is message three',
- 'This is message four',
- 'This is message five'
- };
- -- Delay between messages (in miliseconds)
- local DELAY = 1000;
- -- Event constants
- local EVENT_ON_SELECT = 2;
- local EVENT_ON_COMMAND = 42;
- -- Menu id, needed for player gossip.
- local MENU_ID = 100;
- -- Menu that shows up when the player opens the gossip
- -- using the command.
- local function onPlayerGossipTalk(_, player)
- player:GossipClearMenu();
- player:GossipMenuAddItem(0, "Start the loop.", 1, 1);
- player:GossipSendMenu(1, player, MENU_ID);
- end
- -- Menu that shows up after the player selected to start
- -- the loop.
- local function onPlayerGossipSelect(_, player, _, _, intid)
- if intid == 1 then
- for index, message in ipairs(messages) do
- player:RegisterEvent(function(_, _, _, player)
- player:GossipClearMenu();
- player:GossipMenuAddItem(0, message, 1, 0);
- player:GossipSendMenu(1, player, MENU_ID);
- end, DELAY * index, 1);
- end
- end
- end
- -- Function to handle the command.
- local function onGossipCommand(_, player, command)
- if command:lower() == gossipCommand:lower() then
- onPlayerGossipTalk(_, player, player);
- return false;
- end
- end
- -- Registering the events.
- RegisterPlayerEvent(EVENT_ON_COMMAND, onGossipCommand)
- RegisterPlayerGossipEvent(MENU_ID, EVENT_ON_SELECT, onPlayerGossipSelect)