The server I develop for needed a pretty standard warp npc for an area and I wanted to make my own instead of reusing one of the other ones. I also thought that it would be helpful to make one that could easily be used by other people. While I can't say that this is well tested, I did attempt to make this as optimized as possible while still flexible.
*The variable 'menunum' refers to the gossip menu id range it will use. It will use anywhere from 'menunum' to 'menunum' minus the number of elements in the 'menu' table. Ex: 33310 to 33289. This number will need changed if you use more than one copy of this script.
*The variable 'menuicon' is the icon used to show submenus. 4 is a gear.
*The variable 'teleicon' is the icon used for the teleport options. 2 is a wing.
*The table 'menu' is where you'll edit the submenus and teleport coords. The script should tolerate any number of menu options in any order. You can also have any number of submenus of the main menu but you can't have a submenu within a submenu.
*You'll need to change 200000 in the RegisterGossipEvent's at the bottom of the script to the entry id of the npc you want to use.
*If you want to run more than one copy, you'll also have to replace all occurances of 'TeleNPC_' with 'YourNpcsName_'
For basic use of this script you won't want to touch the actual functions, just the variables. The most common problem will be messing up the 'menu' by misplacing a bracket or a comma. Please report any problems you have here so I can make it as stable and efficient as possible.
Code:
--*****************************************
--*UniversalTeleNPC script by Oxin v1.0 *
--*Made for UniversalWoW(www.universal-wow.com) *
--*Everyone is free to distribute and modify to their *
--*needs but please leave the original credits *
--*****************************************
local menunum = 33310
local menuicon = 4
local teleicon = 2
local menu =
{
{"Class Trainers",
{
{"Paladin", 37, 1160.088257, 371.752472, 355.525665},
{"Priest", 37, 1160.088257, 371.752472, 355.525665},
{"Shaman", 37, 1057.267456, 397.039124, 339.991333},
{"Warrior", 37, 1024.346680, 386.166229, 332.062164},
{"Rogue", 37, 1011.189636, 391.762573, 336.828796},
{"Warlock", 37, 1218.062134, 346.329102, 370.863312},
{"Mage", 37, 1218.062134, 346.329102, 370.863312},
{"Hunter", 37, 1165.920898, 308.611786, 354.212952},
{"Druid", 37, 1165.920898, 308.611786, 354.212952}
}
},
{"Profession Trainers",
{
{"Leatherworking", 37, 1026.105103, 385.793518, 336.799896},
{"Enchanting", 37, 1218.062134, 346.329102, 370.863312},
{"Blacksmithing", 37, 1240.293823, 243.216705, 355.536072},
{"Engineering", 37, 1240.293823, 243.216705, 355.536072},
{"Alchemy", 37, 1227.457886, 198.279648, 354.644836},
{"Tailoring", 37, 1180.818604, 194.865295, 357.214050},
{"Enchanting", 37, 1178.090942, 206.977142, 372.440460},
{"Cooking", 37, 1159.221436, 331.393188, 354.312592}
}
},
{"Vendors",
{
{"Main Vendors", 37, 1175.451782, 270.882629, 357.752716},
{"Gems", 37, 1104.128174, 401.164734, 354.609253},
{"Containers", 37, 1104.128174, 401.164734, 354.609253},
{"Projectiles", 37, 1104.128174, 401.164734, 354.609253},
{"Season 3", 37, 1096.719971, 298.905939, 338.617249},
{"Dungeon Tiers", 37, 1096.719971, 298.905939, 338.617249},
{"Food", 37, 1159.419434, 214.685043, 357.204498}
}
},
{"Innkeeper", 37, 1180.024780, 211.609070, 357.207306},
{"Mounts", 37, 1140.919189, 277.717896, 353.954224},
{"Battlemasters", 37, 99.597717, 344.603516, 333.011078},
{"Weaponmaster", 37, 1143.361450, 213.367447, 356.382141}
}
function TeleNPC_MainMenu(Unit, Player)
local i = 0
Unit:GossipCreateMenu(menunum, Player)
for k,v in pairs(menu) do
i = i + 1
if type(v[2]) == "table" then
Unit:GossipMenuAddItem(Player, menuicon, v[1], i, 0)
i = i + #(v[2])
else
Unit:GossipMenuAddItem(Player, teleicon, v[1], i, 0)
end
end
Unit:GossipSendMenu(Player)
end
function TeleNPC_SubMenu(Unit, Player, i, Submenu)
Unit:GossipCreateMenu(menunum-i, Player)
Unit:GossipMenuAddItem(Player, 7, "<--Back", 0, 0)
for k,v in pairs(Submenu) do
i = i + 1
Unit:GossipMenuAddItem(Player, teleicon, v[1], i, 0)
end
Unit:GossipSendMenu(Player)
end
function TeleNPC_OnGossipTalk(Unit, Event, Player)
TeleNPC_MainMenu(Unit, Player)
end
function TeleNPC_OnGossipSelect(Unit, Event, Player, MenuId, Id, Code)
local i = 0
if(Id == 0) then
TeleNPC_MainMenu(Unit,Player)
else
for k,v in pairs(menu) do
i = i + 1
if (Id == i) then
if type(v[2]) == "table" then
TeleNPC_SubMenu(Unit, Player, i, v[2])
else
Player:Teleport(v[2], v[3], v[4], v[5])
Player:GossipComplete()
end
return
elseif (type(v[2]) == "table") then
for j,w in pairs(v[2]) do
i = i + 1
if (Id == i) then
Player:Teleport(w[2], w[3], w[4], w[5])
Player:GossipComplete()
return
end
end
end
end
end
end
RegisterGossipEvent(200000, 1, "TeleNPC_OnGossipTalk")
RegisterGossipEvent(200000, 2, "TeleNPC_OnGossipSelect")