Tudo bem galera xtibiana?
Resolvi trazer a vocês um sistema de nick que permite mudar o nome do monstro in-game.
A função e simples de se usar e não tem nenhum tipo de limitação ela foi desenvolvida na versão 8.6 com a tfs 0.3.6.
Lets go:
Vá em monster.h e procure isto:
typedef std::list<Creature*> CreatureList; class Monster : public Creature { private: Monster(MonsterType* _mType); public: #ifdef __ENABLE_SERVER_DIAGNOSTIC__ static uint32_t monsterCount; #endif virtual ~Monster();
std::string nick,realname;
static Monster* createMonster(const std::string& name);
static Monster* createMonsterNick(const std::string& name, std::string nick);
virtual const std::string& getName() const {return mType->name;}
virtual const std::string& getName() const {return nick;}
Depois vá em monster.cpp e procure:
Monster* Monster::createMonster(const std::string& name) { MonsterType* mType = g_monsters.getMonsterType(name); if(!mType) return NULL; return createMonster(mType); }
Monster* Monster::createMonster(const std::string& name) { MonsterType* mType = g_monsters.getMonsterType(name); if(!mType) return NULL; mType->name = name; return createMonster(mType); } Monster* Monster::createMonsterNick(const std::string& name, std::string nick) { MonsterType* mType = g_monsters.getMonsterType(name); if(!mType) return NULL; if (!(nick == "")) { mType->name = nick; } return createMonster(mType); }
Continuando em monster.cpp procure:
currentOutfit = mType->outfit;
Adicionar embaixo:
nick = mType->name;
Vá em luascript.h e procure isto
static int32_t luaDoCreateNpc(lua_State* L);
Embaixo coloque:
static int32_t luaDoCreateMonsterNick(lua_State* L); static int32_t luaGetCreatureNickRealName(lua_State* L);
Em luascript.cpp procure:
//doPlayerSetIdleTime(cid, amount) lua_register(m_luaState, "doPlayerSetIdleTime", LuaScriptInterface::luaDoPlayerSetIdleTime);
Coloque embaixo:
//doCreateMonster(monster, nick, pos) lua_register(m_luaState, "doCreateMonsterNick", LuaScriptInterface::luaDoCreateMonsterNick);
Continue em luascript.cpp e procure isto:
int32_t LuaScriptInterface::luaGetCreatureName(lua_State* L) { //getCreatureName(cid) ScriptEnviroment* env = getEnv(); if(Creature* creature = env->getCreatureByUID(popNumber(L))) lua_pushstring(L, creature->getName().c_str()); else { errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND)); lua_pushboolean(L, false); } return 1; }
Coloque isto:
int32_t LuaScriptInterface::luaGetCreatureNickRealName(lua_State* L) { //getCreatureNickRealName(cid) ScriptEnviroment* env = getEnv(); if(Monster* monster = env->getCreatureByUID(popNumber(L))->getMonster()) lua_pushstring(L, monster->realname.c_str()); else { errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND)); lua_pushboolean(L, false); } return 1; } int32_t LuaScriptInterface::luaDoCreateMonsterNick(lua_State* L) { //doCreateMonsterNick(monster, nick, pos) ScriptEnviroment* env = getEnv(); PositionEx pos; popPosition(L, pos); std::string nick = popString(L); const std::string name = popString(L).c_str(); Monster* monster = Monster::createMonsterNick(name, nick); if(!monster) { errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND)); lua_pushboolean(L, false); return 1; } if(!g_game.placeCreature(monster, pos)) { delete monster; errorEx("Cannot create monster: " + name); lua_pushboolean(L, false); return 1; } monster->realname = name; lua_pushnumber(L, env->addThing((Thing*)monster)); return 1; }
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Exemplo de uso:
function onSay(cid, words, param, channel) local t = string.explode(param, ",") doCreateMonsterNick(t[1], t[2], getThingPos(cid)) return true end