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

Compiling implement onkill

knightxd

Member
Joined
Feb 21, 2009
Messages
211
Reaction score
16
Location
Rio de Janeiro
solved ~ close plz



Hey guys, i was trying to make an onKill script that executes an action by loading the damage done on the monster killed, its working just fine as executing the action, but its the same action for everybody, don't matter how much damage they did on it.

example, if i and a friend get a dragon down, and i did 800 damage and he 200, we get the same rewards, i was looking at tfs 0.4 source and i found "onKill(cid, target, damage, flags)", this one in 0.3.6 is "onKill(cid, target, lasthit)" i've tryed to mix it some times, but i get no result but errors...

anyone knows how to add damage to 0.3.6 source??
hope someone can find it a way :thumbup:

here 0.4 onkill

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

and here 0.3.6 one

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;
	}
}
 
Last edited:
Made it but damage only returns damage from player's last hit, not total ;|
KGo test on 0.4

i've just tested on 0.4 with mcs..

i used this script...

function onKill(cid, target, damage, flags)
if isMonster(target) then
dano = damage
doPlayerSay(cid, ""..dano.."", TALKTYPE_SAY)
end
return true
end

and with 1 character, when i killed a wolf it returns..
19:54 Testador [173]: 25 (that is right)
also, with both characters killing a dragon it returns..
19:59 Testador [173]: 479
19:59 Tester [165]: 648 (the damage that each one dealt - conting the dragon healing)
and also, i've tested another time with 3 mcs..
20:06 Testador [173]: 395
20:06 Tester [165]: 660
20:06 Testerx [219]: 108
and another time, killing a behemoth.. with one characters and one hit of each other..
20:11 Tester [162]: 3868
20:11 Testador [173]: 61
20:11 Testerx [216]: 71

well i think its working on 0.4 :X
 
Back
Top Bottom