• 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 Enabling shared experience [OTX3, 7.72]

X X X

Newb
Joined
Jul 26, 2015
Messages
146
Reaction score
13
Hey guys, running into a problem with shared experience. I know that it is in the source code but since original Tibia didn't have shared experience you can't enable it like normal by right clicking on yourself after you are in a party.

I created a talkaction to do it but I'm getting a nil value error and I don't understand why. Here is my shared.lua:

Lua:
local cfg = {
    inFightBlock = true,
    onlyLeader = true,
}

function onSay(cid, words, param, channel)
    local members = getPartyMembers(cid)
    if(not(members))then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You are not in a party.")
        return true
    end

    if(cfg.onlyLeader and not(iscurrentLeader(cid)))then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Only the party leader can enable/disable shared experience.")
        return true
    end

    if(cfg.inFightBlock and hasCreatureCondition(cid, CONDITION_INFIGHT))then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You may not enable shared experience during or immediately after a fight!")
        return true
    end

    local boolean = not(isPartySharedExperienceActive(cid))
    if(setPartySharedExperience(cid, boolean))then
        for _, pid in ipairs(members) do
            if(not(iscurrentLeader(pid)))then
                doPlayerSendTextMessage(pid, MESSAGE_INFO_DESCR, "Shared Experience has been "..(boolean and "activated" or "deactivated")..".")
            end
        end
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "There was an error. Try again in few seconds.")
    end

    return true
end

The first part of the code works, meaning that if I am not in a party and say "!shared", I get a blue console message saying "22:38 You are not in a party."

When I am in a party and I say "!shared," this is the error I get in the console:

Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/shared.lua:onSay
data/talkactions/scripts/shared.lua:13: attempt to call global 'iscurrentLeader' (a nil value)
stack traceback:
        [C]: in function 'iscurrentLeader'
        data/talkactions/scripts/shared.lua:13: in function <data/talkactions/scripts/shared.lua:6>

So I understand this message, it means that it doesn't recognize the value I'm trying to call (who is the leader of the party). But I thought that all I needed to include was cid? I don't know how else to call it so I need some help.

Thank you
 
Solution
You aren't calling the right things. Use this:

Lua:
function onSay(player, words, param)
    local party = player:getParty()
    if not party then
        player:sendCancelMessage("You are not part of a party.")
        return false
    end
    
    if party:getLeader() ~= player then
        player:sendCancelMessage("You are not the leader of the party.")
        return false
    end
    
    if party:isSharedExperienceActive() then
        if player:getCondition(CONDITION_INFIGHT) then
            player:sendCancelMessage("You are in fight. Experience sharing not disabled.")
        else
            party:setSharedExperience(false)
        end
    else
        if player:getCondition(CONDITION_INFIGHT) then...
You aren't calling the right things. Use this:

Lua:
function onSay(player, words, param)
    local party = player:getParty()
    if not party then
        player:sendCancelMessage("You are not part of a party.")
        return false
    end
    
    if party:getLeader() ~= player then
        player:sendCancelMessage("You are not the leader of the party.")
        return false
    end
    
    if party:isSharedExperienceActive() then
        if player:getCondition(CONDITION_INFIGHT) then
            player:sendCancelMessage("You are in fight. Experience sharing not disabled.")
        else
            party:setSharedExperience(false)
        end
    else
        if player:getCondition(CONDITION_INFIGHT) then
            player:sendCancelMessage("You are in fight. Experience sharing not enabled.")
        else
            party:setSharedExperience(true)
        end
    end
        
    return false
end
 
Solution
Back
Top