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

If you use TFS 0.3, this function is already there:
Code:
getPlayerExtraExpRate(cid)
setPlayerExtraExpRate(cid, value)
 
@up Yep mine too
I'll gonna check it but i'm not sure should i use that what "ponei" wrote. TFS 0.2 mystic spirit has experience stage? ohhh i think yes ; )

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)));
 
i did search something like this like 6 months ago rly usefull for donators
 
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)) * exp

i am using the last sources 0.31, but doens't have this line
 
To everyone who has the crash issue!


Replace


Code:
int 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;
}

With

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

I've tested it and I get inside the game, It wont crash and it compiled fine.
I haven't tested the function though. I'll do it as soon as possible and report back to you.

Edit: Yes, works flawlessly. Nemaneth, you should add this to your tutorial.

Feel free to show your gratitude through repping me :)
 
Last edited:
Anyone know how I can make this % instead of * ?
I've tried adding 1.2 that equals 20% but wont work.
 
this compatible with 0.2.7?

Sorry for double post but I haven't received an answer...
 
Back
Top