• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Feature [CreatureEvent] OnSpawn(cid)

Doggynub

LUA / C++
Joined
Sep 28, 2008
Messages
2,541
Reaction score
186
well based on a request, this event occur when the monster is summoned, created, spawned w/e


using this to Register any monster
Code:
<event type="spawn" name="monsterThink" registerTo ="monster" event="script" value="look.lua"/>
Lua:
function onSpawn(cid)
	doBroadcastMessage("Monster ".. getCreatureName(cid).." was created.")
	return true
end


Support : 0.4


Setup :


#goto creatureEvent.h :


find [cpp]uint32_t executePrepareDeath(Creature* creature, DeathList deathList);[/cpp]


under it paste [cpp] uint32_t executeOnSpawn(Creature* creature);[/cpp]


find
[cpp]CREATURE_EVENT_DEATH,[/cpp]


replace the line under it with this
[cpp]CREATURE_EVENT_PREPAREDEATH,
CREATURE_EVENT_SPAWN [/cpp]
---------------------------------------------------------------------------------------------------------------------


#goto creatureevent.cpp


find [cpp]else if(tmpStr == "preparedeath")
m_type = CREATURE_EVENT_PREPAREDEATH;[/cpp]


under it paste[cpp]else if(tmpStr == "spawn")
m_type = CREATURE_EVENT_SPAWN; [/cpp]


find [cpp] case CREATURE_EVENT_PREPAREDEATH:
return "onPrepareDeath";[/cpp]


under it paste[cpp] case CREATURE_EVENT_SPAWN:
return "onSpawn";[/cpp]
find [cpp]case CREATURE_EVENT_PREPAREDEATH:
return "cid, deathList";[/cpp]


under itpaste [cpp] case CREATURE_EVENT_SPAWN:
return "cid"; [/cpp]


go to the end of file and paste this
[cpp]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;
}
}
[/cpp]


----------------------------------------------------------------------------------------------------------


# goto monster.cpp


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


under it ##press enter key to move down a line or 2## then paste[cpp] CreatureEventList spawn = getCreatureEvents(CREATURE_EVENT_SPAWN);
for(CreatureEventList::iterator it = spawn.begin(); it != spawn.end(); ++it)
(*it)->executeOnSpawn(this); [/cpp]




And you are done.
 
Last edited:
nah, when you kill a monster and he is summoned back, when you summon a monster.
 
No matter! I saw your other posts with this and found that i need! thanks!
 
you should use parentheses here:
Code:
if(isSummon())
some people probably wont get it to work...
 
error on compiling:

Code:
xx\creatureevent.cpp In member function `uint32_t CreatureEvent::executeOnSpawn(Creature*)': 
xx\creatureevent.cpp could not convert `((Event*)this)->Event::m_scriptData' to `bool' 
xx\creatureevent.cpp no match for 'operator*' in '*((Event*)this)->Event::m_scriptData' 
xx\Makefile.win [Build Error]  [obj//creatureevent.o] Error 1

help-me

my sources is tfs 0.3.6
 
as you do not have to make sure I can add it to 0.3.6

or at least tell me a way to edit the monsters of the hunts without
to do for globalevents.


I really need this function, and I can not change the version of my server
because the project is already very advanced.
 
I got some erros, can u help me?

Code:
creatureevent.cpp: In member function ‘uint32_t CreatureEvent::executeOnSpawn(Creature*)’:
creatureevent.cpp:1867: error: could not convert ‘((CreatureEvent*)this)->CreatureEvent::<anonymous>.Event::m_scriptData’ to ‘bool’
creatureevent.cpp:1868: error: no match for ‘operator*’ in ‘*((CreatureEvent*)this)->CreatureEvent::<anonymous>.Event::m_scriptData’
make[1]: *** [creatureevent.o] Error 1
make[1]: Leaving directory `/home/iunix/Área de Trabalho/Pakemão/trunk.r3777'
make: *** [all] Error 2
I'm trying compile in Linux Mint Julia
 
Sorry to revive the topic,
but I need a lot of it, would not stage it to 0.3.6?
I think many here would appreciate
thank you
 
I managed to get it to compile in 0.3.6 - But I am not completely sure if it works yet.

at the bottom of creatureevent.cpp where you paste
Code:
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;
	}
}

PASTE THIS INSTEAD:

Code:
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;
 
 
 
			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;
	}
}

If someone would like to test it and let me know, I would appreciate it.
 
ArkSeyonet

Thank you, ironically the most angry I've been waiting for this review all of the code and by coincidence I fis the same thing.
Yet thanks
 
Back
Top