So, while making a current project, I decided to throw in some of my first attempts at Lua. Im aiming for it to do 3 things at the moment.
-Have a dynamic chat message that greets people within a certain range, and differentiate between GM players and regular players
-Activate the flight path (Thanks Stoneharry for your excellent guide) via Gossip Scripts
-Teleport to the coordinates via Gossip Scripts
[SPOILER]
Code:
local Players = GetInRangePlayers()
function Johnny_McWeaksauce_Greeting(Unit, Event)
If plr:IsGm() == true then
Unit:SendChatMessage(14, 0, "Hello GM" Players)
else
Unit:SendChatMessage(14, 0, "Hello" Players)
end
end
function Johhny_McWeaksauce_OnGossip(Unit, Event, Player)
Unit:GossipCreateMenu(100, Player, 0)
Unit:GossipMenuAddItem(0, "Fly to the Aviary", 1, 0)
Unit:GossipMenuAddItem(0, "Go to the Surface", 2, 0)
Unit:GossipSendMenu(Player)
end
function Johhny_McWeaksauce_OnSubMenu(Unit, Event, Player, id, intid, code)
if (intid == 1) then
--function flight_path_JohhnyMcWeaksauce(event, plr, message, type, language)
--local Taxi = LuaTaxi:CreateTaxi()
--Taxi:AddPathNode(1, 16230, 16400, -57)
--Taxi:AddPathNode(1, 16226, 16406, -54)
--Taxi:AddPathNode(1, 16222, 16399, -50)
--Taxi:AddPathNode(1, 16226, 16395, -44)
--Taxi:AddPathNode(1, 16231, 16399, -39)
--Taxi:AddPathNode(1, 16226, 16403, -32)
--Taxi:AddPathNode(1, 16222, 16403, -32)
--Taxi:AddPathNode(1, 16226, 16403, -32)
--Taxi:AddPathNode(1, 16228, 16391, -32)
--Taxi:AddPathNode(1, 16236, 16392, -32)
--Taxi:AddPathNode(1, 16236, 16413, -32)
--Taxi:AddPathNode(1, 16214, 16414, -33)
--plr:StartTaxi(Taxi, 17675)
--end
else
if (intid == 2) then
Player:Teleport(1, 16222.599609, 16265.900391, 13.208697)
end
end
RegisterServerHook(16, "flight_path_Johnny_McWeaksauce")
RegisterUnitEvent(16999, 18, "Johnny_McWeaksauce_Greeting")
RegisterUnitGossipEvent(16999, 1, "Johhny_McWeaksauce_OnGossip")
RegisterUnitGossipEvent(16999, 2, "Johhny_McWeaksauce_OnSubMenu")
[/SPOILER]Edit number 2: So, after rewriting the code, I went and delete the talking for the time being. I was able to get the menu to work, as well as the teleport, I just need to figure out how to get the if command within the submenu function to reference the taxi function.
Also, for some reason, ANY message causes a flight... >.<
[SPOILER]
Code:
function Johnny_McWeaksauce_Flight_Path(event, plr, message, type, language)
local Taxi = LuaTaxi:CreateTaxi()
Taxi:AddPathNode(1, 16230, 16400, -57)
Taxi:AddPathNode(1, 16226, 16406, -54)
Taxi:AddPathNode(1, 16222, 16399, -50)
Taxi:AddPathNode(1, 16226, 16395, -44)
Taxi:AddPathNode(1, 16231, 16399, -39)
Taxi:AddPathNode(1, 16226, 16403, -32)
Taxi:AddPathNode(1, 16222, 16403, -32)
Taxi:AddPathNode(1, 16226, 16403, -32)
Taxi:AddPathNode(1, 16228, 16391, -32)
Taxi:AddPathNode(1, 16236, 16392, -32)
Taxi:AddPathNode(1, 16236, 16413, -32)
Taxi:AddPathNode(1, 16214, 16414, -33)
plr:StartTaxi(Taxi, 17675)
end
function Johnny_McWeaksauce_OnGossip(Unit, Event, Player)
Unit:GossipCreateMenu(100, Player, 0)
Unit:GossipMenuAddItem(0, "Fly to the Aviary", 1, 0)
Unit:GossipMenuAddItem(0, "Go to the Surface", 2, 0)
Unit:GossipSendMenu(Player)
end
function Johnny_McWeaksauce_OnSubMenu(Unit, Event, Player, id, intid, code)
if (intid == 1) then
end
if (intid == 2) then
Player:Teleport(1, 16222.599609, 16265.900391, 13.208697)
end
end
RegisterServerHook(16, "Johnny_McWeaksauce_Flight_Path")
RegisterUnitGossipEvent(16999, 1, "Johnny_McWeaksauce_OnGossip")
RegisterUnitGossipEvent(16999, 2, "Johnny_McWeaksauce_OnSubMenu")
[/SPOILER]Edit #3: Got it working.
[SPOILER]
Code:
function Johnny_McWeaksauce_OnGossip(Unit, Event, Player)
Unit:GossipCreateMenu(100, Player, 0)
Unit:GossipMenuAddItem(0, "Fly to the Aviary", 1, 0)
Unit:GossipMenuAddItem(0, "Go to the Surface", 2, 0)
Unit:GossipSendMenu(Player)
end
function Johnny_McWeaksauce_OnSubMenu(Unit, Event, Player, id, intid, code)
if (intid == 1) then
local Taxi = LuaTaxi:CreateTaxi()
Taxi:AddPathNode(1, 16230, 16400, -57)
Taxi:AddPathNode(1, 16226, 16406, -54)
Taxi:AddPathNode(1, 16222, 16399, -50)
Taxi:AddPathNode(1, 16226, 16395, -44)
Taxi:AddPathNode(1, 16231, 16399, -39)
Taxi:AddPathNode(1, 16226, 16403, -32)
Taxi:AddPathNode(1, 16222, 16403, -32)
Taxi:AddPathNode(1, 16226, 16403, -32)
Taxi:AddPathNode(1, 16228, 16391, -32)
Taxi:AddPathNode(1, 16236, 16392, -32)
Taxi:AddPathNode(1, 16236, 16413, -32)
Taxi:AddPathNode(1, 16214, 16414, -33)
Player:StartTaxi(Taxi, 17675)
end
if (intid == 2) then
Player:Teleport(1, 16222.599609, 16265.900391, 13.208697)
end
end
RegisterUnitGossipEvent(16999, 1, "Johnny_McWeaksauce_OnGossip")
RegisterUnitGossipEvent(16999, 2, "Johnny_McWeaksauce_OnSubMenu")
[/SPOILER]Now to find a way to allow my other NPC to take a code to activate the teleport.
[SPOILER]
Code:
function Murloc_OnGossip(Unit, Event, Player)
Unit:GossipCreateMenu(100, Player, 0)
Unit:GossipMenuAddItem(0, "Yes I know the secret code", 1, 1)
Unit:GossipSendMenu(Player)
end
function Murloc_OnSubMenu(Unit, Event, Player, id, intid, code)
if (intid == 1) then
Player:Teleport (1, 16240.183594, 16394.423828, -64.379303)
end
end
RegisterUnitGossipEvent(21190, 1, "Murloc_OnGossip")
RegisterUnitGossipEvent(21190, 2, "Murloc_OnSubMenu")
[/SPOILER]
Edit #4: I finally got both scripts working. I figure i'll post them here for anyone else looking to do something similar, and eventually release it with what its designed for. Text in red is designed to be changed.
Aviary/To the Surface NPC
[SPOILER]
Code:
function Johnny_McWeaksauce_OnGossip(Unit, Event, Player)
Unit:GossipCreateMenu(100, Player, 0)
Unit:GossipMenuAddItem(0, "Fly to the Aviary", 1, 0)
Unit:GossipMenuAddItem(0, "Go to the Surface", 2, 0)
Unit:GossipSendMenu(Player)
end
function Johnny_McWeaksauce_OnSubMenu(Unit, Event, Player, id, intid, code)
if (intid == 1) then
local Taxi = LuaTaxi:CreateTaxi()
Taxi:AddPathNode(1, 16230, 16400, -57)
Taxi:AddPathNode(1, 16226, 16406, -54)
Taxi:AddPathNode(1, 16222, 16399, -50)
Taxi:AddPathNode(1, 16226, 16395, -44)
Taxi:AddPathNode(1, 16231, 16399, -39)
Taxi:AddPathNode(1, 16226, 16403, -32)
Taxi:AddPathNode(1, 16222, 16403, -32)
Taxi:AddPathNode(1, 16226, 16403, -32)
Taxi:AddPathNode(1, 16228, 16391, -32)
Taxi:AddPathNode(1, 16236, 16392, -32)
Taxi:AddPathNode(1, 16236, 16413, -32)
Taxi:AddPathNode(1, 16214, 16414, -33)
Player:StartTaxi(Taxi, 17675)
end
if (intid == 2) then
Player:Teleport(1, 16222.599609, 16265.900391, 13.208697)
end
end
RegisterUnitGossipEvent(16999, 1, "Johnny_McWeaksauce_OnGossip")
RegisterUnitGossipEvent(16999, 2, "Johnny_McWeaksauce_OnSubMenu")
[/SPOILER]
Code NPC
[SPOILER]
Code:
function Murloc_OnGossip(Unit, Event, Player)
Unit:GossipCreateMenu(20001, Player, 0)
Unit:GossipMenuAddItem(0, "I know this knowledge", 1, 1)
Unit:GossipSendMenu(Player)
end
function Murloc_OnSubMenu(Unit, Event, Player, id, intid, code)
if (intid == 1) and (code == "Password") then
Player:Teleport (1, 16240.183594, 16394.423828, -64.379303)
end
end
RegisterUnitGossipEvent(15186, 1, "Murloc_OnGossip")
RegisterUnitGossipEvent(15186, 2, "Murloc_OnSubMenu")
[/SPOILER]