diff options
Diffstat (limited to 'src/game/ScriptMgr.cpp')
-rw-r--r-- | src/game/ScriptMgr.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/game/ScriptMgr.cpp b/src/game/ScriptMgr.cpp index 26609430e27..05dc57f2a00 100644 --- a/src/game/ScriptMgr.cpp +++ b/src/game/ScriptMgr.cpp @@ -161,8 +161,34 @@ void Script::RegisterSelf() int id = GetScriptId(Name.c_str()); if (id) { - m_scripts[id] = this; - ++num_sc_scripts; + // try to find the script in assigned scripts + bool IsExist = false; + for (uint16 i = 0; i < MAX_SCRIPTS; ++i) + { + if (m_scripts[i]) + { + // if the assigned script's name and the new script's name is the same + if (m_scripts[i]->Name == Name) + { + IsExist = true; + break; + } + } + } + + // if the script doesn't assigned -> assign it! + if (!IsExist) + { + m_scripts[id] = this; + ++num_sc_scripts; + } + // if the script is already assigned -> delete it! + else + { + // TODO: write a better error message than this one :) + error_log("ScriptName: '%s' already assigned with the same ScriptName, so the script can't work.", Name.c_str()); + delete this; + } } else { |