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

Creating Custom Commands

View previous topic View next topic Go down

default Creating Custom Commands

Post   on Mon Jul 09, 2012 6:27 pm

Maybe you want to make custom commands sometime for your server. Look here and learn:


void onCommand(Player * pPlayer, uint32 Type, uint32 Lang, const char * Message, const char * Misc)
{
if(Message == "#command") //If player message is #command do followning
{
pPlayer->EventTeleport(MAPID, X, Y, Z);
}
}
void SetupCommand(ScriptMgr * Mgr)
{
mgr->register_hook(SERVER_HOOK_EVENT_ON_CHAT, &onCommand); //Register the command
}


Here is the Explanation: (sorry, couldn't write it before, hadn't the time)

This is for the first a C++ script, just compile it to make it work.

void onCommand(Player * pPlayer, uint32 Type, uint32 Lang, const char * Message, const char * Misc)

this line over here, You declare the void
OnCommand, so you can call this function later in any other function.
This line is much more interesting:

if(Message == "#command")

so If player Message is (==) #command, then we do followning between these two { }

so it should look like this by now

void onCommand(Player * pPlayer, uint32 Type, uint32 Lang, const char * Message, const char * Misc)
{
if(Message == "#command")
{

Here we can code anything you want the player to do when entering the command. In this case we use an Teleport Event.

pPlayer->EventTeleport(MAPID, X, Y, Z);

MapID = The mapid of the map.
X = the X location.
Y = the Y location.
Z = the Z location.

just type .gps
ingame to get these Coordinates at the spot your standing.

So this far we have declared an function, and if the player says: #command, you get teleported to your location.

But it ain't far from done yet, so we end the IF section with this character:

}

The script should look like this now :

void onCommand(Player * pPlayer, uint32 Type, uint32 Lang, const char * Message, const char * Misc)
{
if(Message == "#command")
{
pPlayer->EventTeleport(MAPID, X, Y, Z);
}


but now we have to finish the Function by another { letter:

void onCommand(Player * pPlayer, uint32 Type, uint32 Lang, const char * Message, const char * Misc)
{
if(Message == "#command")
{
pPlayer->EventTeleport(MAPID, X, Y, Z);
}
}

So now we just did a simple function. Now we only
have to Register the function so it works ingame, we do that by another
function:

void SetupCommand(ScriptMgr * Mgr)
{



The server call this function inside the DLL, just to register the #command event.

Now we have to register the command event. Do that by typing this in the SetupCommand function:

mgr->register_hook(SERVER_HOOK_EVENT_ON_CHAT, &onCommand);

Note the white text, this text right here calls our earlier function OnCommand, just by placing character & in front of it.

Now we have done the command event, and soon the SetupCommand event, just by finishing it with this character }

}

Now it should look like this :

void onCommand(Player * pPlayer, uint32 Type, uint32 Lang, const char * Message, const char * Misc)
{
if(Message == "#command")
{
pPlayer->EventTeleport(MAPID, X, Y, Z);
}
}
void SetupCommand(ScriptMgr * Mgr)
{
mgr->register_hook(SERVER_HOOK_EVENT_ON_CHAT, &onCommand);
}


We have just written an .cpp script, hurray!
You just have to compile it to get it ingame. It is a bunch of compiler guides here at mmowned. Here is one of them:

[Only admins are allowed to see this link]


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