From afb3e790de943692e88fd5e8f539acda82aad704 Mon Sep 17 00:00:00 2001 From: Spp Date: Wed, 3 Nov 2010 08:44:03 +0100 Subject: [PATCH] Core/Scripts: add example_commandscript as an example of how to use commandscripts to add your own commands to the core Patch by Paradox Closes issue 4630 --HG-- branch : trunk --- src/server/game/Scripting/ScriptLoader.cpp | 2 + src/server/scripts/Examples/CMakeLists.txt | 1 + .../Examples/example_commandscript.cpp | 60 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 src/server/scripts/Examples/example_commandscript.cpp diff --git a/src/server/game/Scripting/ScriptLoader.cpp b/src/server/game/Scripting/ScriptLoader.cpp index 0c26428c8d8..7060de9bcd3 100755 --- a/src/server/game/Scripting/ScriptLoader.cpp +++ b/src/server/game/Scripting/ScriptLoader.cpp @@ -24,6 +24,7 @@ void AddSC_example_creature(); void AddSC_example_escort(); void AddSC_example_gossip_codebox(); void AddSC_example_misc(); +void AddSC_example_commandscript(); // spells void AddSC_deathknight_spell_scripts(); @@ -586,6 +587,7 @@ void AddExampleScripts() AddSC_example_escort(); AddSC_example_gossip_codebox(); AddSC_example_misc(); + AddSC_example_commandscript(); } void AddSpellScripts() diff --git a/src/server/scripts/Examples/CMakeLists.txt b/src/server/scripts/Examples/CMakeLists.txt index 2808ec0bfaf..dfd65e8dbae 100644 --- a/src/server/scripts/Examples/CMakeLists.txt +++ b/src/server/scripts/Examples/CMakeLists.txt @@ -5,6 +5,7 @@ set(scripts_STAT_SRCS Examples/example_escort.cpp Examples/example_creature.cpp Examples/example_spell.cpp + Examples/example_commandscript.cpp ) message(" -> Prepared: Examples") diff --git a/src/server/scripts/Examples/example_commandscript.cpp b/src/server/scripts/Examples/example_commandscript.cpp new file mode 100644 index 00000000000..eca3d113861 --- /dev/null +++ b/src/server/scripts/Examples/example_commandscript.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2008-2010 TrinityCore + * Copyright (C) 2006-2009 ScriptDev2 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +/* ScriptData +Name: Example_Commandscript +%Complete: 100 +Comment: Short custom scripting example +Category: Script Examples +EndScriptData */ + +#include "ScriptPCH.h" +#include "Chat.h" + +// **** This script is designed as an example for others to build on **** +// **** Please modify whatever you'd like to as this script is only for developement **** + +// **** Script Info **** +// This script's primary purpose is to show just how much you can really do with commandscripts + +class example_commandscript : public CommandScript +{ + public: + example_commandscript() : CommandScript("example_commandscript") { } + + static bool HandleHelloWorldCommand(ChatHandler* handler, const char* /*args*/) + { + handler->PSendSysMessage("Hello World"); + return true; + } + + ChatCommand* GetCommands() const + { + static ChatCommand HelloWorldCommandTable[] = + { + { "hello", SEC_PLAYER, true, &HandleHelloWorldCommand, "", NULL }, + { NULL, 0, false, NULL, "", NULL } + }; + return HelloWorldCommandTable; + } +}; + +void AddSC_example_commandscript() +{ + new example_commandscript(); +}