Idea Motion Group
လူၾကီးမင္းတြင္ Idea Motion Group မွမွတ္ပံုတင္ျပီးေသာ Member Account ရွိပါက Log In မွ တဆင့္ဝင္ေရာက္ပါ။
New Guest ျဖစ္ပါက Register ျပဳလုပ္၍ဝင္ေရာက္ေပးပို႔ႏိုင္ပါသည္။။
*********Idea Motion Group*********
Log in

I forgot my password

Latest topics
Country Codes

Timer

Total
  • >

/>

Test

HowTo: Create custom commands. (Trinity)

View previous topic View next topic Go down

default HowTo: Create custom commands. (Trinity)

Post   on Fri Jul 06, 2012 8:51 am

Greetings AC Web. I havent seen any tutorials about this so I figured that I will make one for you.
This will be my first tutorial ever made so if its too hard to read or
understand please tell me about it so I can modify this thread, and/or
take your tips with me to my next tutorial.
If you have any problems with this script you could ask for my help, but
I wont help you set it up over TeamViewer or something like that.
If you would like to take this script to the next level (creating other
commands that is not in this thread) and you get stuck somewhere, or
don't know what to do or how to make it, feel free to ask for my help.

Note: you cannot make custom commands on trinity if you are using a repack.


[C++] HowTo: Create custom commands. (Trinity)

First we want to create a new c++ file.
If you don't know how to do this, the easiest way to do this is to;
1. Open up notepad.
2. Click file -> Save as.
3. Change filetype from .txt to All files
4. Type in the script's name in the box above. We will use (test_command.cpp) for this tutorial.

You can save this wherever you want, but in the end of the day it needs to be inside your source folder. (Mine's C:/Trinity)
Save the file to X:/YourSourceFolder/src/server/scripts/Custom. I will save mine to C:/Trinity/src/server/scripts/Custom.
Your new cpp file should be placed inside X:/YourSourceFolder/src/server/scripts/Custom

Now, open up the program you compile with, I use Microsoft Visual C++ 2010 Express.
On the left, it should look something similar to this:
[Only admins are allowed to see this image]

Now, open up scripts, right click on Source Files->Add and click Existing Item like this:
[Only admins are allowed to see this image]

Now you should be able to locate the script you just made.
- Go into your build folder (C:/Trinity/src/server/scripts/Custom
- Select the .cpp file you made (test_command.cpp) and click the Add button.

The empty .cpp file you made should now be added to your program, inside scripts.
Find the file, and double click it or whatever to open it inside your program.

First of all we would like to start with includes. You might not need all of these, but we will add them anyway.
On the top line of your .cpp file add this:



Code:
#include "ScriptMgr.h"
#include "ObjectMgr.h"
#include "MapManager.h"
#include "Chat.h"
#include "Group.h"
Now we want to insert the class.



Code:
class test_commandscript : public CommandScript
{
public:
test_commandscript() : CommandScript("test_commandscript") { }
After that's done, we want to create our commands, but first of all we want to insert this:



Code:
ChatCommand* GetCommands() const
Under that line, we will create our commands.



Code:
{
static ChatCommand testCommandTable[] =
{
{ "command", SEC_PLAYER, false, &HandleTestCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "test", SEC_PLAYER, true, NULL, "", testCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
In this case, our top static ChatCommand will be the Subcommands, while the other static ChatCommand will be the command itself.

So right now, we have created a command called "test", with a subcommand called "command".
If you write .test while you are ingame you will get a list of the subcommands.
If you write .test command - it would actually make your character do the command.

SEC_PLAYER is our required gm level or account security level.
SEC_RANK = GM LEVEL.



Code:
SEC_PLAYER = 0,
SEC_MODERATOR = 1,
SEC_GAMEMASTER = 2,
SEC_ADMINISTRATOR = 3,
SEC_CONSOLE = 4
The "&HandleTestCommand" will be the handler of each
subcommand, and will be linked to the command's script that we will
write later.
The handlers needs to be unique and different from each subcommand, or else every command you make would have the same effect.

Now we want to write our new command's script.



Code:
static bool HandleTestCommand(ChatHandler* handler, const char* args)
{

Player* me = handler->GetSession()->GetPlayer();

me->Say("test command?", LANG_UNIVERSAL);
return true;
After that we want to add in the voids, in order to compile it.



Code:
}
};

void AddSC_test_commandscript()
{
new test_commandscript();
}
Our script should now look like this:



Code:
#include "ScriptMgr.h"
#include "ObjectMgr.h"
#include "MapManager.h"
#include "Chat.h"
#include "Group.h"

class test_commandscript : public CommandScript
{
public:
test_commandscript() : CommandScript("test_commandscript") { }

ChatCommand* GetCommands() const
{
static ChatCommand testCommandTable[] =
{
{ "command", SEC_PLAYER, false, &HandleTestCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "test", SEC_PLAYER, true, NULL, "", testCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}

static bool HandleTestCommand(ChatHandler* handler, const char* args)
{

Player* me = handler->GetSession()->GetPlayer();

me->Say("test command?", LANG_UNIVERSAL);
return true;
}
};

void AddSC_test_commandscript()
{
new test_commandscript();
}
READ NEXT POST


Join date : 1970-01-01

View user profile

Back to top Go down

default Re: HowTo: Create custom commands. (Trinity)

Post   on Fri Jul 06, 2012 8:55 am

We have now created our test command. If you type .test command while
you are ingame after compiling your character would say: test command?
Note: You will not be able to compile the script into your server before
you add the script to Scriptloader.cpp, but before we do that we will
create simple teleport command into our test command.

In the top static ChatCommand of our script, add this:



Code:
{ "gurubashi", SEC_PLAYER, false, &HandleGurubashiCommand, "", NULL },
It should now look like this:



Code:
static ChatCommand testCommandTable[] =
{
{ "command", SEC_PLAYER, false, &HandleTestCommand, "", NULL },
{ "gurubashi", SEC_PLAYER, false, &HandleGurubashiCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "test", SEC_PLAYER, true, NULL, "", testCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
Now we are going to write the teleport script.
Below the test command code we wrote, add this:



Code:
static bool HandleGurubashiCommand(ChatHandler* handler, const char* args)
{

Player* me = handler->GetSession()->GetPlayer();

if (me->isInCombat())
{
handler->SendSysMessage(LANG_YOU_IN_COMBAT);
handler->SetSentErrorMessage(true);
return false;
}

// stop flight if need
if (me->isInFlight())
{
me->GetMotionMaster()->MovementExpired();
me->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
me->SaveRecallPosition();

me->TeleportTo(0, -13181.8f, 339.356f, 42.9805f, 1.18013f); // MapId, X, Y, Z, O
return true;
}
Your script should now look like this:



Code:
#include "ScriptMgr.h"
#include "ObjectMgr.h"
#include "MapManager.h"
#include "Chat.h"
#include "Group.h"

class test_commandscript : public CommandScript
{
public:
test_commandscript() : CommandScript("test_commandscript") { }

ChatCommand* GetCommands() const
{
static ChatCommand testCommandTable[] =
{
{ "command", SEC_PLAYER, false, &HandleTestCommand, "", NULL },
{ "gurubashi", SEC_PLAYER, false, &HandleGurubashiCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "test", SEC_PLAYER, true, NULL, "", testCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}

static bool HandleTestCommand(ChatHandler* handler, const char* args)
{

Player* me = handler->GetSession()->GetPlayer();

me->Say("test command?", LANG_UNIVERSAL);
return true;
}

static bool HandleGurubashiCommand(ChatHandler* handler, const char* args)
{

Player* me = handler->GetSession()->GetPlayer();

if (me->isInCombat())
{
handler->SendSysMessage(LANG_YOU_IN_COMBAT);
handler->SetSentErrorMessage(true);
return false;
}

// stop flight if need
if (me->isInFlight())
{
me->GetMotionMaster()->MovementExpired();
me->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
me->SaveRecallPosition();

me->TeleportTo(0, -13181.8f, 339.356f, 42.9805f, 1.18013f); // MapId, X, Y, Z, O
return true;
}
};

void AddSC_test_commandscript()
{
new test_commandscript();
}
Now, if you type .test gurubashi while you are ingame, it will teleport you to gurubashi if you're not in combat.
If you are in combat and you do the command, you will not be teleported
and you will get a message telling you that you're in combat.

Now we can add our script to Scriptloader.cpp
At this time you remember where you opened your script inside your program.
Minimize "scripts" over to the left in your program, as you wont need to have it open now.
It should now look something like this (again):
[Only admins are allowed to see this image]

Now open up your "game" and Source Files and look for ScriptLoader.cpp
After you have found your ScriptLoader.cpp, open it and scroll all the way to the bottom.
It should look like this, if you haven't added any custom scripts to your server before.



Code:
#ifdef SCRIPTS
/* This is where custom scripts' loading functions should be declared. */

#endif

void AddCustomScripts()
{
#ifdef SCRIPTS
/* This is where custom scripts should be added. */

#endif
}
As we used this in our script:



Code:
void AddSC_test_commandscript()
{
new test_commandscript();
}
That's what we want to use in ScriptLoader.cpp so our script gets added to the server.

Modify the ScriptLoader.cpp so it looks like this;



Code:
#ifdef SCRIPTS
/* This is where custom scripts' loading functions should be declared. */
void AddSC_test_commandscript();
#endif

void AddCustomScripts()
{
#ifdef SCRIPTS
/* This is where custom scripts should be added. */
AddSC_test_commandscript();
#endif
}
When you're done with that, save ScriptLoader.cpp and save your test_command.cpp.
You can now start the compile.

When the compile is complete it should say something like this:



Code:
------ Build started: Project: ALL_BUILD, Configuration: Release Win32 ------
Build all projects
========== Build: 6 succeeded, 0 failed, 8 up-to-date, 0 skipped ==========
If you are running the server from the build folder and
worldserver.exe is up and running when you compile, the compile wont be
successful.
Close worldserver.exe and re-compile.

If you get any errors on the compile while your worldserver.exe is shut
down, you might want to read the tutorial again and check if you missed
something.
The script should work on latest rev of Trinity, but feel free to test it.

Open up worldserver.exe, login and write .test [Only admins are allowed to see this image]
Enjoy!

Here is a pastebin of the script we have just made: [Only admins are allowed to see this link]


Bottom line; I hope this tutorial was helpful. Please don't repost this and give yourself credits for it.


I might create and release a copy of Arena-Tournament (Abyssal WoW)'s
player commands if you guys want me to. (Changefaction, customize,
changerace, etc)


- Blex.


Join date : 1970-01-01

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum