PDA

View Full Version : [C++] Create A Custom Teleporter NPC



mager1794
07-07-09, 01:30 AM
well this is fully done in notepad for me cause the computer i do my programming and stuff is broken and i gotta buy a new copy of windows
for it but hey alteast im trying here
ok



type this into your notepad or visual c++ or what ever your gonna use



#include "StdAfx.h"
#include "Setup.h"

#ifdef WIN32
#pragma warning(disable:4305)
#endif

that is your opening text

Next type this under that





class SCRIPT_DECL GlobalNPC : public GossipScript
{
public:
void GossipHello(Object * pObject, Player* Plr, bool AutoSend);
void GossipSelectOption(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code);
void GossipEnd(Object * pObject, Player* Plr);
void Destroy()
{
delete this;
}
};


ok now we will make the opening menu that you see when you speak to the warpNPC





void GlobalNPC::GossipHello(Object * pObject, Player* Plr, bool AutoSend)
{
GossipMenu *Menu;
objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), 1, Plr);

now here is where we divide the horde and ally warps

"i got bored of old color so i went to red"



if(Plr->getRace()== 10||Plr->getRace()== 2||Plr->getRace()== 6||Plr->getRace()== 8||Plr->getRace()== 5)
ok that divided them so now under that put




{Menu->AddItem(0, "Horde Cities", 1);}else{Menu->AddItem(1, "Alliance Cities", 2);}

that will make it where if alliance they cant port to horde and if horde they cant port to alliance





Menu->AddItem(2, "Global Locations", 80);

look at taht study it clearly stare stare stare BAM!!! you got hit with knowledge

lets break it down

Menu- its stating that its part of the menu obvious right

->pointing to the command i guess lol thats my easy description

AddItem - This is what will add this to be selectable on the menu as a port or another menu with more ports

the 2 is just a number for the icon that will be next to it i usually put 0 for it cuase im cool like that

"Global Locations" - that is the name of the menu or port

then 80 - that is the case that that menu links to

ok lets create our own little custom one here just so we understand it

now do what ever you want for yours dont scroll down past the line below til you finish your menu peice



_

ok for my creation i got


Menu->AddItem(4, "ZOMG this guide is awesome", 20);

weird eh,

but if your menu is kind like mine then Good job

now before we go any further let me mention the case thing i said earlier

on my example i put the case as 20

so somewhere in my script will be




case 20: //Magers guide

now if you have a slight C++ knowledge you know what that means
but if you dont well then your screwed lol j/k
the case is what the link will send you to
if the case is a teleport it will port you to where its supposed to
if its a menu you get to go to another menu again

do you kinda understand??

anyway after you made all the menu items you want for the first thing

(btw dont make the Case the same as others or else it will do the same thing)

after your done with your main menu type



if(AutoSend)
Menu->SendTo(Plr);
}

void GlobalNPC::GossipSelectOption(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code)
{
Creature * pCreature = (pObject->GetTypeId()==TYPEID_UNIT)?((Creature*)pObject):NUL L;
if(pCreature==NULL)
return;

GossipMenu * Menu;
switch(IntId)
{

it should somewhat look like this



if(Plr->getRace()== 10||Plr->getRace()== 2||Plr->getRace()== 6||Plr->getRace()== 8||Plr->getRace()== 5)
{Menu->AddItem(0, "Horde Cities", 1);}else{Menu->AddItem(1, "Alliance Cities", 2);}
Menu->AddItem(3, "Azeroth Instances", 30);
Menu->AddItem(4, "Outland Instances", 50);
Menu->AddItem(5, "Shattrath", 20);
Menu->AddItem(6, "Gurubashi Arena", 21);
Menu->AddItem(8, "Buff me up, baby!", 96);
Menu->AddItem(7, "Make This Place Your Home", 95);
Menu->AddItem(9, "Remove Resurrection Sickness", 97);

if(AutoSend)
Menu->SendTo(Plr);
}

void GlobalNPC::GossipSelectOption(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code)
{
Creature * pCreature = (pObject->GetTypeId()==TYPEID_UNIT)?((Creature*)pObject):NUL L;
if(pCreature==NULL)
return;

GossipMenu * Menu;
switch(IntId)
{
great now we got that set up
time for Case 0:


case 0:
GossipHello(pObject, Plr, true);
break;that goes directly under the little "{" mark from the code above

now we go to case 1

now one of your menu items that you made should have started with case 1 if not change it or just do a different case its all the same thing

now if you want the case to send you to another menu just make it look like this a bit


case 1:
{
objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), 1, Plr);
Menu->AddItem(5, "Silvermoon", 4);
Menu->AddItem(5, "Orgrimmar", 5);
Menu->AddItem(5, "Thunder Bluff", 6);
Menu->AddItem(5, "Undercity", 7);

Menu->SendTo(Plr);
}
break;that goes directly under the little "{" mark from the code above

I taught the Menu items so i dont need to describe that again
and the Menu->SendTo(Plr);
just make it to where it shows up

all you need to know now is to make it port

that would be a simple command

so lets base off of Menu->AddItem(5, "Thunder Bluff", 6);

so now we will put


case 6://ThunderBluff
{
Plr->EventTeleport(1, -1304.569946, 205.285004, 68.681396);
}
break; the //thunderbluff is just a comment that reminds you that, that one is the one that ports you to Thunder bluff

Plr->EventTeleport - that is innitiating that the Plr or Player is going have the event teleport used on him/her

then the coords are where you end up at


now just type this at the bottom of this and your done



void GlobalNPC::GossipEnd(Object * pObject, Player* Plr)
{
GossipScript::GossipEnd(pObject, Plr);
}

void SetupGlobalNPC(ScriptMgr * mgr)
{
GossipScript * gs = (GossipScript*) new GlobalNPC();
mgr->register_gossip_script(NPC ID)
}replace the NPC ID with your NPCs ID and compile

if you need help compiling look to another guide please

Well Guys i hoped you liked it and please leave feed back

i wanna know what you guys think

Torgash
09-09-09, 11:32 AM
Nice.

Veldor
14-11-09, 03:10 PM
i will try this now. But i have to say the colors you used to make this tutorial are so ugly !