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

Solved How to get gained experience

VirrageS

←•†ĿuĀ && ©¤¤•→
Joined
May 30, 2010
Messages
984
Reaction score
63
Location
Poland
Hello

How in title is way to get gained exerience (white number after kill monster).

I want to use it like this but I don't know how to return it:


Lua:
doPlayerSendCancel(cid, 'You gained '.. xxxx ..' experience.')



Thanks so much for helping. ^_^
 
Last edited:
Lua:
function onKill(cid, target, lastHit)
	if not(isPlayer(cid) and isMonster(target)) then
		return true
	end
	local exp = getConfigInfo('rateExperience')
	if getBooleanFromString(getConfigInfo('experienceStages') then
		exp = getExperienceStage(getPlayerLevel(cid), getVocationInfo(getPlayerVocation(cid)).experienceMultiplier)
	end
	
	doPlayerSendCancel(cid, 'You gained ' .. getMonsterInfo(getCreatureName(target)).experience*exp .. ' experience.')
	return true
end
 
Not matter that I must to add new function but problem is which function :p

In creature.cpp (1283-1285; 1305-1307) there is function which showing this exp


Code:
	std::stringstream ss;
	ss << (uint64_t)gainExp;
	g_game.addAnimatedText(getPosition(), (uint8_t)color, ss.str());

Is way to use it in lua function I mean return ss.str() or something else??
 
Luascript.cpp:

[cpp] //getDamageRatio(cid, target)
lua_register(m_luaState, "getDamageRatio", LuaInterface::luaDoGetDamageRatio);
[/cpp]


[cpp]int32_t LuaInterface::luaDoGetDamageRatio(lua_State* L) // Damage Ratio
{
//getDamageRatio(cid, target)
ScriptEnviroment* env = getEnv();

Creature* target = env->getCreatureByUID(popNumber(L));
if(!target)
{
errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
lua_pushboolean(L, false);
return 1;
}

Creature* player = env->getPlayerByUID(popNumber(L));
if(!player)
{
errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushboolean(L, false);
return 1;
}

lua_pushnumber(L, target->getDamageRatio(player));
return 1;
}[/cpp]

luascript.h:
[cpp]static int32_t luaDoGetDamageRatio(lua_State* L); // Damage Ratio[/cpp]

Now what to do:
Create a onKill script and register it onLogin to the player (as every script)
Put in the script:
Lua:
function onKill(cid, target, lastHit)
	registerCreatureEvent(target, "showExp")
	return true
end

Create another creaturescript:
XML:
	<event type="death" name="showExp" event="script" value="YOURFILE.lua"/>
and put in:
Lua:
function onDeath(cid, corpse, deathList)
	for i = 1, #deathList do
		if isPlayer(deathList[i]) then
			local exp = getConfigInfo('rateExperience')
			if getBooleanFromString(getConfigInfo('experienceStages')) then
				exp = getExperienceStage(getPlayerLevel(deathList[i]), getVocationInfo(getPlayerVocation(deathList[i])).experienceMultiplier)
			end
			local expgain = exp*getDamageRatio(deathList[i], cid)*getMonsterInfo(getCreatureName(cid)).experience
			doPlayerSendTextMessage(deathList[i], MESSAGE_INFO_DESCR, "You gained ".. expgain .." experience.")
		end
	end
	return true
end

You also need to check whether the player has 1.5exp because of stamina shit. That isn't included.
 
I can't try it now because I'm on my friend's computer. :(
But I think that it will work. ^_^



Thanks and rep++
:thumbup:
 
@zakius
ofc it is :D no one would like to register to every single monster xD

@topic
it works
 
Put onKill script in a file, register the file in creaturescripts.xml and then register it in login.lua too. The death event doesn't need to be registered onLogin only on kill
 
I have done every thing that you say and not working.

I solved it problem was in message i changed "MessageClasses" and every thing working perfectly.

Thanks so much :rolleyes:
 
Last edited:
Back
Top