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

Lua Function Add a higher exprate when using an items

Rizz

Quited with Tibia/OT
Joined
Jun 16, 2007
Messages
573
Reaction score
4
Location
Stockholm, Sweden
This was made based by a script Umby, only did some minor changes (changed some math more or less only)

Warning! Not Tested! But it SHOULD work :)

So, lets start.

in player.cpp
BELOW
Code:
idleTime = 0;
ADD
Code:
extraExpRate = 0;

Then find this:
Code:
return (result * g_config.getNumber(ConfigManager::RATE_EXPERIENCE) );

and REPLACE with this:
Code:
return (result * (g_config.getNumber(ConfigManager::RATE_EXPERIENCE) + extraExpRate));

At the BOTTOM of player.cpp add this
Code:
void Player::changePlayerExtraExpRate(uint32_t rate)
{
	extraExpRate = rate;
}

Now in player.h
BELOW
Code:
void resetIdleTime() {idleTime = 0;}

Add this

Code:
uint32_t getExtraExpRate() const {return extraExpRate;}
void changePlayerExtraExpRate(uint32_t rate);

BELOW
Code:
int32_t idleTime;

Add this
Code:
uint32_t extraExpRate;

In creature.cpp find this:
Code:
return attacker->getPlayer() ? ((uint64_t)std::floor(getDamageRatio(attacker) * lostExperience * g_game.getExperienceStage(attacker->getPlayer()->getLevel()))) : ((uint64_t)std::floor(getDamageRatio(attacker) * lostExperience * g_config.getNumber(ConfigManager::RATE_EXPERIENCE) ));

and REPLACE it with
Code:
return attacker->getPlayer() ? (((uint64_t)std::floor(getDamageRatio(attacker) * lostExperience * (g_game.getExperienceStage(attacker->getPlayer()->getLevel()) + attacker->getPlayer()->getExtraExpRate())))
) : ((uint64_t)std::floor(getDamageRatio(attacker) * lostExperience * g_config.getNumber(ConfigManager::RATE_EXPERIENCE)));

In the luascript.cpp
BELOW
Code:
lua_register(m_luaState, "escapeString", LuaScriptInterface::luaEscapeString);

Add this
Code:
lua_register(m_luaState, "setPlayerExtraExpRate", LuaScriptInterface::luaSetPlayerExtraExpRate);

At the BOTTOM of luascript.cpp add this
Code:
int LuaScriptInterface::luaSetPlayerExtraExpRate(lua_State *L)
{    
    uint32_t rate = popNumber(L);                    
    uint32_t cid = popNumber(L);            	
    ScriptEnviroment* env = getScriptEnv();	    
    Player* player = env->getPlayerByUID(cid);	       
            	
       if(player){    
			player->changePlayerExtraExpRate(rate);
            lua_pushnumber(L, LUA_ERROR);
       }    
       else{       
           reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
           lua_pushnumber(L, LUA_ERROR);
       }       
    return 1;
}

And in luascript.h
BELOW
Code:
static int32_t luaEscapeString(lua_State* L);

Add this
Code:
static int32_t luaSetPlayerExtraExpRate(lua_State* L);


Simple example:
data/movements/scripts/booster.lua
Code:
function onEquip(cid, item)
        setPlayerExtraExpRate(cid, 1)
end

function onDeEquip(cid, item)
 	setPlayerExtraExpRate(cid, 0)
end

data/movements/movements.xml
Code:
	<movevent event="Equip" itemid="2179" slot="ring" function="onEquipItem" script="booster.lua"/>
	<movevent event="DeEquip" itemid="2179" slot="ring" function="onDeEquipItem" script="booster.lua"/>

ID 2179 is a gold ring.

So if "Rat" on your server gives 35 exp (7x) for someone with booster on it will give 35 + 5 (exp in monster file) = 40 exp (8x).

AND AGAIN - BASED ON A SCRIPT BY UMBY

P.s. basicly copied the text too :)

P.p.s. You should be able to add BOTH codes ("Mine" and Umby's") to your source without any problem.
 
Didnt you actually just change the name from `expRate` to `extraExpRate` and instead of multiplying (*) you have switched to summing (+) ?
 
Yes he did, anyways it's nice tho... You don't always want to multiply :)
 
@marcinek

Chagned the order of operations a bit (added brackers, moved some varibales) to make it work with + instead of *.
 
It's a nice work, i remember on a game i played called Tales of Pirates, when you reach level 20 you get an experience apple that will increase your experience rate by 1x ~ 2x for a remaing time of 15 minutes.
 
In creature.cpp find this:
Code:
return attacker->getPlayer() ? ((uint64_t)std::floor(getDamageRatio(attacker) * lostExperience * g_game.getExperienceStage(attacker->getPlayer()->getLevel()))) : ((uint64_t)std::floor(getDamageRatio(attacker) * lostExperience * g_config.getNumber(ConfigManager::RATE_EXPERIENCE) ));

and REPLACE it with
Code:
return attacker->getPlayer() ? (((uint64_t)std::floor(getDamageRatio(attacker) * lostExperience * (g_game.getExperienceStage(attacker->getPlayer()->getLevel()) + attacker->getPlayer()->getExtraExpRate())))
) : ((uint64_t)std::floor(getDamageRatio(attacker) * lostExperience * g_config.getNumber(ConfigManager::RATE_EXPERIENCE)));

That's not in creature.cpp (TFS 0.2.5) :confused:
Red
 
Does this script have any timeout, or is it permanent? >.<
Nowadays we use doPlayerSetRate(cid, SKILL__LEVEL, 1.extra) and the timeout? when player logs out or dies extra exp is gone
 
Im trying to compile on 8.62
the only diference is on this part
on this part:

Code:
Then find this:
Code:
[CODE]return (result * g_config.getNumber(ConfigManager::RATE_EXPERIENCE[COLOR="red"]) )[/COLOR];
and REPLACE with this:
Code:
Code:
return (result * (g_config.getNumber(ConfigManager::RATE_EXPERIENCE) + extraExpRate));
[/CODE]
on 8.62, there isnt space betwen the red things. i saw that the diference was + extraExp... then just added it and didnt put spaces. now im compiling, and will tell u if worked or not. if works, u can use for 8.62 too :D
 
Back
Top