• 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 setPlayerExpRate(cid, rate)

EvulMastah

๏̯͡๏﴿
Premium User
Joined
Aug 19, 2007
Messages
4,941
Solutions
11
Reaction score
352
This was made by Umby

So, lets start.

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

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)) * expRate);

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

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

Add this

Code:
uint32_t getExpRate() const {return expRate;}
void changePlayerExpRate(uint32_t rate);

BELOW
Code:
int32_t idleTime;

Add this
Code:
uint32_t expRate;

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()->getExpRate()) : ((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, "setPlayerExpRate", LuaScriptInterface::luaSetPlayerExpRate);

At the BOTTOM of luascript.cpp add this
Code:
int32_t LuaScriptInterface::luaSetPlayerExpRate(lua_State *L)
{    
    uint32_t rate = popNumber(L);                    
    uint32_t cid = popNumber(L);            	
    ScriptEnviroment* env = getScriptEnv();	    
    Player* player = env->getPlayerByUID(cid);	       
            	
       if(player){    
			player->changePlayerExpRate(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 luaSetPlayerExpRate(lua_State* L);



How does it work?

- It gets configs expRate and multiply it by functions expRate.

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

function onDeEquip(cid, item)
 	setPlayerExpRate(cid, 1)
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 for someone with booster on it will give 35 * 4 = 140 exp.

AND AGAIN - ALL CREDITS TO UMBY
 
Last edited:
Really nice and usefull :)

Should be perfect with getPlayerExpRate too :)
 
amazing code but if the server dont have Experience Stage, u must replace
Code:
return (uint64_t)std::floor(getDamageRatio(attacker) * lostExperience * g_config.getNumber(ConfigManager::RATE_EXPERIENCE));
with
Code:
return attacker->getPlayer() ? (((uint64_t)std::floor(getDamageRatio(attacker) * lostExperience)) * attacker->getPlayer()->getExpRate()) : ((uint64_t)std::floor(getDamageRatio(attacker) * lostExperience * g_config.getNumber(ConfigManager::RATE_EXPERIENCE)));
 
Last edited:
This is a great code, good job! I'm going to use it for sure..
 
This was made based by a script Umby, only did some minor changes

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 :)
 
This was made based by a script Umby, only did some minor changes

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 :)

Can made this code for Clean SVN???? Please Thank you!
 
I've asked Umby to create this function for clean SVN too on your requests and I suppose he will do it, since he dont know how to deny :thumbup:
 
thank you men, i will wait the clean svn version ^^ and how i can make a account manager for clean svn? the last one
 
Account Manager in-game?
No idea, else look at otfans for their project.
 
Last edited:
and do you know how make account easy in sqlite? (aac web page or software?)
 
Umby said:
on the other hand, for clean SVN -
in the old tutorial everything will be the same except
in creature.cpp
change this:

to this:
Code:
return attacker->getPlayer() ? ((int32_t)std::floor((getDamageRatio(attacker) * lostExperience * g_config.getNumber(ConfigManager::RATE_EXPERIENCE)) * attacker->getPlayer()->getExpRate())) : ((int32_t)std::floor(getDamageRatio(attacker) * lostExperience * g_config.getNumber(ConfigManager::RATE_EXPERIENCE)));

everything else should be the same
(maybe the tutorial will need edits if i used any TFS-only variables to direct where to paste in the original).

Try if that works.
 
Going to use this to my server :) pretty cool for low exp servers (even for high exp)
 
Back
Top