Jump to content

Modifying GM commands


Guest Drako
 Share

Recommended Posts

hello guys,

I'm looking for a way of implementing my own gm commands to work with a little modification I've made.

So is there maybe a tutorial about that topic?

Or maybe you can give me some hints, what I will have to change to add custom GM commands

or where I have to look (maybe it's a database thing ;-))

regards

Drako

Link to comment
Share on other sites

You have to add the command to the big commands array in Chat.cpp (I believe) as well as code the actual command in one of the Level#.cpp files (or make your own CustomCommands.cpp) Then you have to put in the database stuff.

You need to know C++ to write commands. If you already know C++, just look at how the others are implemented.

Link to comment
Share on other sites

Well, I'll do you one better. If you look at Chat.cpp, scroll down past all the command sub-menu definitions and you'll find the main commands table:

 static ChatCommand commandTable[] =
   {
       { "account",        SEC_PLAYER,         true,  NULL,                                           "", accountCommandTable  },
       { "gm",             SEC_MODERATOR,      true,  NULL,                                           "", gmCommandTable       },
       { "npc",            SEC_MODERATOR,      false, NULL,                                           "", npcCommandTable      },
       { "go",             SEC_MODERATOR,      false, NULL,                                           "", goCommandTable       },
       { "learn",          SEC_MODERATOR,      false, NULL,                                           "", learnCommandTable    },
       { "modify",         SEC_MODERATOR,      false, NULL,                                           "", modifyCommandTable   },
       { "debug",          SEC_MODERATOR,      true,  NULL,                                           "", debugCommandTable    },
       { "tele",           SEC_MODERATOR,      true,  NULL,                                           "", teleCommandTable     },
       { "character",      SEC_GAMEMASTER,     false, NULL,                                           "", characterCommandTable},
       { "event",          SEC_GAMEMASTER,     false, NULL,                                           "", eventCommandTable    },
       { "gobject",        SEC_GAMEMASTER,     false, NULL,                                           "", gobjectCommandTable  },
       { "honor",          SEC_GAMEMASTER,     false, NULL,                                           "", honorCommandTable    },
       { "wp",             SEC_GAMEMASTER,     false, NULL,                                           "", wpCommandTable       },
       { "quest",          SEC_ADMINISTRATOR,  false, NULL,                                           "", questCommandTable    },
       { "reload",         SEC_ADMINISTRATOR,  true,  NULL,                                           "", reloadCommandTable   },
       { "list",           SEC_ADMINISTRATOR,  true,  NULL,                                           "", listCommandTable     },
       { "lookup",         SEC_ADMINISTRATOR,  true,  NULL,                                           "", lookupCommandTable   },
       { "pdump",          SEC_ADMINISTRATOR,  true,  NULL,                                           "", pdumpCommandTable    },
       { "guild",          SEC_ADMINISTRATOR,  true,  NULL,                                           "", guildCommandTable    },
       { "cast",           SEC_ADMINISTRATOR,  false, NULL,                                           "", castCommandTable     },
       { "reset",          SEC_ADMINISTRATOR,  true,  NULL,                                           "", resetCommandTable    },
       { "instance",       SEC_ADMINISTRATOR,  true,  NULL,                                           "", instanceCommandTable },
       { "server",         SEC_ADMINISTRATOR,  true,  NULL,                                           "", serverCommandTable   },

       { "aura",           SEC_ADMINISTRATOR,  false, &ChatHandler::HandleAuraCommand,                "", NULL },
       { "unaura",         SEC_ADMINISTRATOR,  false, &ChatHandler::HandleUnAuraCommand,              "", NULL },
       { "announce",       SEC_MODERATOR,      true,  &ChatHandler::HandleAnnounceCommand,            "", NULL },
       { "nameannounce",      SEC_MODERATOR,      false, &ChatHandler::HandleNameAnnounceCommand,       "", NULL },
       { "notify",         SEC_MODERATOR,      true,  &ChatHandler::HandleNotifyCommand,              "", NULL },
       { "goname",         SEC_MODERATOR,      false, &ChatHandler::HandleGonameCommand,              "", NULL },
       { "namego",         SEC_MODERATOR,      false, &ChatHandler::HandleNamegoCommand,              "", NULL },
       { "groupgo",        SEC_MODERATOR,      false, &ChatHandler::HandleGroupgoCommand,             "", NULL },
       { "commands",       SEC_PLAYER,         true,  &ChatHandler::HandleCommandsCommand,            "", NULL },
       { "demorph",        SEC_GAMEMASTER,     false, &ChatHandler::HandleDeMorphCommand,             "", NULL },
       { "die",            SEC_ADMINISTRATOR,  false, &ChatHandler::HandleDieCommand,                 "", NULL },
       { "revive",         SEC_ADMINISTRATOR,  true,  &ChatHandler::HandleReviveCommand,              "", NULL },
       { "dismount",       SEC_PLAYER,         false, &ChatHandler::HandleDismountCommand,            "", NULL },
       { "gps",            SEC_MODERATOR,      false, &ChatHandler::HandleGPSCommand,                 "", NULL },
       { "guid",           SEC_GAMEMASTER,     false, &ChatHandler::HandleGUIDCommand,                "", NULL },
       { "help",           SEC_PLAYER,         true,  &ChatHandler::HandleHelpCommand,                "", NULL },
       { "itemmove",       SEC_GAMEMASTER,     false, &ChatHandler::HandleItemMoveCommand,            "", NULL },
       { "cooldown",       SEC_ADMINISTRATOR,  false, &ChatHandler::HandleCooldownCommand,            "", NULL },
       { "unlearn",        SEC_ADMINISTRATOR,  false, &ChatHandler::HandleUnLearnCommand,             "", NULL },
       { "distance",       SEC_ADMINISTRATOR,  false, &ChatHandler::HandleGetDistanceCommand,         "", NULL },
       { "recall",         SEC_MODERATOR,      false, &ChatHandler::HandleRecallCommand,              "", NULL },
       { "save",           SEC_PLAYER,         false, &ChatHandler::HandleSaveCommand,                "", NULL },
       { "saveall",        SEC_MODERATOR,      true,  &ChatHandler::HandleSaveAllCommand,             "", NULL },
       { "kick",           SEC_GAMEMASTER,     true,  &ChatHandler::HandleKickPlayerCommand,          "", NULL },
       { "ban",            SEC_ADMINISTRATOR,  true,  NULL,                                           "", banCommandTable      },
       { "unban",          SEC_ADMINISTRATOR,  true,  NULL,                                           "", unbanCommandTable    },
       { "baninfo",        SEC_ADMINISTRATOR,  false, NULL,                                           "", baninfoCommandTable  },
       { "banlist",        SEC_ADMINISTRATOR,  true,  NULL,                                           "", banlistCommandTable  },
       { "start",          SEC_PLAYER,         false, &ChatHandler::HandleStartCommand,               "", NULL },
       { "taxicheat",      SEC_MODERATOR,      false, &ChatHandler::HandleTaxiCheatCommand,           "", NULL },
       { "linkgrave",      SEC_ADMINISTRATOR,  false, &ChatHandler::HandleLinkGraveCommand,           "", NULL },
       { "neargrave",      SEC_ADMINISTRATOR,  false, &ChatHandler::HandleNearGraveCommand,           "", NULL },
       { "explorecheat",   SEC_ADMINISTRATOR,  false, &ChatHandler::HandleExploreCheatCommand,        "", NULL },
       { "hover",          SEC_ADMINISTRATOR,  false, &ChatHandler::HandleHoverCommand,               "", NULL },
       { "levelup",        SEC_ADMINISTRATOR,  false, &ChatHandler::HandleLevelUpCommand,             "", NULL },
       { "showarea",       SEC_ADMINISTRATOR,  false, &ChatHandler::HandleShowAreaCommand,            "", NULL },
       { "hidearea",       SEC_ADMINISTRATOR,  false, &ChatHandler::HandleHideAreaCommand,            "", NULL },
       { "additem",        SEC_ADMINISTRATOR,  false, &ChatHandler::HandleAddItemCommand,             "", NULL },
       { "additemset",     SEC_ADMINISTRATOR,  false, &ChatHandler::HandleAddItemSetCommand,          "", NULL },
       { "bank",           SEC_ADMINISTRATOR,  false, &ChatHandler::HandleBankCommand,                "", NULL },
       { "wchange",        SEC_ADMINISTRATOR,  false, &ChatHandler::HandleChangeWeather,              "", NULL },
       { "ticket",         SEC_GAMEMASTER,     true,  &ChatHandler::HandleTicketCommand,              "", NULL },
       { "delticket",      SEC_GAMEMASTER,     true,  &ChatHandler::HandleDelTicketCommand,           "", NULL },
       { "maxskill",       SEC_ADMINISTRATOR,  false, &ChatHandler::HandleMaxSkillCommand,            "", NULL },
       { "setskill",       SEC_ADMINISTRATOR,  false, &ChatHandler::HandleSetSkillCommand,            "", NULL },
       { "whispers",       SEC_MODERATOR,      false, &ChatHandler::HandleWhispersCommand,            "", NULL },
       { "pinfo",          SEC_GAMEMASTER,     true,  &ChatHandler::HandlePInfoCommand,               "", NULL },
       { "respawn",        SEC_ADMINISTRATOR,  false, &ChatHandler::HandleRespawnCommand,             "", NULL },
       { "send",           SEC_MODERATOR,      true,  NULL,                                           "", sendCommandTable     },
       { "loadscripts",    SEC_ADMINISTRATOR,  true,  &ChatHandler::HandleLoadScriptsCommand,         "", NULL },
       { "mute",           SEC_MODERATOR,      true,  &ChatHandler::HandleMuteCommand,                "", NULL },
       { "unmute",         SEC_MODERATOR,      true,  &ChatHandler::HandleUnmuteCommand,              "", NULL },
       { "movegens",       SEC_ADMINISTRATOR,  false, &ChatHandler::HandleMovegensCommand,            "", NULL },
       { "cometome",       SEC_ADMINISTRATOR,  false, &ChatHandler::HandleComeToMeCommand,            "", NULL },
       { "damage",         SEC_ADMINISTRATOR,  false, &ChatHandler::HandleDamageCommand,              "", NULL },
       { "combatstop",     SEC_GAMEMASTER,     false, &ChatHandler::HandleCombatStopCommand,          "", NULL },
       { "flusharenapoints",SEC_ADMINISTRATOR, false, &ChatHandler::HandleFlushArenaPointsCommand,    "", NULL },
       { "repairitems",    SEC_GAMEMASTER,     true,  &ChatHandler::HandleRepairitemsCommand,         "", NULL },
       { "waterwalk",      SEC_GAMEMASTER,     false, &ChatHandler::HandleWaterwalkCommand,           "", NULL },

       { NULL,             0,                  false, NULL,                                           "", NULL }

The first argument is the command name, the second is the security level (it's hardcoded for whatever reason) the third is whether or not it's allowed in the console, and the fourth is a pointer to it's handler function (you can ignore the other 2 arguments)

Now, simply code the handler function in one of the Level files (or, like I said, you can make your own file for your commands) and add it to that table. Then, insert the entry in `world`.`commands` for it.

Link to comment
Share on other sites

ok, now there is a new question for me...

I want a command to work in this way:

a Game-Master (gmlevel >= 1) can use it on other characters

but a normal player should only be able to use it on himself.

getting the gmlevel shouldn't be that hard, but how can I determine the "caster" of the command?

so I could do something like

if ((target == caster) || (gmlevel >= 1))
// OK
else
// no permission!

like explained, the gmlevel part is easy... but the caster part...

just don't know how to get a pointer to the player that casts the command :-(

would be nice, if someone could show me the right way here :D

regards

Drako

Link to comment
Share on other sites

Well, sure. If you look at the other commands, such as in Level1.cpp:

bool ChatHandler::HandleGonameCommand(const char* args)
{
   Player* target;
   uint64 target_guid;
   std::string target_name;
   if (!extractPlayerTarget((char*)args,&target,&target_guid,&target_name))
       return false;

   Player* _player = m_session->GetPlayer();
   if (target == _player || target_guid == _player->GetGUID())
   {
       SendSysMessage(LANG_CANT_TELEPORT_SELF);
       SetSentErrorMessage(true);
       return false;
   }

You'll see that here, the targeted player is taken from extractPlayerTarget() and assigned to target, and the player using the command, _player, is taken from m_session->GetPlayer(). You can just use this in your command.

Link to comment
Share on other sites

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use