• 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 Changing the functions in sources or fix Lua script?

War-Ots

New Member
Joined
Feb 17, 2016
Messages
29
Reaction score
2
Hi!
Well I know I a bit of c++ because I learned alot of C, but I'm not too used the sources of the servers and the API tfs 1.2 (I still need to understand better how does it works) so it give me have arisen following doubts:

I was working on a function in my PVP-E server, to balance the exp gained on kill. I had a Lua script that was easy to 'fix' this exp problem but I had a problem in that script. When for example: 3 players kill 1, this 3 players will recive the same exp, that is, imagine that this player that died gives 100 exp all this 3 players that killed him will recive each one 100 exp, well that is not correct!

I had something like this code here:
Code:
local experience = attackPlayer:getExperience()
                local expFormula = (experience * expMultiplier)
                local bonusExpFormula = (experience * bonusExpMultiplier)

                player:addExperience(math.floor(expFormula), true)

Then I figured out that what was missing is the damageRatio each players deals in the fight, but as far as I know that function is only available in sources so I went to my sources to solve the problem.
Then I found this :
Code:
uint64_t Player::getGainedExperience(Creature* attacker) const
{
if (g_config.getBoolean(ConfigManager::EXPERIENCE_FROM_PLAYERS)) {
Player* attackerPlayer = attacker->getPlayer();
if (attackerPlayer && attackerPlayer != this && skillLoss && std::abs(static_cast<int32_t>(attackerPlayer->getLevel() - level)) <= g_config.getNumber(ConfigManager::EXP_FROM_PLAYERS_LEVEL_RANGE)) {

return std::max<uint64_t>(0, std::floor(getLostExperience() * getDamageRatio(attacker) *0,75));
}
}
}
return 0;
}
This function is the config.lua exp recived when you kill a player and that works preaty fine for me BUT! I wanted something more, I would like to add to this function a new parameter that is Creature* target and with this target I could do a new formula to calculate the exp recived when you kill someone.

My question here is: Is it easier to fix the lua script? (how? I am not used to this TFS API as I said and I dont know how to do I would be very happy if someone could give me an example for this case)

Or how can I add a new parameter to the function and use it? (I know that I have to put that new parameter in the function lib but how I am gonna tell to the program what is that target?)

I hope I was clear any problem about this post comment below and I will for sure answer ASAP.

Thanks and sorry something I am still getting used to Otland and to ot servers world :)
 
Hi!
Well I know I a bit of c++ because I learned alot of C, but I'm not too used the sources of the servers and the API tfs 1.2 (I still need to understand better how does it works) so it give me have arisen following doubts:

I was working on a function in my PVP-E server, to balance the exp gained on kill. I had a Lua script that was easy to 'fix' this exp problem but I had a problem in that script. When for example: 3 players kill 1, this 3 players will recive the same exp, that is, imagine that this player that died gives 100 exp all this 3 players that killed him will recive each one 100 exp, well that is not correct!

I had something like this code here:
Code:
local experience = attackPlayer:getExperience()
                local expFormula = (experience * expMultiplier)
                local bonusExpFormula = (experience * bonusExpMultiplier)

                player:addExperience(math.floor(expFormula), true)

Then I figured out that what was missing is the damageRatio each players deals in the fight, but as far as I know that function is only available in sources so I went to my sources to solve the problem.
Then I found this :
Code:
uint64_t Player::getGainedExperience(Creature* attacker) const
{
if (g_config.getBoolean(ConfigManager::EXPERIENCE_FROM_PLAYERS)) {
Player* attackerPlayer = attacker->getPlayer();
if (attackerPlayer && attackerPlayer != this && skillLoss && std::abs(static_cast<int32_t>(attackerPlayer->getLevel() - level)) <= g_config.getNumber(ConfigManager::EXP_FROM_PLAYERS_LEVEL_RANGE)) {

return std::max<uint64_t>(0, std::floor(getLostExperience() * getDamageRatio(attacker) *0,75));
}
}
}
return 0;
}
This function is the config.lua exp recived when you kill a player and that works preaty fine for me BUT! I wanted something more, I would like to add to this function a new parameter that is Creature* target and with this target I could do a new formula to calculate the exp recived when you kill someone.

My question here is: Is it easier to fix the lua script? (how? I am not used to this TFS API as I said and I dont know how to do I would be very happy if someone could give me an example for this case)

Or how can I add a new parameter to the function and use it? (I know that I have to put that new parameter in the function lib but how I am gonna tell to the program what is that target?)

I hope I was clear any problem about this post comment below and I will for sure answer ASAP.

Thanks and sorry something I am still getting used to Otland and to ot servers world :)
return std::max<uint64_t>(0, std::floor(getLostExperience() * getDamageRatio(attacker) *0,75));
This should be a dot not a comma:https://github.com/otland/forgottenserver/blob/master/src/player.cpp#L3316

And what would be Creature* target? There is already both creatures in it.

attackerPlayer = Player that killed "this"
this = Player that died.
 
Back
Top