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

TFS 1.X+ Castle Boost exp

545658

Member
Joined
Nov 6, 2016
Messages
26
Reaction score
5
Hello, I have a problem with exp bonus castle when a guild takes over such a castle.
After taking over the castle the guild does not get bonus exp.

data/events/player.lua
Code:
function Player:onGainExperience(source, exp, rawExp)
 local xpCastle = 0
 if self:getGuild() and self:getGuild():getId() == CASTLE24H:getGuildIdFromCastle() then
 xpCastle = exp * 1.20 -- +20% XP
end

data/lib/castle.lua
LUA:
function CASTLE24H:getGuildIdFromCastle()
  local guildId  = -1
  local resultId = db.storeQuery("SELECT `guild_id` FROM `castle`;")
  if (resultId ~= false) then
    guildId = result.getDataInt(resultId, "guild_id")
    result.free(resultId)
  end
  return guildId
end
 

Attachments

Last edited:
In player.lua, shouldn't you use exp instead of xpcastle?

LUA:
function Player:onGainExperience(source, exp, rawExp)
    if self:getGuild() and self:getGuild():getId() == CASTLE24H:getGuildIdFromCastle() then
        exp = exp * 1.20 -- +20% XP
    end
 
In player.lua, shouldn't you use exp instead of xpcastle?

LUA:
function Player:onGainExperience(source, exp, rawExp)
    if self:getGuild() and self:getGuild():getId() == CASTLE24H:getGuildIdFromCastle() then
        exp = exp * 1.20 -- +20% XP
    end

Or it could also be an alternative here, it should work.

LUA:
function Player:onGainExperience(source, exp, rawExp)
    local xpCastle = 0
    if self:getGuild() and self:getGuild():getId() == CASTLE24H:getGuildIdFromCastle() then
        xpCastle = exp * 0.20 
        exp = exp + xpCastle
    end
end
 
Or it could also be an alternative here, it should work.

LUA:
function Player:onGainExperience(source, exp, rawExp)
    local xpCastle = 0
    if self:getGuild() and self:getGuild():getId() == CASTLE24H:getGuildIdFromCastle() then
        xpCastle = exp * 0.20 
        exp = exp + xpCastle
    end
end

I don't think so, firstly, you don't need to declare xpcastle = 0 and the PlayeronGainExperience function is bigger than it presented, it can't end at this end that you placed and it also doesn't make sense for you to keep xpcastle just to calculate the 20% bonus since if you put exp = exp * 1.2 you already do this..

Not that it can't be done the way you presented it, I have little knowledge, but I believe it's cleaner and more concise, as it doesn't seem like any complex changes are necessary.
 
I don't think so, firstly, you don't need to declare xpcastle = 0 and the PlayeronGainExperience function is bigger than it presented, it can't end at this end that you placed and it also doesn't make sense for you to keep xpcastle just to calculate the 20% bonus since if you put exp = exp * 1.2 you already do this..

Not that it can't be done the way you presented it, I have little knowledge, but I believe it's cleaner and more concise, as it doesn't seem like any complex changes are necessary.
OK I understand. Thanks for the info. I'm learning and getting more practical every day. Thank you for clearing my doubts. You are sure!
 
I have similar xpboost scripts and I use them this way:

LUA:
function Player:onGainExperience(source, exp, rawExp)
 local xpCastle = 0
 if self:getGuild() and self:getGuild():getId() == CASTLE24H:getGuildIdFromCastle() then
 xpCastle = exp * 1.20 -- +20% XP
 end

return exp + xpCastle
end
 
Back
Top