muito grande, deu ate preguiça de ler mas Parece um sistema muito bom, parabéns
- Fórum
- OTServ
- Recursos
- Linguagens de Programação
- doCreateMonsterNick(monster, nick, pos)
doCreateMonsterNick(monster, nick, pos)
Por caotic, 24 de jan. de 2014 em Linguagens de Programação
Muito obrigado, eu estava atras dessa função já tinha algum tempo!
info
Grupo: Visconde
Registrado: 04/11/12
Posts: 464
Reputação: +90
Gênero: Masculino
Char no Tibia: Lysty Of Death

isso nao causaria um erro?
ScriptEnvir oment* env = getEnv();
nao seria assim não?
ScriptEnviroment* env = getEnv();
info
Grupo: Infante
Registrado: 04/03/11
Posts: 1.6k
Reputação: +393
Char no Tibia: No Have

isso nao causaria um erro?
ScriptEnvir oment* env = getEnv();nao seria assim não?
ScriptEnviroment* env = getEnv();
Deve ser na hora de eu copiar e acabei clicando em espaço sem perceber
Editado Janeiro 24 por caotic
Era por isso que eu não conseguia compilar :s
info
Grupo: Lenda
Registrado: 03/10/06
Posts: 2.6k
Reputação: +309
Gênero: Masculino
Char no Tibia: Knight Orion

Eu trocaria
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);
}por
Monster* Monster::createMonsterNick(const std::string& name, std::string nick) {
MonsterType* mType = g_monsters.getMonsterType(name);
if(!mType || nick.empty())
return NULL;
mType->name = nick;
return createMonster(mType);
}Porque não vejo utilidade na função se for dado um "nick" vazio. Assim você mata um if e algumas linhas.
Também dá pra reduzir um pouco aqui e continuar legível:
Monster* Monster::createMonster(const std::string& name) {
MonsterType* mType = g_monsters.getMonsterType(name);
if(!mType)
return NULL;
return createMonster(mType);
}por
Monster* Monster::createMonster(const std::string& name) {
MonsterType* mType = g_monsters.getMonsterType(name);
return mType ? createMonster(mType) : NULL;
}
info
Grupo: Infante
Registrado: 04/03/11
Posts: 1.6k
Reputação: +393
Char no Tibia: No Have

Eu trocaria
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); }porMonster* Monster::createMonsterNick(const std::string& name, std::string nick) { MonsterType* mType = g_monsters.getMonsterType(name); if(!mType || nick.empty()) return NULL; mType->name = nick; return createMonster(mType); }Porque não vejo utilidade na função se for dado um "nick" vazio. Assim você mata um if e algumas linhas.
Também dá pra reduzir um pouco aqui e continuar legível:
Monster* Monster::createMonster(const std::string& name) { MonsterType* mType = g_monsters.getMonsterType(name); if(!mType) return NULL; return createMonster(mType); }porMonster* Monster::createMonster(const std::string& name) { MonsterType* mType = g_monsters.getMonsterType(name); return mType ? createMonster(mType) : NULL; }
if(!mType || nick.empty()) return NULL;
A possiblidade do cara colocar uma string vazia logo o mType do monstro seria ignorado.
Diminuição de linha é encheção de linguiça.
Editado Janeiro 25 por caotic
info
Grupo: Conde
Registrado: 20/09/12
Posts: 711
Reputação: +86
Char no Tibia: noé

Realmente otimo este codigo, parabens
Alguém testo em serve de pokemon PDA e funciona?
@nociam
Cara, como alguém vai adicionar essa função no PDA sem as sources?
kkkk Isso já tem no PDA.
info
Grupo: Herói
Registrado: 12/06/12
Posts: 1k
Reputação: +362
Gênero: Masculino
Char no Tibia: Aarow

Belo sistema Caotic
irei testar aqui ![]()
Eu não entendi muito bem.
Ele da 1 nick ao monster? Isso quer dizer o que exatamente? .-.
Troca o nome dele por outro?











info
Grupo: Infante
Registrado: 04/03/11
Posts: 1.6k
Reputação: +393
Char no Tibia: No Have
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();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:
Adicionar embaixo:
Vá em luascript.h e procure isto
Embaixo coloque:
Em luascript.cpp procure:
Coloque embaixo:
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:
Editado Março 11 por caotic