• 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 [TFS 1.2] Outfit bonuses

darkmu

Well-Known Member
Joined
Aug 26, 2007
Messages
274
Solutions
1
Reaction score
50
Location
Paraná,Brazil
I'm doing some tests, I put it in the array to activate with citizen, however using the debbuger (print) this is always returning me false ... what should I be missing?

Creature.lua
Lua:
function Creature:onChangeOutfit(outfit)
    if not self:isPlayer() then
        return true
    end

    local previousBonusCondition = getBonusOutfitID(self:getOutfit().lookType)
    if previousBonusCondition then
        self:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, previousBonusCondition)
    end
    
    local bonusOutfit = getBonusOutfit(outfit.lookType)
    print(bonusOutfit)
    if bonusOutfit then
        local addons = 1
        if self:canWearOutfit(outfit.lookType, 2) then
            addons = 3
        elseif self:canWearOutfit(outfit.lookType, 1) then
            addons = 2
        end
      
        local newBonusCondition = createBonusCondition(bonusOutfit, addons)
        if newBonusCondition then
            self:addCondition(newBonusCondition)
        end
    end
    return true
end

LIB
Lua:
--[[
    addions[1] = no addons
    addons[2] = 1st addon unlocked
    addons[3] = 2nd addon unlocked
]]--

OUTFIT_BONUSES = {
    [{136, 128}] = {id = 1, -- +1 each id for new outfits
                    addons = {
                                [1] = nil,
                                [2] = { CONDITION_MAGICLEVELPOINT, 5 },
                                [3] = { CONDITION_HASTE, 25 }
                            }
    },
    [{118, 119}] = {id = 2,
                    addons = {
                                [1] = nil,
                                [2] = { CONDITION_MAGICLEVELPOINT, 5 },
                                [3] = { CONDITION_HASTE, 25 }
                            }
    }
}

function getBonusOutfit(outfit)
    for i, v in pairs(OUTFIT_BONUSES) do   
        if outfit == i then
            return OUTFIT_BONUSES[i]
        end
    end
    return false
end


function createBonusCondition(bonus, addon)
    local condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
    condition:setParameter(CONDITION_PARAM_TICKS, -1)
    condition:setParameter(CONDITION_PARAM_SUBID, bonus.id)
    for x = 1, addon do
        for i = 1, #bonus.addons[x] do
            local param = bonus.addons[x][1]
            local value = bonus.addons[x][2]
            condition:setParameter(param, value)
        end
    end
    return condition
end

function getBonusOutfitID(outfit)
    for outfits, bonus in pairs(OUTFIT_BONUSES) do
        if table.contains(outfits, outfit) then
            return bonus.id
        end
    end
    return nil
end

RETURN ON PRINT
false
 
Declare outfit before calling the function getBonusOutfit in creature.lua

Lua:
local outfit = self:getOutfit()

Also I dont think the getBonusOutfit() function will work, I suggest to changing to something like that:
Lua:
OUTFIT_BONUSES = {
    [1] = {looktypes = {136, 138},
            id = 1, -- +1 each id for new outfits
            addons = {
                      [1] = nil,
                      [2] = { CONDITION_MAGICLEVELPOINT, 5 },
                      [3] = { CONDITION_HASTE, 25 }
                     }
    }
    },
    [2] = {looktypes = {118, 119},
            id = 2,
            addons = {
                      [1] = nil,
                      [2] = { CONDITION_MAGICLEVELPOINT, 5 },
                      [3] = { CONDITION_HASTE, 25 }
                     }
    }
}

function getBonusOutfit(outfit)
    for i, v in ipairs(OUTFIT_BONUSES) do
        if isInArray(v.looktypes, outfit) then
            return OUTFIT_BONUSES[i]
        end
    end
    return false
end
 
I'm doing some tests, I put it in the array to activate with citizen, however using the debbuger (print) this is always returning me false ... what should I be missing?

Creature.lua
Lua:
function Creature:onChangeOutfit(outfit)
    if not self:isPlayer() then
        return true
    end

    local previousBonusCondition = getBonusOutfitID(self:getOutfit().lookType)
    if previousBonusCondition then
        self:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, previousBonusCondition)
    end
   
    local bonusOutfit = getBonusOutfit(outfit.lookType)
    print(bonusOutfit)
    if bonusOutfit then
        local addons = 1
        if self:canWearOutfit(outfit.lookType, 2) then
            addons = 3
        elseif self:canWearOutfit(outfit.lookType, 1) then
            addons = 2
        end
     
        local newBonusCondition = createBonusCondition(bonusOutfit, addons)
        if newBonusCondition then
            self:addCondition(newBonusCondition)
        end
    end
    return true
end

LIB
Lua:
--[[
    addions[1] = no addons
    addons[2] = 1st addon unlocked
    addons[3] = 2nd addon unlocked
]]--

OUTFIT_BONUSES = {
    [{136, 128}] = {id = 1, -- +1 each id for new outfits
                    addons = {
                                [1] = nil,
                                [2] = { CONDITION_MAGICLEVELPOINT, 5 },
                                [3] = { CONDITION_HASTE, 25 }
                            }
    },
    [{118, 119}] = {id = 2,
                    addons = {
                                [1] = nil,
                                [2] = { CONDITION_MAGICLEVELPOINT, 5 },
                                [3] = { CONDITION_HASTE, 25 }
                            }
    }
}

function getBonusOutfit(outfit)
    for i, v in pairs(OUTFIT_BONUSES) do  
        if outfit == i then
            return OUTFIT_BONUSES[i]
        end
    end
    return false
end


function createBonusCondition(bonus, addon)
    local condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
    condition:setParameter(CONDITION_PARAM_TICKS, -1)
    condition:setParameter(CONDITION_PARAM_SUBID, bonus.id)
    for x = 1, addon do
        for i = 1, #bonus.addons[x] do
            local param = bonus.addons[x][1]
            local value = bonus.addons[x][2]
            condition:setParameter(param, value)
        end
    end
    return condition
end

function getBonusOutfitID(outfit)
    for outfits, bonus in pairs(OUTFIT_BONUSES) do
        if table.contains(outfits, outfit) then
            return bonus.id
        end
    end
    return nil
end

RETURN ON PRINT
false

Your system looks very organized, could you pass me the complete and corrected code to use it on my server?

I would be very grateful
 
Back
Top