mirror of
https://github.com/liyunfan1223/azerothcore-wotlk.git
synced 2026-08-08 15:58:04 +00:00
fix(doc): cleanup outdated documentation in ScriptMgr.h (#5488)
* Update ScriptMgr.h * Update ScriptMgr.h
This commit is contained in:
@@ -72,6 +72,7 @@ struct TargetInfo;
|
|||||||
|
|
||||||
#define VISIBLE_RANGE 166.0f //MAX visible range (size of grid)
|
#define VISIBLE_RANGE 166.0f //MAX visible range (size of grid)
|
||||||
|
|
||||||
|
// Check out our guide on how to create new hooks in our wiki! https://www.azerothcore.org/wiki/hooks-script
|
||||||
/*
|
/*
|
||||||
TODO: Add more script type classes.
|
TODO: Add more script type classes.
|
||||||
|
|
||||||
@@ -81,72 +82,6 @@ struct TargetInfo;
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
Standard procedure when adding new script type classes:
|
|
||||||
|
|
||||||
First of all, define the actual class, and have it inherit from ScriptObject, like so:
|
|
||||||
|
|
||||||
class MyScriptType : public ScriptObject
|
|
||||||
{
|
|
||||||
uint32 _someId;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void RegisterSelf();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
MyScriptType(const char* name, uint32 someId)
|
|
||||||
: ScriptObject(name), _someId(someId)
|
|
||||||
{
|
|
||||||
ScriptRegistry<MyScriptType>::AddScript(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// If a virtual function in your script type class is not necessarily
|
|
||||||
// required to be overridden, just declare it virtual with an empty
|
|
||||||
// body. If, on the other hand, it's logical only to override it (i.e.
|
|
||||||
// if it's the only method in the class), make it pure virtual, by adding
|
|
||||||
// = 0 to it.
|
|
||||||
virtual void OnSomeEvent(uint32 someArg1, std::string& someArg2) { }
|
|
||||||
|
|
||||||
// This is a pure virtual function:
|
|
||||||
virtual void OnAnotherEvent(uint32 someArg) = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Next, you need to add a specialization for ScriptRegistry. Put this in the bottom of
|
|
||||||
ScriptMgr.cpp:
|
|
||||||
|
|
||||||
template class ScriptRegistry<MyScriptType>;
|
|
||||||
|
|
||||||
Now, add a cleanup routine in ScriptMgr::~ScriptMgr:
|
|
||||||
|
|
||||||
SCR_CLEAR(MyScriptType);
|
|
||||||
|
|
||||||
Now your script type is good to go with the script system. What you need to do now
|
|
||||||
is add functions to ScriptMgr that can be called from the core to actually trigger
|
|
||||||
certain events. For example, in ScriptMgr.h:
|
|
||||||
|
|
||||||
void OnSomeEvent(uint32 someArg1, std::string& someArg2);
|
|
||||||
void OnAnotherEvent(uint32 someArg);
|
|
||||||
|
|
||||||
In ScriptMgr.cpp:
|
|
||||||
|
|
||||||
void ScriptMgr::OnSomeEvent(uint32 someArg1, std::string& someArg2)
|
|
||||||
{
|
|
||||||
FOREACH_SCRIPT(MyScriptType)->OnSomeEvent(someArg1, someArg2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScriptMgr::OnAnotherEvent(uint32 someArg)
|
|
||||||
{
|
|
||||||
FOREACH_SCRIPT(MyScriptType)->OnAnotherEvent(someArg1, someArg2);
|
|
||||||
}
|
|
||||||
|
|
||||||
Now you simply call these two functions from anywhere in the core to trigger the
|
|
||||||
event on all registered scripts of that type.
|
|
||||||
*/
|
|
||||||
|
|
||||||
class ScriptObject
|
class ScriptObject
|
||||||
{
|
{
|
||||||
friend class ScriptMgr;
|
friend class ScriptMgr;
|
||||||
|
|||||||
Reference in New Issue
Block a user