Code:
function Test_Unit_Gossip(pUnit, event, player, pMisc, intid)
pUnit:GossipCreateMenu(50, player, 0)
pUnit:GossipMenuAddItem(0, "|cff3060B5Current status:|r Looking for Racers!", 1, 0)
pUnit:GossipMenuAddItem(9, "Sign me up for this race!", 2, 0)
[...] -- skipping out this bit as we don't need it for this guide
pUnit:GossipMenuAddItem(0, " > Racer 3", 3, 0)
if (intid == 3) then
pUnit:GossipMenuAddItem(0, "|cff095F0B > Races won: 0", 0)
pUnit:GossipMenuAddItem(0, "|cFFFF0000 > Races lost: 0", 0)
end
pUnit:GossipMenuAddItem(7, "[Exit]", 50, 0)
pUnit:GossipSendMenu(player)
end
function Test_Unit_Select(pUnit, event, player, id, intid, code, pMisc)
if (intid == 50) then
player:GossipComplete()
end
if (intid == 3) then
Test_Unit_Gossip(pUnit, player, intid)
end
end
RegisterUnitGossipEvent(50, 1, "Test_Unit_Gossip")
RegisterUnitGossipEvent(50, 2, "Test_Unit_Select")
Alright, there's the script we'll be using! Now for the real work.
Code:
function Test_Unit_Gossip(pUnit, event, player, pMisc, intid)
You should've noticed something immediately in the parameters of this function. Yes, that's right! We have included an 'intid' parameter in the gossip function which normally isn't there. We'll be needing this parameter later on.
Code:
pUnit:GossipMenuAddItem(0, " > Racer 3", 3, 0)
[...]
function Test_Unit_Select(pUnit, event, player, id, intid, code, pMisc)
if (intid == 3) then
Test_Unit_Gossip(pUnit, player, intid)
end
end
So we press the " > Racer 3" item with intid 3. The Test_Unit_Select function is ran and we have a match. What happens then? Lua calls the Test_Unit_Gossip function again, huh? Does that mean we get back to the menu selection screen then? Yep, that's correct. The script sends us back to the gossip menu, but with some extra information this time. Namely, it's sending the intid to the gossip menu , too! Remember the parameter 'intid' in our gossip menu? It's ready for use, sir!
Code:
function Test_Unit_Gossip(pUnit, event, player, pMisc, intid)
[...]
if (intid == 3) then
pUnit:GossipMenuAddItem(0, "|cff095F0B > Races won: 0", 0)
pUnit:GossipMenuAddItem(0, "|cFFFF0000 > Races lost: 0", 0)
end
If we're sent back from the selection with the intid it means we can check what value the intid contains. Considering we were sent back with intid as 3, we would have a match here. In case we have a match two additional menu items are displayed, these will appear under the racer! If it's done doing this it'll continue with the rest of the script thus we end up with the menu as displayed in the picture. I have added the spaces (