Hi,
I have implemented basic code to load the names of mobs and NPC from a textfile located in locale/de, locale/en and so on.
Somehow my code doesn't seem to work properly but I don't know why.
The names of Mobs don't show ingame, so I assume that the MobNames Table I created is not filled correctly.
Bitte melden Sie sich an, um diesen Link zu sehen.
This is what I did:
Code: PythonApplication.cpp - LoadLocaleData
- [...]
- char szItemList[256];
- char szItemProto[256];
- char szItemDesc[256];
- char szMobProto[256];
- char szSkillDescFileName[256];
- char szSkillTableFileName[256];
- char szInsultList[256];
- #ifdef ENABLE_NAMES_FROM_TXT
- char szMobNames[256];
- #endif // ENABLE_NAMES_FROM_TXT
- [...]
- #ifdef ENABLE_NAMES_FROM_TXT
- snprintf(szMobNames, sizeof(szMobNames), "%s/mob_list.txt", localePath);
- #endif // ENABLE_NAMES_FROM_TXT
- [...]
- #ifdef ENABLE_NAMES_FROM_TXT
- if (!rkNPCMgr.LoadMobNames(szMobNames))
- {
- TraceError("LoadLocaleData - LoadMobNames(%s) Error", szMobNames);
- return false;
- }
- #endif
- [...]
Code: PythonNonPlayer.cpp
- #ifdef ENABLE_NAMES_FROM_TXT
- bool CPythonNonPlayer::LoadMobNames(const char* c_szFileName)
- {
- const VOID* pvData;
- CMappedFile kFile;
- if (!CEterPackManager::Instance().Get(kFile, c_szFileName, &pvData))
- {
- Tracenf("CItemManager::LoadMobNames(c_szFileName=%s) - Load Error", c_szFileName);
- return false;
- }
- CMemoryTextFileLoader kTextFileLoader;
- kTextFileLoader.Bind(kFile.Size(), pvData);
- std::string stTemp;
- CTokenVector kTokenVector;
- for (DWORD i = 0; i < kTextFileLoader.GetLineCount(); ++i)
- {
- CPythonNonPlayer::TMobNames t = { 0 };
- if (!kTextFileLoader.SplitLineByTab(i, &kTokenVector))
- continue;
- while (kTokenVector.size() < 2)
- kTokenVector.push_back("");
- DWORD dwVnum = atoi(kTokenVector[0].c_str());
- const std::string& c_localeName = kTokenVector[1];
- TMobNames* pTable = &t;
- TMobNames* pNonPlayerData = new TMobNames;
- memcpy(pNonPlayerData, pTable, sizeof(TMobNames));
- m_MobNamesDataMap.insert(TMobNamesDataMap::value_type(pNonPlayerData->dwVnum, pNonPlayerData));
- }
- return true;
- }
- #endif
- [...]
- bool CPythonNonPlayer::GetName(DWORD dwVnum, const char ** c_pszName)
- {
- #ifdef ENABLE_NAMES_FROM_TXT
- const TMobNames* p = GetNamesTable(dwVnum);
- if (!p)
- return false;
- *c_pszName = p->szLocaleName;
- return true;
- #else
- const TMobTable * p = GetTable(dwVnum);
- if (!p)
- return false;
- *c_pszName = p->szLocaleName;
- return true;
- #endif
- }
- [...]
- #ifdef ENABLE_NAMES_FROM_TXT
- const CPythonNonPlayer::TMobNames* CPythonNonPlayer::GetNamesTable(DWORD dwVnum)
- {
- TMobNamesDataMap::iterator itor = m_MobNamesDataMap.find(dwVnum);
- if (itor == m_MobNamesDataMap.end())
- return NULL;
- return itor->second;
- }
- #endif // ENABLE_NAMES_FROM_TXT
Code: PythonNonPlayer.h
- [...]
- #ifdef ENABLE_NAMES_FROM_TXT
- typedef struct SMobNames
- {
- DWORD dwVnum;
- char szLocaleName[CHARACTER_NAME_MAX_LEN + 1];
- } TMobNames;
- #endif // ENABLE_NAMES_FROM_TXT
- [...]
- #ifdef ENABLE_NAMES_FROM_TXT
- typedef std::map<DWORD, TMobNames*> TMobNamesDataMap;
- #endif
- [...]
- #ifdef ENABLE_NAMES_FROM_TXT
- bool LoadMobNames(const char* c_szFileName);
- #endif
- const TMobTable * GetTable(DWORD dwVnum);
- #ifdef ENABLE_NAMES_FROM_TXT
- const TMobNames * GetNamesTable(DWORD dwVnum);
- #endif
- [...]
Maybe someone sees some issues within the CPythonNoNPlayer::LoadMobnames method?
Thanks in advance