#include "Script.h"
#include "ScriptMgr.h"
#include "ObjectMgr.h"
#include "MapManager.h"
#include "Chat.h"
#include <fstream>
#include <string>
class spawn_commandscript : public CommandScript { // class name must be same as file name (case sensitive) & inherit from CommandScript !!! you can change the class name but then you have to make changes in the .cpp file too !!! like in the OnGossipHello function! and also in cmakeliststxt!
class spawn_commandscript : public CommandScript { // class name must be same as file name (case sensitive) & inherit from CommandScript !!! you can change the class name but then you have to make changes in the .cpp file too !!! like in the OnGossipHello function! and also in cmakeliststxt! //and also change it here: #include "spawn_commandscript.h" to #include "newname_commandscript.h" !!!!! & don't forget to add it into CMakeLists.txt!!!!!! & don't forget that when adding new commandscripts, usually need to register them at bottom of this file: Scripts/worldserver/Server/MainServerDefines.cpp ! ! ! ! ! ! ! & don't forget that if command script has some custom functions, they should go into worldserver/scripts/Custom folder!!!!!!!!!!!!!! or if they are global, add them into worldserver/scripts/Global folder!!!!!!!!!!!!!
public: //public so other classes can use these functions (in this case only WorldSession uses it)
spawn_commandscript(); //constructor - called when object is created
static std::vector<ChatCommand> GetCommands() { //function which returns vector of commands which will be used by Eluna (see Eluna Readme for more info about Eluna)
static std::vector<ChatCommand> creatureSpawnCommandTable = //static so we can access it globally without creating object each time we want to use it vector of commands - each command is represented by struct ChatCommand with fields for command name, security level required for this command and pointer to function which will be executed when player types this command note that all commands MUST have UNIQUE names!!!!!! if there are 2 commands with same names, only 1 will work and another one won't work!!!!!!!!! note2 - security level means how high GM level player must have so he could use this command 0 = all players can use it 1 = Gamemasters can use it 2 = admins (console) can use it 3 = only owners of server can use it note3 - pointer to function is set at bottom of this page where all functions linked with chatcommands are defined !!!!! note4 - there are many more fields available for chatcommands but we dont need them now :) see ChatCommand struct definition at top of page: Server\Protocol\Opcodes\WorldOpcodes.h line 1058-1068 or just google ChatCommand structure :) these fields are used by eluna engine so dont touch them unless you know what u r doing ;) also read eluna readme before touching anything ;) note5 - after adding new chatcommands here remember to register them at bottom of this file: Scripts/worldserver/Server/MainServerDefines.cpp !!!!! or else they wont work!!!!! remember about unique names!!!!! example1: { "mycmd", SECURITY_ADMINISTRATOR, &HandleMyCmd }, example2: { NULL, 0, NULL } <- do not remove this line! its used by eluna engine as end marker for array of ChatCommands btw i think best way is just copy existing entry and modify its values :) last thing before starting making your own commands -> READ ELUNA README FILE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ok? ok :) let's start making our own commands now :D first let's define our own structure which will store data about creature spawning typedef struct _CreatureSpawnData -> typedef means we create our own type named _CreatureSpawnData which is actually a struct _CreatureSpawnData typedef struct _CreatureSpawnData -> _CreatureSpawnData is just a random unique name i chose { -> opening bracket means start defining structure body uint32 entry; -> uint32 means unsigned 32bit integer variable type float x; -> float variable type float y; -> float variable type float z; -> float variable type float o; -> float variable type uint32 delay; -> unsigned 32bit integer variable type } CreatureSpawnData; -> closing bracket plus CreatureSpawnData tells compiler that we finished defining body of structure named CreatureSpawnData and now we assign alias CreatureSpawnData so instead typing long StructName everytime we want create instance of our structure we just write CreatureSapwnData :) ok? cool :D let's move on :D next step would be creating a handler function which will handle our custom console command remember that handler functions always take 3 arguments : char* args , WorldSession* m_session , int id char* args - contains arguments passed with console command WorldSession* m_session - contains pointer to current session object int id - no idea what its used for lolz xD i never used id argument lolz xD lets define handler funtion prototype first above GetCommands() function like this : static bool HandleMyCmd(const char *args , WorldSession *m_session , int /*str*/); const char *args means args argument passed trought console contains const char * data type WorldSession *m_session means m session argument passed trought console contains pointer tp WorldSession object data type /*str*/ part tells compiler that third argument exists but since its not used lets ignore him ;) next step would be writing actual code inside HandleMyCmd() handler funtion body remeber Handler funtions always return bool value true or false depending on success or failure execution ;) lets start writing code inside HandleMyCmd() funtion body like this :
创作工场
免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。
点击这里>>使用🔥专业版,更聪明、更完整、更原创!