PDA

View Full Version : Understanding Custom Commands



Crux
02-09-08, 02:05 AM
Custom Commands are quite tricky to understand, and also difficult to make if you do not know what your doing. We're going to be using a command "#rezz" Author: Dark Alex.
First, just take a look through his script, study it.

//---------------------
// Name: Playercommands
// Author: Darkalex
//---------------------

#include "StdAfx.h"
#include "Setup.h"

static string rezzcmd = "#rezz"; //Revive Player-command
bool rezzon = true; //Will be switchable later ingame via GMCommand

void EventPlayerCommands(Player * pPlayer, uint32 Type, uint32 Lang, const char * Message, const char * Misc)
{
//#rezz-Command - Start
if(Message == rezzcmd)
{
if(rezzon)
if( rezzon ) { //You can add parameters where reviing is enabled here. e.g. for allowing it only on kalimdor and in Zone 123: (pPlayer->GetMapId() == 1 || pPlayer->GetZoneId() == 123)
if (pPlayer->GetUInt32Value(PLAYER_FIELD_COINAGE)>=7500) //Will cost 75 Silver (check if enough money)
{
pPlayer->SetUInt32Value(PLAYER_FIELD_COINAGE,(pPlayer->GetUInt32Value(PLAYER_FIELD_COINAGE) - 7500)); //Here 75 Silver is removed
sEventMgr.AddEvent(pPlayer, &Player::RemoteRevive, EVENT_PLAYER_REST, 1, 1,0);
} else pPlayer->BroadcastMessage("You don't have 75 silver in your backpack.");
} else
pPlayer->BroadcastMessage("You can't revive here!");
else
pPlayer->BroadcastMessage("You can't revive here!.");
}
//#rezz-Command end.
}


void SetupPlayerCommands(ScriptMgr * mgr)
{
mgr->register_hook(SERVER_HOOK_EVENT_ON_CHAT, (void *) EventPlayerCommands);
}Now, the first bit is pretty much the starting bit, mostly all scripts start with "StdAfx.h" and "Setup.h" (Dont forget to put these in!"

#include "StdAfx.h"
#include "Setup.h"

static string rezzcmd = "#rezz";
bool rezzon = true;

Now You see "#rezz"?? Thats what you type into game. Yes! Sure the scripting is difficult but easy for the players!
Dont need to mess around with true and false there, but say if you wanted to make a command that will enable you to use a command whilst in combat you can type something like Bypasscombat = false will make it so you cant use the command in combat, but placing false with true will make it so you can use it.

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

Now this part is everything you need to include for your script (Cant really explain it) But if you didnt want to explain anything You could write void EventPlayerCommands() the () is where you can place thing's like uint32 pPlayer etc.

if(Message == rezzcmd)
{
if(rezzon)
if( rezzon ) {
if (pPlayer->GetUInt32Value(PLAYER_FIELD_COINAGE)>=7500
{
Player->SetUInt32Value(PLAYER_FIELD_COINAGE,(pPlayer->GetUInt32Value(PLAYER_FIELD_COINAGE) - 7500));
sEventMgr.AddEvent(pPlayer, &Player::RemoteRevive, EVENT_PLAYER_REST, 1, 1,0);
} else pPlayer->BroadcastMessage("You don't have 75 silver in your backpack.");

Your probably thinking wow... I don't understand a word of this.. But it's actually quite simple.
Just ignore this part:

if(Message == rezzcmd)
{
if(rezzon)
if( rezzon ) {

You may add parameters if you wish, but if your a begginer just keep it simple!

if (pPlayer->GetUInt32Value(PLAYER_FIELD_COINAGE)>=7500
{
Player->SetUInt32Value(PLAYER_FIELD_COINAGE,(pPlayer->GetUInt32Value(PLAYER_FIELD_COINAGE) - 7500));

Now what this part does is tells the system to take 75 silver from your backpack, and throw it into mid-air! Well it just pays for your rezzing cost.

sEventMgr.AddEvent(pPlayer, &Player::RemoteRevive, EVENT_PLAYER_REST, 1, 1,0);
} else pPlayer->BroadcastMessage("You don't have 75 silver in your backpack.");

Oh NO! You don't have 75 silver in your backpack! Now you can't use your command.. That's pretty much what all that garbage does if you didnt have this it would take 75 silver regardless of you having enough money and the command would work!

} else
pPlayer->BroadcastMessage("You can't revive here!");
else
pPlayer->BroadcastMessage("You can't revive here!.");
}
}

This should be pretty simple to understand "You can't revive here!"

And the ending of the script..

void SetupPlayerCommands(ScriptMgr * mgr)
{
mgr->register_hook(SERVER_HOOK_EVENT_ON_CHAT, (void *) EventPlayerCommands);
}

Now.. Where it has PlayerCommands in the script change that to what ever you like! the SERVER_HOOK_EVENT_ON_CHAT will find the "#rezz" command and when you type this in game it will say.. hey that player just said #rezz to me.. I know what to do.. Ill rezz him at no cost to myself but charge him 75 silver !! MWahaaaaa
Now thats all! Post any questions/feedback you have!

Synthetic
02-09-08, 07:26 AM
That's so nice, very usefull for many people. Cus! it is VERY hard to make custom abilities without High-Script Knowledge.

Hephaestus
02-09-08, 07:45 AM
Thanks for the share.

StickyIcky
02-09-08, 01:26 PM
http://www.mmopro.net/forums/images/bluefox/buttons/reputation.gif for youuu

Crux
02-09-08, 11:57 PM
Thanks for feedback.
EDIT: You may post this guide on any forums as you wish, but don't forget the credits