• 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.1 Party Exp

Tysoch86

New Member
Joined
Jan 8, 2016
Messages
81
Reaction score
1
Hi there, I am trying to modify the amount of exp gain based on the # of players in a party, to promote group hunting, so the higher the # of players in a party the higher the exp.

Can anyone help me find this in TFS 1.1?
 
:/ How does this look?


Code:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        return exp
    end

    -- Soul regeneration
    local vocation = self:getVocation()
    if self:getSoul() < vocation:getMaxSoul() and exp >= self:getLevel() then
        soulCondition:setParameter(CONDITION_PARAM_SOULTICKS, vocation:getSoulGainTicks() * 1000)
        self:addCondition(soulCondition)
    end

    -- Apply experience stage multiplier
    exp = exp * Game.getExperienceStage(self:getLevel())
   
   
    -- Party Experience Bonus
    local membersList = getPartyMembers(cid)
    if(membersList == nil or type(membersList) ~= 'table' or #membersList <= 1) then
        doPlayerSendCancel(cid, "No party members in range.")
        doSendMagicEffect(pos, CONST_ME_POFF)
        return false
    end

    local affectedList = {}
    for _, pid in ipairs(membersList) do
        if(getDistanceBetween(getCreaturePosition(pid), pos) <= 36) then
            table.insert(affectedList, pid)
        end
    end

    local tmp = #affectedList
    if(tmp <= 1) then
        exp = exp * 1.0
    elseif(tmp <=2) then
        exp = exp * 1.2
    elseif(tmp <=3) then
        exp = exp * 1.3
    elseif(tmp <=4) then
        exp = exp * 1.4
    elseif(tmp <=5) then
        exp = exp * 1.5
    elseif(tmp <=6) then
        exp = exp * 1.6
    elseif(tmp <=7) then
        exp = exp * 1.7
    elseif(tmp <=8) then
        exp = exp * 1.8
    elseif(tmp <=9) then
        exp = exp * 1.9
    elseif(tmp <=10) then
        exp = exp * 2.0
        doPlayerSendCancel(cid, "No party members in range.")
        return false
    end

    -- Stamina modifier
    if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then
        useStamina(self)

        local staminaMinutes = self:getStamina()
        if staminaMinutes > 2400 and self:isPremium() then
            exp = exp * 1.5
        elseif staminaMinutes <= 840 then
            exp = exp * 0.5
        end
    end

    return exp
end
 
I didn't look at the rest, change this
Code:
    local tmp = #affectedList
    if(tmp <= 1) then
        exp = exp * 1.0
    elseif(tmp <=2) then
        exp = exp * 1.2
    elseif(tmp <=3) then
        exp = exp * 1.3
    elseif(tmp <=4) then
        exp = exp * 1.4
    elseif(tmp <=5) then
        exp = exp * 1.5
    elseif(tmp <=6) then
        exp = exp * 1.6
    elseif(tmp <=7) then
        exp = exp * 1.7
    elseif(tmp <=8) then
        exp = exp * 1.8
    elseif(tmp <=9) then
        exp = exp * 1.9
    elseif(tmp <=10) then
        exp = exp * 2.0
        doPlayerSendCancel(cid, "No party members in range.")
        return false
    end

To this
Code:
    if #affectedList > 0 and #affectedList < 21 then
        exp = exp * (#affectedList * 0.1)
    else
        doPlayerSendCancel(cid, "No party members in range.")
        return false
    end
 
Hmmm, I have this:

Code:
    -- Party Experience Bonus
    local membersList = getPartyMembers(cid)
    if(membersList == nil or type(membersList) ~= 'table' or #membersList <= 1) then
        doPlayerSendCancel(cid, "No party members in range.")
        return false
    end

    local affectedList = {}
    for _, pid in ipairs(membersList) do
        if(getDistanceBetween(getCreaturePosition(pid), pos) <= 36) then
            table.insert(affectedList, pid)
        end
    end

    local tmp = #affectedList
    if #affectedList > 0 and #affectedList < 21 then
        exp = exp + (#affectedList * 0.1 )
    else
        doPlayerSendCancel(cid, "No party members in range.")
        return false
    end


And its not giving any exp at all..
Any thoughts? maybe with the member list?
 
change this
Code:
getPartyMembers(cid)
to this
Code:
getPartyMembers(self:getId())
You could use the core functions but this just simplifies it, why re-invent the wheel

There are a few other corrections, you will need to replace some functions in the script which are cid related to their metamethod counterparts like sending cancel messages, although you could just use self:getId() as I did above.
 
Last edited:
Thanks i've tried this out:

Code:
    -- Apply experience stage multiplier
    exp = exp * Game.getExperienceStage(self:getLevel())
   
        -- Party Experience Bonus
    local membersList = getPartyMembers(self:getId())
    if(membersList == nil or type(membersList) ~= 'table' or #membersList <= 1) then
        doPlayerSendCancel(self:getId(), "No party members in range.")
        return false
    end

    local affectedList = {}
    for _, pid in ipairs(membersList) do
        if(getDistanceBetween(getCreaturePosition(pid), pos) <= 36) then
            table.insert(affectedList, pid)
        end
    end

    local tmp = #affectedList
    if #affectedList > 0 and #affectedList < 21 then
        exp = exp + (#affectedList * 0.1 + 1 )
        return false
    end

It displays the "no party members in range." msg when testing with 0 party memebers but doesn't give any exp.
I thought this may have been this line " exp = exp + (#affectedList * 0.1 )" so i changed that line to " exp = exp + (#affectedList * 0.1 + 1 )"

But still nothing.
Thanks for your help!

Do you know of any tibia specific LUA video tutorials that I can watch?
 
Do you know of any tibia specific LUA video tutorials that I can watch?
TFS is just a framework, lua is a scripting language, there is no such video tutorial that I know of that combines the 2, start looking on youtube for videos on lua if you don't like to read.

Once you learn lua you will understand the TFS framework.
 
Thanks i've tried this out:

Code:
    -- Apply experience stage multiplier
    exp = exp * Game.getExperienceStage(self:getLevel())
  
        -- Party Experience Bonus
    local membersList = getPartyMembers(self:getId())
    if(membersList == nil or type(membersList) ~= 'table' or #membersList <= 1) then
        doPlayerSendCancel(self:getId(), "No party members in range.")
        return false
    end

    local affectedList = {}
    for _, pid in ipairs(membersList) do
        if(getDistanceBetween(getCreaturePosition(pid), pos) <= 36) then
            table.insert(affectedList, pid)
        end
    end

    local tmp = #affectedList
    if #affectedList > 0 and #affectedList < 21 then
        exp = exp + (#affectedList * 0.1 + 1 )
        return false
    end

It displays the "no party members in range." msg when testing with 0 party memebers but doesn't give any exp.
I thought this may have been this line " exp = exp + (#affectedList * 0.1 )" so i changed that line to " exp = exp + (#affectedList * 0.1 + 1 )"

But still nothing.
Thanks for your help!

Do you know of any tibia specific LUA video tutorials that I can watch?
You shouldn't return false in this event, you have to return the amount of exp that the player is going to get.

So change where you have "return false" to "return exp"
 
I'm studying videos now, starting at the beginning lol. I should be able to contribute rather than leech from this community haha.

OK, I have changed the "return exp"

In the mean time I modified the script to bypass the two lower "locals" and just ran this

Code:
    local membersList = getPartyMembers(self:getId())
    if(membersList == nil or type(membersList) ~= 'table' or #membersList <= 1) then
        doPlayerSendCancel(self:getId(), "No party members in range.")
    elseif #memberList > 0 and #memberList < 21 then
        exp = exp + (#memberList * 0.1 + 1 )
        return false
    end

And came up with this error:

Lua Script Error: [Event Interface]
data/event/scripts/player.lua:player@onGainExperience
data/event/scripts/player.lua:161: attempt to get legnt of global 'memberList'
<a nil value>
stack traceback:
[C]: in function '__len'
data/events/scripts/player.lua:161: in function <data/events/scripts/player.lua:139>

Line 139 is "function Player:eek:nGainExperience(source, exp, rawExp)"

(sorry if there are typos i was unable to copy from the exp and it is very hard to test it again with only 1 player online :D )
 
Update:

Here is the working script :D
Thanks to Codex NG and MatheusMkalo!


TFS 1.1

Place this in data/event/scripts/player.lua
Code:
        -- Party Experience Bonus
    local membersList = getPartyMembers(self:getId())
    if(membersList == nil or type(membersList) ~= 'table' or #membersList <= 1) then
        exp = exp
    elseif (#membersList > 1) then
        exp = exp * (#membersList * 1.0)
   
        return exp
    end

In the line "exp = exp * (#membersList * 1.0)" , the 1.0 can be modified, higher is better for groups.
 
Back
Top