• 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 outfit bonus

darkmu

Well-Known Member
Joined
Aug 26, 2007
Messages
274
Solutions
1
Reaction score
50
Location
Paraná,Brazil
Can anyone identify where I'm going wrong? Because it is not triggering the conditions as I select the example addon.

TFS 1.3

Lua:
conditions = {
    [128] = {
                [1] = {
                        [1] = {
                                condition = CONDITION_ATTRIBUTES,
                                params = {                                     
                                    {CONDITION_PARAM_TICKS, -1}, -- 1 minute
                                    {CONDITION_PARAM_SKILL_DISTANCE, 50},                               
                                }
                            },               
                },
                [2] = {
                        [1] = {
                                condition = CONDITION_REGENERATION,
                                params = {                               
                                    {CONDITION_PARAM_TICKS, -1}, -- 1 minute                                   
                                    {CONDITION_PARAM_STAT_MAXHITPOINTS, 500}, -- gain 500 to max hp       
                                }
                            },
                    },
            },
}

temp = {}

function getBonusOutfit(outfit, addons)
    local outfitTable = conditions[outfit]

    if not outfitTable then return false end
    
    for k, v in ipairs(outfitTable[addons]) do
        local condition = Condition(v.condition)   
        for _, param in pairs(v.params) do
            condition:setParameter(param[1], param[2])
        end
        table.insert(temp, condition)
    end
    
    return temp
end

Lua:
function Creature:onChangeOutfit(outfit)
    if not self:isPlayer() then
        return true
    end
    
    print(outfit.lookType)
    local newBonusCondition = getBonusOutfit(outfit.lookType, 1)

    if newBonusCondition then
        self:addCondition(newBonusCondition)
    end
    
    return true
end
 
Solution
Why are you trying to return a variable outside the environment block of the main function, as you can see in your code, the variable condition is local, and therefore only visible from the environment block of the for loop

I will show you an example using your base:
Lua:
local conditions = {
    [128] = {
        [1] = {
            condition = CONDITION_ATTRIBUTES,
            params = {
                {CONDITION_PARAM_TICKS, -1}, -- 1 minute
                {CONDITION_PARAM_SKILL_DISTANCE, 50}
            }
        }
    }
}

function sendPlayerBonusOutfit(player, lookType, addons)
    local outfitTable = conditions[lookType]
    if outfitTable then
        local outfitInfo = outfitTable[addons]
        if outfitInfo then
            local...
First of all it is sending as a parameter a table called temp
self:addCondition(newBonusCondition)

1616889293208.png

this function requires a Condition not a table

it is also not handling the removal of conditions when you change outfits
 
First of all it is sending as a parameter a table called temp
self:addCondition(newBonusCondition)

View attachment 57017

this function requires a Condition not a table

it is also not handling the removal of conditions when you change outfits
Lua:
function getBonusOutfit(outfit, addons)
    local outfitTable = conditions[outfit]

    if not outfitTable then return false end

    for k, v in ipairs(outfitTable[addons]) do       
        local condition = Condition(CONDITION_ATTRIBUTES)   
        for _, param in pairs(v.params) do
            condition:setParameter(param[1], param[2])
        end       
    end

    return condition
end

I am not understanding why nill is returning me in condition, and when debugging it is returning values.
 
Why are you trying to return a variable outside the environment block of the main function, as you can see in your code, the variable condition is local, and therefore only visible from the environment block of the for loop

I will show you an example using your base:
Lua:
local conditions = {
    [128] = {
        [1] = {
            condition = CONDITION_ATTRIBUTES,
            params = {
                {CONDITION_PARAM_TICKS, -1}, -- 1 minute
                {CONDITION_PARAM_SKILL_DISTANCE, 50}
            }
        }
    }
}

function sendPlayerBonusOutfit(player, lookType, addons)
    local outfitTable = conditions[lookType]
    if outfitTable then
        local outfitInfo = outfitTable[addons]
        if outfitInfo then
            local condition = Condition(outfitInfo.condition)
            condition:setParameter(CONDITION_PARAM_SUBID, 666)
            for _, param in pairs(outfitInfo.params) do
                condition:setParameter(param[1], param[2])
            end
            player:addCondition(condition)
            return true
        end
    end
    return false
end

function Creature:onChangeOutfit(outfit)
    if self:isPlayer() then
        self:removeCondition(CONDITION_ATTRIBUTES, nil, 666, true)
        sendPlayerBonusOutfit(self, outfit.lookType, outfit.lookAddons)
    end
    return true
end
 
Last edited:
Solution
Why are you trying to return a variable outside the environment block of the main function, as you can see in your code, the variable condition is local, and therefore only visible from the environment block of the for loop

I will show you an example using your base:
Lua:
local conditions = {
    [128] = {
        [1] = {
            condition = CONDITION_ATTRIBUTES,
            params = {
                {CONDITION_PARAM_TICKS, -1}, -- 1 minute
                {CONDITION_PARAM_SKILL_DISTANCE, 50}
            }
        }
    }
}

function sendPlayerBonusOutfit(player, lookType, addons)
    local outfitTable = conditions[lookType]
    if outfitTable then
        local outfitInfo = outfitTable[addons]
        if outfitInfo then
            local condition = Condition(outfitInfo.condition)
            for _, param in pairs(outfitInfo.params) do
                condition:setParameter(param[1], param[2])
            end
            player:addCondition(condition)
            return true
        end
    end
    return false
end

function Creature:onChangeOutfit(outfit)
    if self:isPlayer() then
        sendPlayerBonusOutfit(self, outfit.lookType, outfit.lookAddons)
    end
    return true
end

Thank you very much, now I need to undo the condition when changing the addon or the looktype
 
Back
Top