Hello & Welcome to our community. Is this your first visit? Register
Follow us on
Follow us on Facebook Follow us on Twitter Watch us on YouTube


MMOCoin

Likes Likes:  0
Results 1 to 4 of 4
  1. #1
    Scout

    Join Date
    Jul 2009
    Posts
    20
    Post Thanks / Like
    Rep Power
    15
    Reputation
    40

    [C++ Guide] Create A Custom User Command


    Register to remove this ad
    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






    › See More: [C++ Guide] Create A Custom User Command



  2. Related Threads - Scroll Down after related threads if you are only interested to view replies for above post/thread

  3. #2
    Grunt
    Sdyess94's Avatar
    Join Date
    Jan 2009
    Posts
    36
    Post Thanks / Like
    Rep Power
    16
    Reputation
    60
    Thanks Mager, I've been having to look at scripts that were already made, which is helpful, but its a lot easier with a tut.



    EDIT: Shouldnt a bool be used?
    Last edited by Sdyess94; 11-07-09 at 05:34 PM.

  4. #3
    Scout

    Join Date
    Jul 2009
    Posts
    20
    Post Thanks / Like
    Rep Power
    15
    Reputation
    40
    Its not required to have a bool but its runs alot better, wasn't really thinking when i made this tutorial

  5. #4
    Beginner

    Join Date
    Nov 2009
    Posts
    2
    Post Thanks / Like
    Rep Power
    15
    Reputation
    1

    Register to remove this ad
    oops saw that there is no questions allowed nice work
    Last edited by Veldor; 14-11-09 at 03:29 PM.

 

 

Visitors found this page by searching for:

c trinitycore2 script for mall command

SEO Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -5. The time now is 12:01 AM.
Powered by vBulletin® Copyright ©2000-2024, Jelsoft Enterprises Ltd.
See More links by ForumSetup.net. Feedback Buttons provided by Advanced Post Thanks / Like (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
vBulletin Licensed to: MMOPro.org