| | Emulator Server Guides Guides for working with World of Warcraft Emulator servers. Learn how to create a WoW Server here.
[NO QUESTIONS HERE] |  | 
06-20-2009
|  | Contributor | | | Join Date: Feb 2008
Posts: 591
Reputation: 255 Level up: 62%, 271 Points needed |     | | | [C++] Creating A Custom User Command Make A Custom User Command I. Introduction II. Moving Forward III. How To Do This IV. A Basic Template V. Getting to the Real Stuff Introduction
Welcome to my tutorial on creating a custom user command. A user command is a relativily easy script to make.
Its strength is also its weakness though, creating this form of user command does not allow you to recieve arguments.
So basically your command cannot be this "#Teleport x y z" but it can be "#Teleport" and they're sent to a designated
coords. In this tutorial were gonna make your most basic but popular command, a mall portal command. Moving Forward
Now of course when writing this script we have to think of everything possible. Such as do we want them to be able to
teleport while in combat, probably not. Maybe we want them to have to pay for this also it really all depends on what
you want. Now in my opinion if your gonna make them pay don't limit it to being out of combat only. Now enough of this
thinking process we all want to move on to our script and i've already got the thinking finished for you. Were gonna
create a mall portal command with a combat limit, and a price, not that i'd suggest it on your server but the point of
this tutorial is to get you on your way to making your own. How To Do This
Now anyone who has never written in C++ is expecting this to be pretty hard probably, but its fairly easy and making simple
scripts like this is a magnificent way to start learning. For this script we will be using what is called a Server Hook, which is
basically a set of occurences defined inside the core that happen so often they figured why not just let people add their own
code(paraphrasing of course). For this script specifically though we will be performing a OnChat Server hook. A Basic Template
I'm gonna give you our base example and then descrive it in this section Code: void PlayerCommands(Player * pPlayer, uint32 Type, uint32 Lang, const char * Message, const char * Misc)
{
}
void SetupPlayerCommands(ScriptMgr * mgr)
{
mgr->register_hook(SERVER_HOOK_EVENT_ON_CHAT, &PlayerCommands);
}
you see void PlayerCommand, that is our main function, the arguments on the left are what we will use to create our command.
then as you see directly under it is SetupPlayerCommands(ScriptMgr * mgr), thats the function that we register inside our setup
files, and under it is where the magic is done. Thats where we use the ScriptMgr to register a hook on a certain server hook and to a special function. Getting to the Real Stuff
Now that we've gotten all that out of the way its time to get down into the actual coding of it. first off lets just create function to
teleport. Code: void PlayerCommands(Player * pPlayer, uint32 Type, uint32 Lang, const char * Message, const char * Misc)
{
pPlayer->SafeTeleport(mapid, instance, x, y, z, o);
}
to find out the mapid, instanceid, x, y, z, and o; go ingame (as a GM) and type .gps and write down the info.
Now with that info anytime we talk we teleport and we don't want that so we need to set it to check for our
command message only. Code: void PlayerCommands(Player * pPlayer, uint32 Type, uint32 Lang, const char * Message, const char * Misc)
{
if(Message == "#Mall" || Message == "#mall")
{
pPlayer->SafeTeleport(mapid, instance, x, y, z, o);
}
}
If you notice that its in there twice, the reason is to not hassle players to have to deal with accidently forgetting a caps,
now that we got it check for our User Command we want to make sure people don't cheat and use this to save
themselves from death. Code: void PlayerCommands(Player * pPlayer, uint32 Type, uint32 Lang, const char * Message, const char * Misc)
{
if(Message == "#Mall" || Message == "#mall")
{
if(!pPlayer->CombatStatus.IsInCombat())
{
pPlayer->SafeTeleport(mapid, instance, x, y, z, o);
}
}
}
There now our players can't cheat to survive, but we don't want them to be able to teleport from anywhere in the world
to a spot filled with items for just anything. We gotta charge them. Code: void PlayerCommands(Player * pPlayer, uint32 Type, uint32 Lang, const char * Message, const char * Misc)
{
if(Message == "#Mall" || Message == "#mall")
{
if(!pPlayer->CombatStatus.IsInCombat())
{
if(pPlayer->GetUInt32Value(PLAYER_FIELD_COINAGE) => 100000)
{
pPlayer->SetUInt32Value(PLAYER_FIELD_COINAGE, pPlayer->GetUInt32Value(PLAYER_FIELD_COINAGE)-100000);
pPlayer->SafeTeleport(mapid, instance, x, y, z, o);
}
}
}
}
There now our User Command is fully built and ready for use, now with the knowledge you've learned go our and
create a bunch of commands for your own private use.
I hope you guys enjoyed what you learned
__________________ http://www.nerdtests.com/mq/uttake.php?id=27159
Awesome Level: 111  | Donate to remove ads, get your "DONATOR title, and get access to the MMOwned community's elite Shoutbawx. 
06-21-2009
|  | Master Sergeant | | | Join Date: Sep 2007 Location: Some place wonderful
Posts: 89
Reputation: 6 | | this is awesome! i currently setting up my server, totally gonna use this tutorial / guide to help me make cool shit  . +REP x2. | 
06-21-2009
|  | Contributor | | | Join Date: Jun 2008 Location: England
Posts: 874
Reputation: 158 Level up: 83%, 190 Points needed |     | | | Really nice +2 rep |  |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | All times are GMT -4. The time now is 04:42 PM. |