doCreateMonsterNick(monster, nick, pos)

caotic
Por caotic
em Linguagens de Programação
  • 1
  • 2

caotic

Afinal de contas,sou um mordomo e tanto
avatar
Infante
Infante

INFOS

Grupo: InfanteRegistrado: 04/03/11Posts: 1599Char 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();
E coloque este codigo em baixo:
std::string nick,realname;
Continue em monster.h e procure:
static Monster* createMonster(const std::string& name);
E coloque embaixo:
static Monster* createMonsterNick(const std::string& name, std::string nick);
Procure também:
virtual const std::string& getName() const {return mType->name;}
E substitua por isto:
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);
}
Substitua por:
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

Shoguns

avatar
Conde
Conde

INFOS

Grupo: CondeRegistrado: 09/10/13Posts: 604

muito grande, deu ate preguiça de ler mas Parece um sistema muito bom, parabéns

 
Nao sei

 

Hyaki

avatar
Artesão
Artesão

INFOS

Grupo: ArtesãoRegistrado: 11/01/14Posts: 108Char no Tibia: Rhynd

Muito obrigado, eu estava atras dessa função já tinha algum tempo!

Strogman

avatar
Visconde
Visconde

INFOS

Grupo: ViscondeRegistrado: 04/11/12Posts: 464Gênero: MasculinoChar no Tibia: Lysty Of Death

isso nao causaria um erro?

ScriptEnvir oment* env = getEnv();

 

nao seria assim não?

ScriptEnviroment* env = getEnv();

 

                                 logo_full_1600.png.f8d0c5d8ba71c660bad630b327c3e64d.png

                                                              htps://www.facebook.com/PokemonOnlineSVKE

                                                                                                                       PokeSvke

caotic

Afinal de contas,sou um mordomo e tanto
avatar
Infante
Infante

INFOS

Grupo: InfanteRegistrado: 04/03/11Posts: 1599Char 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

Hyaki

avatar
Artesão
Artesão

INFOS

Grupo: ArtesãoRegistrado: 11/01/14Posts: 108Char no Tibia: Rhynd

Era por isso que eu não conseguia compilar :s

Lordfire

TFS Maintainer
avatar
Lenda
Lenda

INFOS

Grupo: LendaRegistrado: 04/10/06Posts: 2605Gênero: MasculinoChar 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;
}

caotic

Afinal de contas,sou um mordomo e tanto
avatar
Infante
Infante

INFOS

Grupo: InfanteRegistrado: 04/03/11Posts: 1599Char 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);
}
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;
}
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.

Maenilse

q manero em fera
avatar
Conde
Conde

INFOS

Grupo: CondeRegistrado: 21/09/12Posts: 711Char no Tibia: noé

Realmente otimo este codigo, parabens

nociam

avatar
Conde
Conde

INFOS

Grupo: CondeRegistrado: 04/02/13Posts: 541Gênero: Masculino

Alguém testo em serve de pokemon PDA e funciona?

zipter98

avatar
Herói
Herói

INFOS

Grupo: HeróiRegistrado: 20/09/12Posts: 2553Gênero: Masculino

@nociam

Cara, como alguém vai adicionar essa função no PDA sem as sources?

Não respondo PMs solicitando suporte. Já existem seções no fórum para isto.

Junior001

..................................
avatar
Herói
Herói

INFOS

Grupo: HeróiRegistrado: 12/06/12Posts: 1026Gênero: MasculinoChar no Tibia: Aarow

Belo sistema Caotic :D irei testar aqui :D

Atenciosamente, Junior Silva

 

 

 

 

 

 

 
 

 

T67thPC.png
 
 
 
 
 
 

LuaniTa

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 23/08/12Posts: 31

Eu não entendi muito bem.

Ele da 1 nick ao monster? Isso quer dizer o que exatamente? .-.

Troca o nome dele por outro?

Você é apenas uma gota em um oceano infinito..

E o que é o oceano se não uma infinidade de gotas?

A VIAGEM

nociam

avatar
Conde
Conde

INFOS

Grupo: CondeRegistrado: 04/02/13Posts: 541Gênero: Masculino

Uhm falei errado tenho as sources do pda versao 5 ai gostaria de saber se isso pode funcionar.


Entao tem esse erro nao aparece o nome de nenhum mostro

y0qs.png

  • 1
  • 2