[C++] Creating A Custom User Command menu

These ads disappear when you log in.

Results 1 to 3 of 3
  1. #1
    mager1794's Avatar Lieutenant Commander
    Reputation
    356
    Join Date
    Feb 2008
    Posts
    703
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)

    [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

    Lunar Gaming - Reaching For The Stars

    These ads disappear when you log in.

  2. #2
    Avatori's Avatar Master Sergeant
    Reputation
    6
    Join Date
    Sep 2007
    Posts
    88
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    this is awesome! i currently setting up my server, totally gonna use this tutorial / guide to help me make cool shit . +REP x2.

  3. #3
    Hunterplay's Avatar Contributor
    Reputation
    158
    Join Date
    Jun 2008
    Posts
    928
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Really nice +2 rep
    Former News Team Member

Similar Threads

  1. I'm about to create a custom area
    By Xeneth in forum World of Warcraft Emulator Servers
    Replies: 49
    Last Post: 02-27-2008, 05:03 PM
  2. [Release] Custom Quest Commands/Subcommands
    By wowcomputer in forum World of Warcraft Emulator Servers
    Replies: 9
    Last Post: 12-29-2007, 05:35 PM
  3. HOWTO: Create a custom patch (e.g. for Cheat Engine)
    By Etherea in forum World of Warcraft Bots and Programs
    Replies: 19
    Last Post: 07-15-2007, 01:47 PM
All times are GMT -5. The time now is 12:02 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved. Digital Point modules: Sphinx-based search