• 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!

Addon bonus tfs 1.3 8.6 only if player has all addons

vexler222

Active Member
Joined
Apr 22, 2012
Messages
714
Solutions
15
Reaction score
46
Hi, i have addon system for tfs 1.3, and it worked if player has outfit without addons, i change it and working in 50% good, cuz now it work if player has first or second addon, how to fix it? Why it not work, i added first and second addon to check


Code:
function Creature:onChangeOutfit(outfit)
    if not self:isPlayer() then
        return true
    end
    if self:hasOutfit(self:getOutfit().lookType, 1) and self:hasOutfit(self:getOutfit().lookType, 2) then
        local previousBonusCondition = getBonusCondition(self:getOutfit().lookType)
        local newBonusCondition = getBonusCondition(outfit.lookType)
        if previousBonusCondition then
            self:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, previousBonusCondition:getSubId())
        end
        if newBonusCondition then
            self:addCondition(newBonusCondition)
        end
    end
    return true
end
 
Solution
@vexler222
Remember to remove previousBonusCondition before 'if' that checks if player has outfit.
Otherwise changing from outfit with bonus, to outfit without bonus, will not remove old outfit bonus!
Lua:
function Creature:onChangeOutfit(outfit)
    if not self:isPlayer() then
        return true
    end

-- remove old bonus
    local previousBonusCondition = getBonusCondition(self:getOutfit().lookType)
    if previousBonusCondition then
        self:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, previousBonusCondition:getSubId())
    end

-- add new bonus
    if outfit.lookAddons == 3 then
        local newBonusCondition = getBonusCondition(outfit.lookType)
        if newBonusCondition then...
self:canWearOutfit(self:getOutfit().lookType, 3)

data/events/scripts/creature.lua:193: attempt to call method 'canWearOutfit' (a nil value)

show your code with 3
same what i past, but i have 3 not 1,2

Code:
function Creature:onChangeOutfit(outfit)
    if not self:isPlayer() then
        return true
    end
    if self:hasOutfit(self:getOutfit().lookType, 3) then
        local previousBonusCondition = getBonusCondition(self:getOutfit().lookType)
        local newBonusCondition = getBonusCondition(outfit.lookType)
        if previousBonusCondition then
            self:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, previousBonusCondition:getSubId())
        end
        if newBonusCondition then
            self:addCondition(newBonusCondition)
        end
    end
    return true
end
 
data/events/scripts/creature.lua:193: attempt to call method 'canWearOutfit' (a nil value)


same what i past, but i have 3 not 1,2

Code:
function Creature:onChangeOutfit(outfit)
    if not self:isPlayer() then
        return true
    end
    if self:hasOutfit(self:getOutfit().lookType, 3) then
        local previousBonusCondition = getBonusCondition(self:getOutfit().lookType)
        local newBonusCondition = getBonusCondition(outfit.lookType)
        if previousBonusCondition then
            self:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, previousBonusCondition:getSubId())
        end
        if newBonusCondition then
            self:addCondition(newBonusCondition)
        end
    end
    return true
end
Try testing this, for me.
(on a character you don't mind having addons for free..)

Check console for prints.

Lua:
function Creature:onChangeOutfit(outfit)
    if not self:isPlayer() then
        return true
    end
    --if self:hasOutfit(self:getOutfit().lookType, 3) then
    --    local previousBonusCondition = getBonusCondition(self:getOutfit().lookType)
    --    local newBonusCondition = getBonusCondition(outfit.lookType)
    --    if previousBonusCondition then
    --        self:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, previousBonusCondition:getSubId())
    --    end
    --    if newBonusCondition then
    --        self:addCondition(newBonusCondition)
    --    end
    --end
   
    print("Testing..")
   
    -- outfit
    if self:hasOutfit(self:getOutfit().lookType) then
        print("Player has outfit.")
    end
    if self:hasOutfit(self:getOutfit().lookType, 3) then
        print("Player has both addons.")
        return true
    end
   
    if self:hasOutfit(self:getOutfit().lookType, 1) then
        print("Player has addon 1.")
    else
        print("Player did not have addon 1. Giving addon and checking again..")
        self:addOutfitAddon(self:getOutfit().lookType, 1)
        if self:hasOutfit(self:getOutfit().lookType, 1) then
            print("Player now has addon 1.")
        else
            print("Player still does not have addon 1.")
        end
    end
   
    if self:hasOutfit(self:getOutfit().lookType, 2) then
        print("Player has addon 2.")
    else
        print("Player did not have addon 2. Giving addon and checking again..")
        self:addOutfitAddon(self:getOutfit().lookType, 2)
        if self:hasOutfit(self:getOutfit().lookType, 2) then
            print("Player now has addon 2.")
        else
            print("Player still does not have addon 2.")
        end
    end
   
    if self:hasOutfit(self:getOutfit().lookType, 3) then
        print("Player now has both addons.")
    else
        print("Player somehow does not have both addons. Very Strange.")
    end
    return true
end
 
Try testing this, for me.
(on a character you don't mind having addons for free..)

Check console for prints.

Lua:
function Creature:onChangeOutfit(outfit)
    if not self:isPlayer() then
        return true
    end
    --if self:hasOutfit(self:getOutfit().lookType, 3) then
    --    local previousBonusCondition = getBonusCondition(self:getOutfit().lookType)
    --    local newBonusCondition = getBonusCondition(outfit.lookType)
    --    if previousBonusCondition then
    --        self:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, previousBonusCondition:getSubId())
    --    end
    --    if newBonusCondition then
    --        self:addCondition(newBonusCondition)
    --    end
    --end
  
    print("Testing..")
  
    -- outfit
    if self:hasOutfit(self:getOutfit().lookType) then
        print("Player has outfit.")
    end
    if self:hasOutfit(self:getOutfit().lookType, 3) then
        print("Player has both addons.")
        return true
    end
  
    if self:hasOutfit(self:getOutfit().lookType, 1) then
        print("Player has addon 1.")
    else
        print("Player did not have addon 1. Giving addon and checking again..")
        self:addOutfitAddon(self:getOutfit().lookType, 1)
        if self:hasOutfit(self:getOutfit().lookType, 1) then
            print("Player now has addon 1.")
        else
            print("Player still does not have addon 1.")
        end
    end
  
    if self:hasOutfit(self:getOutfit().lookType, 2) then
        print("Player has addon 2.")
    else
        print("Player did not have addon 2. Giving addon and checking again..")
        self:addOutfitAddon(self:getOutfit().lookType, 2)
        if self:hasOutfit(self:getOutfit().lookType, 2) then
            print("Player now has addon 2.")
        else
            print("Player still does not have addon 2.")
        end
    end
  
    if self:hasOutfit(self:getOutfit().lookType, 3) then
        print("Player now has both addons.")
    else
        print("Player somehow does not have both addons. Very Strange.")
    end
    return true
end
I already know what's going on, this script checks if a player has two addons, they don't have to be worn, is it possible that the bonuses only work if the player has both addons on self?
 
I already know what's going on, this script checks if a player has two addons, they don't have to be worn, is it possible that the bonuses only work if the player has both addons on self?
Lua:
if player:getOutfit().lookAddons == 3 then
    print("player is currently wearing both addons for this outfit.")
end
 
@vexler222
Remember to remove previousBonusCondition before 'if' that checks if player has outfit.
Otherwise changing from outfit with bonus, to outfit without bonus, will not remove old outfit bonus!
Lua:
function Creature:onChangeOutfit(outfit)
    if not self:isPlayer() then
        return true
    end

-- remove old bonus
    local previousBonusCondition = getBonusCondition(self:getOutfit().lookType)
    if previousBonusCondition then
        self:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, previousBonusCondition:getSubId())
    end

-- add new bonus
    if outfit.lookAddons == 3 then
        local newBonusCondition = getBonusCondition(outfit.lookType)
        if newBonusCondition then
            self:addCondition(newBonusCondition)
        end
    end
    return true
end

Lua:
if player:getOutfit().lookAddons == 3 then
    print("player is currently wearing both addons for this outfit.")
end
Creature:onChangeOutfit(outfit) is called when player change outfit. In player:getOutfit() is current outfit (old outfit), new outfit that player selected is in variable outfit, so it must be:
Lua:
if outfit.lookAddons == 3 then
You can return false to make it not change outfit, example:
when you make some 'team vs team' event and want to set some colors of players outfits (red vs blue) and block possiblity to change outfit of players who are on event.
 
Solution
@vexler222
Remember to remove previousBonusCondition before 'if' that checks if player has outfit.
Otherwise changing from outfit with bonus, to outfit without bonus, will not remove old outfit bonus!
Lua:
function Creature:onChangeOutfit(outfit)
    if not self:isPlayer() then
        return true
    end

-- remove old bonus
    local previousBonusCondition = getBonusCondition(self:getOutfit().lookType)
    if previousBonusCondition then
        self:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, previousBonusCondition:getSubId())
    end

-- add new bonus
    if outfit.lookAddons == 3 then
        local newBonusCondition = getBonusCondition(outfit.lookType)
        if newBonusCondition then
            self:addCondition(newBonusCondition)
        end
    end
    return true
end


Creature:onChangeOutfit(outfit) is called when player change outfit. In player:getOutfit() is current outfit (old outfit), new outfit that player selected is in variable outfit, so it must be:
Lua:
if outfit.lookAddons == 3 then
My bad. The language barrier made me think this was some sort of custom function.
I see I'm just blind now.
 
@vexler222
Lembre-se de remover previousBonusCondition antes de 'if' que verifica se o jogador tem roupa.
Caso contrário, mudar de roupa com bônus, para roupa sem bônus, não removerá o bônus de roupa antiga!
[código=lua]
função Criatura:eek:nChangeOutfit(roupa)
se não self:isPlayer() então
retornar verdadeiro
fim

-- remover bônus antigo
local anteriorBonusCondition = getBonusCondition(self:getOutfit().lookType)
se anteriorBonusCondition então
self:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, previousBonusCondition:getSubId())
fim

-- adicionar novo bônus
if outfit.lookAddons == 3 then
local newBonusCondition = getBonusCondition(outfit.lookType)
se newBonusCondition então
self:addCondition(newBonusCondition)
fim
fim
retornar verdadeiro
fim
[/código]


Creature:onChangeOutfit(outfit) é chamado quando o jogador troca de roupa. Em player:getOutfit() é a roupa atual (roupa antiga), a nova roupa que o jogador selecionou está na variável roupa, então deve ser:
[código=lua]
if outfit.lookAddons == 3 then
[/código]
Você pode retornar false para não mudar de roupa, exemplo:
quando você faz algum evento 'time vs time' e quer definir algumas cores de roupas de jogadores (vermelho vs azul) e bloquear a possibilidade de mudar de roupa de jogadores que estão no evento.
is it possible to make it add the bonus to the player even if he is not using the addon? however he would have to have the complete addon.. example. the player has the citizen full that gives +5 speed then he switches to the hunter that is not complete, but he still has the citizen's bonus.
 
Back
Top