• 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!

CreatureEvent [CreatureEvent/Npc] Killing in the name of... [All monsters, all tasks with rewards]

Maybe I found the source of the bug ( literally lol source ~ sources *-* )

creature.cpp 0.3b1pl1
Code:
void Creature::onKilledCreature(Creature* target)
{
	if(getMaster())
		getMaster()->onKilledCreature(target);

	//scripting event - onKill
	CreatureEvent* eventKill = getCreatureEvent(CREATURE_EVENT_KILL);
	if(eventKill)
		eventKill->executeOnKill(this, target);
}

creature.cpp 0.4

Code:
bool Creature::onKilledCreature(Creature* target, DeathEntry& entry)
{		
	bool ret = true;
	if(master)
		ret = master->onKilledCreature(target, entry);

	CreatureEventList killEvents = getCreatureEvents(CREATURE_EVENT_KILL);
	if(!entry.isLast())
	{
		for(CreatureEventList::iterator it = killEvents.begin(); it != killEvents.end(); ++it)
			(*it)->executeKill(this, target, entry);

		return true;
	}

	for(CreatureEventList::iterator it = killEvents.begin(); it != killEvents.end(); ++it)
	{
		if(!(*it)->executeKill(this, target, entry) && ret)
			ret = false;
	}

	return ret;
}

creatureevent.cpp 0.4
Code:
	//onKill(cid, target, damage, flags)
	if(m_interface->reserveEnv())
	{
		uint32_t flags = 0;
		if(entry.isLast())
			flags |= 1;

		if(entry.isJustify())
			flags |= 2;

		if(entry.isUnjustified())
			flags |= 4;

		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 << "local target = " << env->addThing(target) << std::endl;
			scriptstream << "local damage = " << entry.getDamage() << std::endl;
			scriptstream << "local flags = " << flags << std::endl;
#ifdef __WAR_SYSTEM__
			scriptstream << "local war = " << entry.getWar().war << std::endl;
#endif

			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));
			lua_pushnumber(L, env->addThing(target));

			lua_pushnumber(L, entry.getDamage());
			lua_pushnumber(L, flags);
#ifndef __WAR_SYSTEM__

			bool result = m_interface->callFunction(4);
#else
			lua_pushnumber(L, entry.getWar().war);

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

uint32_t CreatureEvent::executeDeath(Creature* creature, Item* corpse, DeathList deathList)
{

creatureevent.cpp 0.3b1pl1
Code:
	//onKill(cid, target)
	if(m_scriptInterface->reserveScriptEnv())
	{
		ScriptEnviroment* env = m_scriptInterface->getScriptEnv();

		#ifdef __DEBUG_LUASCRIPTS__
		std::stringstream desc;
		desc << creature->getName();
		env->setEventDesc(desc.str());
		#endif

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

		uint32_t cid = env->addThing(creature);
		uint32_t targetId = env->addThing(target);

		lua_State* L = m_scriptInterface->getLuaState();

		m_scriptInterface->pushFunction(m_scriptId);
		lua_pushnumber(L, cid);
		lua_pushnumber(L, targetId);

		int32_t result = m_scriptInterface->callFunction(2);
		m_scriptInterface->releaseScriptEnv();

		return (result == LUA_TRUE);
	}
	else
	{
		std::cout << "[Error - CreatureEvent::executeOnKill] Call stack overflow." << std::endl;
		return 0;
	}
}

uint32_t CreatureEvent::executeOnDeath(Creature* creature, Item* corpse, Creature* lastHitKiller, Creature* mostDamageKiller)
{

So, I've tried to add that code on creature.cpp to 0.4 but didn't work.

Based on this there's any modification I can do to make it work? (Both in script or sources) I'll keep trying here, but if you could take a look at the codes and give me a light, I would be very grateful!

Edit

An screenshot of the error message I receive when add onkill function to creature.cpp on 0.4:

http://img256.imageshack.us/img256/7420/63661316.jpg
 
Last edited:
It doesn't work for me on 0.4. When I kill a monster it doesn't count. I have tried everything and I did everything you told us to do. Im getting really frustrated..
Please help me!
 
Guys, i think it won't work on 0.4, because i haven't tested the scripts on that distro, you must w8 until 0.4 get released for public and, when it happens, i will update the scripts.
 
Guys, i think it won't work on 0.4, because i haven't tested the scripts on that distro, you must w8 until 0.4 get released for public and, when it happens, i will update the scripts.

then i dont know why! when i update to 0.4 and it's working, didnt test all but do some task and count monster killed ok:)

--> 0.4 Now!
Code:
16:13 1 Troll defeated. Total [1/100] Trolls.
16:13 Kjra: exevo gran mas frigo
16:13 2 Troll defeated. Total [2/100] Trolls.
16:13 3 Troll defeated. Total [3/100] Trolls.
16:14 4 Troll defeated. Total [4/100] Trolls.
16:14 5 Troll defeated. Total [5/100] Trolls.
16:14 6 Troll defeated. Total [6/100] Trolls.
16:14 7 Troll defeated. Total [7/100] Trolls.
16:14 8 Troll defeated. Total [8/100] Trolls.
16:14 9 Troll defeated. Total [9/100] Trolls.
16:14 10 Troll defeated. Total [10/100] Trolls.
 
Lol yea, darkhaos can you please make it so that you can cancel the task. I wanna make this an event on my serv.
 
Hello,

i have read every post in this thread. I did everything according to your description.

I had the same problam as Xoriak. My distro didn't have the functions "getCreatureStorage" and "doCreatureSetStorage", so I changed it to "getPlayerStorageValue" and "doPlayerSetStorageValue".

That works now.

but now i get another error in my Server console:

Lua Script Error: [Npc interface]
data/npc/scripts/killinginthenameof.lua:eek:nThink

luagetDistanceTo(). Thing not found

Lua Script Error: [Npc interface]
data/npc/scripts/killinginthenameof.lua:eek:nThink

luaCloseShopWindow(). Player not found

I checked the monster names in the scripts and they are equal

do i have to change onThink to something else?

Can you help me?

Thank you in advance

Edit: I use TFS 8.54
 
Last edited:
Hello,

i have read every post in this thread. I did everything according to your description.

I had the same problam as Xoriak. My distro didn't have the functions "getCreatureStorage" and "doCreatureSetStorage", so I changed it to "getPlayerStorageValue" and "doPlayerSetStorageValue".

That works now.

but now i get another error in my Server console:

Lua Script Error: [Npc interface]
data/npc/scripts/killinginthenameof.lua:eek:nThink

luagetDistanceTo(). Thing not found

Lua Script Error: [Npc interface]
data/npc/scripts/killinginthenameof.lua:eek:nThink

luaCloseShopWindow(). Player not found

I checked the monster names in the scripts and they are equal

do i have to change onThink to something else?

Can you help me?

Thank you in advance

Edit: I use TFS 8.54

You have a problem with your npc lib, not my script.
 
you are right

i used mystic spirit 0.2.7, as soon as i changed to tfs 0.3.6 it works perfectly

thx man realy nice
 
Back
Top