PDA

View Full Version : Npc Teleport



b14d3r11
07-07-09, 02:10 PM
Ok guys this is my 1st tutorial on the matter at hand: Lua Npc Teleporter Script,
I will only be covering the actual script not the npc itself.

Okay 1st you need to start off with this:


local npcid = 0
function WarpNPC_OnGossipTalk(pUnit, event, player, pMisc)
This code is telling how the whole parts following are going to work.
pUnit = I dont really get this one so...
Event = This will be the Name of the text that you select
player = By going off the code i thin the Player is the Menu.
pMisc = I don't really know this one so i always left it 0 and it worked

To make it fair for Gankers or PVP we will add this snipet of code in


if (player:IsInCombat() == true) then
player:SendAreaTriggerMessage("You are in combat!")
else
This is making sure the player isnt in combat, and if the player is it will display the message "You are in Combat!"

Now we are on to the part i Like... Actualy making the freakin menus http://www.************/forums/images/smilies/tongue.gif


pUnit:GossipCreateMenu(3544, player, 0)
pUnit:GossipMenuAddItem(3, "Name of Menu", 1, 0)
This is kinda self Explanitory, but if you dont get it... pUnit:GossipCreateMenu will create the menu and pUnit:GossipMenuAddItem will make the text to click

now for pUnit:GossipMenuAddItem(3, "Name of Menu", #, 0) # will go up with each time you make another Menuadditem like this


pUnit:GossipCreateMenu(3544, player, 0)
pUnit:GossipMenuAddItem(3, "Name of Menu", 1, 0)
pUnit:GossipMenuAddItem(3, "Name of Menu", 2, 0)
pUnit:GossipMenuAddItem(3, "Name of Menu", 3, 0)
pUnit:GossipSendMenu(player)
end
end
the # going up will define a new menu

now heres the next snipet of code


function WarpNPC_OnGossipSelect(pUnit, event, player, id, intid, code, pMisc)
if(intid == 999) then
pUnit:GossipCreateMenu(99, player, 0)
the 1st line is saying when you actualy select one of those menus
2nd line is defining what happens when you soon to be Back button (in submenus) will take you back here

now under that put


pUnit:GossipMenuAddItem(3, "Name of Menu", 1, 0)
pUnit:GossipMenuAddItem(3, "Name of Menu", 2, 0)
pUnit:GossipMenuAddItem(3, "Name of Menu", 3, 0)
pUnit:GossipSendMenu(player)
end
This is just saying whats gonna happen when you select it

so far we have:


local npcid = 0
function WarpNPC_OnGossipTalk(pUnit, event, player, pMisc)
if (player:IsInCombat() == true) then
player:SendAreaTriggerMessage("You are in combat!")
else
pUnit:GossipCreateMenu(3544, player, 0)
pUnit:GossipMenuAddItem(3, "Name of Menu", 1, 0)
pUnit:GossipMenuAddItem(3, "Name of Menu", 2, 0)
pUnit:GossipMenuAddItem(3, "Name of Menu", 3, 0)
pUnit:GossipSendMenu(player)
end
end

function WarpNPC_OnGossipSelect(pUnit, event, player, id, intid, code, pMisc)
if(intid == 999) then
pUnit:GossipCreateMenu(99, player, 0)
pUnit:GossipMenuAddItem(3, "Name of Menu", 1, 0)
pUnit:GossipMenuAddItem(3, "Name of Menu", 2, 0)
pUnit:GossipMenuAddItem(3, "Name of Menu", 3, 0)
pUnit:GossipSendMenu(player)
end
This will define the basic menu; like when you go and talk to a NPC it will show 3 choices and when u click nothing will happen. so to make something happen or to add submenus do this


if(intid == 1) then
pUnit:GossipCreateMenu(99, player, 0)
pUnit:GossipMenuAddItem(3, "Sub Menu", 4, 0)
pUnit:GossipMenuAddItem(3, "Sub Menu", 5, 0)
This is saying if you click on the "Name of Menu", 1 then it will open up a sub menu with 2 items but notice the "player" slot changed and went up 1 from the previous menu.

Now to make one of the "Sub Menu" be a teleport set it up like so


if(intid == 4) then
player:Teleport(Map, X, Y, Z)
pUnit:GossipComplete(player)
end
This will teleport you to the provided location.

Notice the Intid changed from a 1 to a 4, that is because it is determining whether Menu item 1 was pressed or 4, 1 will open up the sub menu so you can get to 4 to teleport

At the end of the script have this:


intid = 0
end

RegisterUnitGossipEvent(Npc ID, 1, "WarpNPC_OnGossipTalk")
RegisterUnitGossipEvent(Npc ID, 2, "WarpNPC_OnGossipSelect")
This will finish the script when everythings is pressed and done with, the NPC Id will be the Id of the NPC you make for your script.

The script now is


local npcid = 0
function WarpNPC_OnGossipTalk(pUnit, event, player, pMisc)
if (player:IsInCombat() == true) then
player:SendAreaTriggerMessage("You are in combat!")
else
pUnit:GossipCreateMenu(3544, player, 0)
pUnit:GossipMenuAddItem(3, "Name of Menu", 1, 0)
pUnit:GossipMenuAddItem(3, "Name of Menu", 2, 0)
pUnit:GossipMenuAddItem(3, "Name of Menu", 3, 0)
pUnit:GossipSendMenu(player)
end
end

function WarpNPC_OnGossipSelect(pUnit, event, player, id, intid, code, pMisc)
if(intid == 999) then
pUnit:GossipCreateMenu(99, player, 0)
pUnit:GossipMenuAddItem(3, "Name of Menu", 1, 0)
pUnit:GossipMenuAddItem(3, "Name of Menu", 2, 0)
pUnit:GossipMenuAddItem(3, "Name of Menu", 3, 0)
pUnit:GossipSendMenu(player)
end

if(intid == 1) then
pUnit:GossipCreateMenu(99, player, 0)
pUnit:GossipMenuAddItem(3, "Sub Menu", 4, 0)
pUnit:GossipMenuAddItem(3, "Sub Menu", 5, 0)
pUnit:GossipMenuAddItem(0, "[Back]", 999, 0)

if(intid == 4) then
player:Teleport(Map, X, Y, Z)
pUnit:GossipComplete(player)
end

intid = 0
end

RegisterUnitGossipEvent(Npc ID, 1, "WarpNPC_OnGossipTalk")
RegisterUnitGossipEvent(Npc ID, 2, "WarpNPC_OnGossipSelect")
Well this is what I know and I hope you guys have learned something from this, I learned all of this from looking at other scripts and realizing what they did. So have fun guys http://************/forums/images/*******/misc/progress.gif http://************/forums/images/*******/buttons/edit.gif (http://www.************/forums/editpost.php?do=editpost&p=1541545)

mager1794
07-07-09, 02:13 PM
Nice tutorial =D +rep from me

Onlykl
07-07-09, 02:17 PM
Nice tutorial =D +rep from me
same from me :)