• 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 Player hasOutfit instead of onChangeOutfit

Mahdi10

New Member
Joined
Jan 27, 2023
Messages
13
Reaction score
2
TFS 1.5

Can someone help me convert this script to use hasOutfit instead of onChangeOutfit?
This script only assigns outfit bonuses when player is already using the outfit, but I need it to assign outfit bonuses when player already has the outfit.
So if the table has 10 outfits, and each outfit assigns 20 max HP and 20 max MP to player, and player has all 10 outfits with full addons, he gets 200 max HP and 200 max MP total bonuses without using any of the 10 outfits.

 
Untested

data/lib/core/player.lua
Lua:
do
    -- # percent attributes must have the absolute value
    local subId = 100
    local outfitBonuses = {
        -- # outfits -> [female, male]
        [{136, 128}] = {
            {param = CONDITION_PARAM_STAT_MAGICPOINTS, value = 10},
            {param = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, value = 10, absolute = true}
        },

        [{137, 129}] = {
            {param = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, value = 50, absolute = true}
        }
    }

    function Player.updateOutfitBonuses(self)

        local updateCondition = false
        local attributes = {}

        for outfits, bonuses in pairs(outfitBonuses) do
            if self:hasOutfit(outfits[self:getSex() + 1]) then
                for i = 1, #bonuses do
                    local bonus = bonuses[i]
                    attributes[bonus.param] = (attributes[bonus.param] or (bonus.absolute and 100 or 0)) + bonus.value
                end
                updateCondition = true
            end
        end

        if updateCondition then

            local previousCondition = self:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, subId)
            if previousCondition then
                self:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, subId)
            end

            local newCondition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
            newCondition:setParameter(CONDITION_PARAM_TICKS, -1)
            newCondition:setParameter(CONDITION_PARAM_SUBID, subId)

            for param, value in pairs(attributes) do
                newCondition:setParameter(param, value)
            end

            self:addCondition(newCondition)
        end
    
        return updateCondition
    end
end

data/creaturescripts/scripts/login.lua
Lua:
-- # outfit bonuses
player:updateOutfitBonuses()

if you want to instantly update the bonuses once a player gets a new outfit, you can use player:updateOutfitBonuses() inside the desired script
 
There is one error (attempt to index global 'self' (a nil value))
I changed Player.updateOutfitBonuses() to Player.updateOutfitBonuses(self) and now error disappeared and I can login but no bonuses assigned to player.
I have player:updateOutfitBonuses() in login.lua and in buyaddons.lua and player have outfit 136 and 137 with all addons.
 
Untested

data/lib/core/player.lua
Lua:
do
    -- # percent attributes must have the absolute value
    local subId = 100
    local outfitBonuses = {
        -- # outfits -> [female, male]
        [{136, 128}] = {
            {param = CONDITION_PARAM_STAT_MAGICPOINTS, value = 10},
            {param = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, value = 10, absolute = true}
        },

        [{137, 129}] = {
            {param = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, value = 50, absolute = true}
        }
    }

    function Player.updateOutfitBonuses(self)

        local updateCondition = false
        local attributes = {}

        for outfits, bonuses in pairs(outfitBonuses) do
            if self:hasOutfit(outfits[self:getSex() + 1]) then
                for i = 1, #bonuses do
                    local bonus = bonuses[i]
                    attributes[bonus.param] = (attributes[bonus.param] or (bonus.absolute and 100 or 0)) + bonus.value
                end
                updateCondition = true
            end
        end

        if updateCondition then

            local previousCondition = self:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, subId)
            if previousCondition then
                self:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, subId)
            end

            local newCondition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
            newCondition:setParameter(CONDITION_PARAM_TICKS, -1)
            newCondition:setParameter(CONDITION_PARAM_SUBID, subId)

            for param, value in pairs(attributes) do
                newCondition:setParameter(param, value)
            end

            self:addCondition(newCondition)
        end
   
        return updateCondition
    end
end

data/creaturescripts/scripts/login.lua
Lua:
-- # outfit bonuses
player:updateOutfitBonuses()

if you want to instantly update the bonuses once a player gets a new outfit, you can use player:updateOutfitBonuses() inside the desired script
I have extensively tested this and it functions very well, as confirmed. However, I am interested in learning if there is a possibility to incorporate elemental damage, such as fire or ice, into the system. Specifically, when altering the outfit (hunter) which entails earth-based damage, will this result in an increased hit damage against monsters/players? I suspect this might involve the 'onHealthChange' or 'onManaChange' events, but despite my attempts, I have been unable to configure the script to facilitate attacking damage. As it stands, it only effectively manages attributes and life/mana regeneration. My intention is to integrate elemental damage and potentially other customized attributes. Should you be able to assist me with this endeavor, your guidance would be immensely appreciated.
 
Back
Top