Ir para conteúdo
Entre para seguir isso  
iuniX

CreatureEvent: onSpawn

Recommended Posts

iuniX    4
iuniX

Estou entediado e vou postar um script que precisa disso, então ai vai.

 

 

Nome: CreatureEvent: onSpawn

Autor: Doggynub

Versão: 0.4

Explicação: Um creature event que executa quando o MOB da respawn.

 

 

Vá até creatureEvent.h e procure:

uint32_t executePrepareDeath(Creature* creature, DeathList deathList);

 

E coloque embaixo:

 uint32_t executeOnSpawn(Creature* creature);

 

Depois procure:

CREATURE_EVENT_DEATH,

 

E coloque:

CREATURE_EVENT_PREPAREDEATH,
CREATURE_EVENT_SPAWN

 

 

Agora vá até creatureevent.cpp e procure:

else if(tmpStr == "preparedeath")
	m_type = CREATURE_EVENT_PREPAREDEATH;

 

Abaixo disso, coloque:

else if(tmpStr == "spawn")
	m_type = CREATURE_EVENT_SPAWN;

 

Procure:

case CREATURE_EVENT_PREPAREDEATH:
		return "onPrepareDeath";

 

E coloque abaixo:

 case CREATURE_EVENT_SPAWN:
		return "onSpawn";

 

Procure:

case CREATURE_EVENT_PREPAREDEATH:
		return "cid, deathList";

 

e coloque abaixo:

 case CREATURE_EVENT_SPAWN:
		return "cid";

 

Vá até o final do arquivo e coloque:

uint32_t CreatureEvent::executeOnSpawn(Creature* creature)
{

//onSpawn(cid)
if(m_interface->reserveEnv())
{
	ScriptEnviroment* env = m_interface->getEnv();
	if(m_scripted == EVENT_SCRIPT_BUFFER)
	{
		env->setRealPos(creature->getPosition());
		std::stringstream scriptstream;


		scriptstream << "local cid = " << env->addThing(creature) << std::endl;



		if(m_scriptData)
			scriptstream << *m_scriptData;


		bool result = true;
		if(m_interface->loadBuffer(scriptstream.str()))
		{
			lua_State* L = m_interface->getState();
			result = m_interface->getGlobalBool(L, "_result", true);
		}


		m_interface->releaseEnv();
		return result;
	}
	else
	{
		#ifdef __DEBUG_LUASCRIPTS__
		std::stringstream desc;
		desc << creature->getName();
		env->setEvent(desc.str());
		#endif


		env->setScriptId(m_scriptId, m_interface);
		env->setRealPos(creature->getPosition());


		lua_State* L = m_interface->getState();
		m_interface->pushFunction(m_scriptId);


		lua_pushnumber(L, env->addThing(creature));


		bool result = m_interface->callFunction(1);
		m_interface->releaseEnv();
		return result;
	}
}
else
{
	std::clog << "[Error - CreatureEvent::executeCast] Call stack overflow." << std::endl;
	return 0;
}
}

 

 

Agora vá até monsters.cpp e procure:

 

void Monster::onCreatureAppear(const Creature* creature)
{
Creature::onCreatureAppear(creature);
if(creature == this)
{
	//We just spawned lets look around to see who is there.
	if(isSummon())
		isMasterInRange = canSee(master->getPosition());

 

Abaixo disso, de uns 2 enters para descer linhas e coloque isso:

CreatureEventList spawn = getCreatureEvents(CREATURE_EVENT_SPAWN);
	for(CreatureEventList::iterator it = spawn.begin(); it != spawn.end(); ++it)
		(*it)->executeOnSpawn(this);

 

 

Pronto, bjs

Compartilhar este post


Link para o post
vdzz    15
vdzz

Muito bom. Assim dá até para colocar um sistema de "level" nos monstros.

Valeu por compartilhar.

Compartilhar este post


Link para o post
Visitante
Este tópico está impedido de receber novos posts.
Entre para seguir isso  
  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×