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

CreatureEvent [TFS 1.2] Outfit bonuses

Infernum

Senator
Joined
Feb 14, 2015
Messages
5,643
Solutions
559
Reaction score
3,946
inside of data/events/scripts/creature.lua (make sure onChangeOutfit is set to 1 in events.xml)
Lua:
function createBonusCondition(id, params)
    local condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
    condition:setParameter(CONDITION_PARAM_TICKS, -1)
    condition:setParameter(CONDITION_PARAM_SUBID, id)
    for i = 1, #params do
        local param = params[i].param
        local value = params[i].value
        condition:setParameter(param, value)
    end
    return condition
end

outfitBonuses = {
    [{128, 136}] = createBonusCondition(1, {
            {param = CONDITION_PARAM_STAT_MAGICPOINTS, value = 10},
            {param = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, value = 110}
        }
    ),
    [{129, 137}] = createBonusCondition(2, {
            {param = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, value = 200}
        }
    )
}

function getBonusCondition(outfit)
    for outfits, bonus in pairs(outfitBonuses) do
        if table.contains(outfits, outfit) then
            return bonus
        end
    end
    return nil
end

function Creature:onChangeOutfit(outfit)
    if not self:isPlayer() then
        return true
    end
    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
    return true
end

inside of data/creaturescripts/scripts/login.lua (inside the onLogin function)
Lua:
    -- Outfit bonus
    local bonusCondition = getBonusCondition(player:getOutfit().lookType)
    if bonusCondition then
        player:addCondition(bonusCondition)
    end

how to configure: (i already created two bonuses for citizen and hunter outfits as an example)
Lua:
outfitBonuses = {
    [{male outfit id, female outfit id}] = createBonusCondition(ID, parameters & values)
}
the ID should be different for each bonus, so the script can identify between conditions
in my example i started from 1 for citizen bonus and used 2 for hunter, if you were to continue you would go 3, 4, 5, etc.
parameters should be inside a table, {param = some_condition_param, value = value_to_set}
here are the available condition params for tfs 1.2:
Code:
CONDITION_PARAM_OWNER
CONDITION_PARAM_TICKS
CONDITION_PARAM_HEALTHGAIN
CONDITION_PARAM_HEALTHTICKS
CONDITION_PARAM_MANAGAIN
CONDITION_PARAM_MANATICKS
CONDITION_PARAM_DELAYED
CONDITION_PARAM_SPEED
CONDITION_PARAM_LIGHT_LEVEL
CONDITION_PARAM_LIGHT_COLOR
CONDITION_PARAM_SOULGAIN
CONDITION_PARAM_SOULTICKS
CONDITION_PARAM_MINVALUE
CONDITION_PARAM_MAXVALUE
CONDITION_PARAM_STARTVALUE
CONDITION_PARAM_TICKINTERVAL
CONDITION_PARAM_FORCEUPDATE
CONDITION_PARAM_SKILL_MELEE
CONDITION_PARAM_SKILL_FIST
CONDITION_PARAM_SKILL_CLUB
CONDITION_PARAM_SKILL_SWORD
CONDITION_PARAM_SKILL_AXE
CONDITION_PARAM_SKILL_DISTANCE
CONDITION_PARAM_SKILL_SHIELD
CONDITION_PARAM_SKILL_FISHING
CONDITION_PARAM_STAT_MAXHITPOINTS
CONDITION_PARAM_STAT_MAXMANAPOINTS
CONDITION_PARAM_STAT_SOULPOINTS
CONDITION_PARAM_STAT_MAGICPOINTS
CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT
CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT
CONDITION_PARAM_STAT_SOULPOINTSPERCENT
CONDITION_PARAM_STAT_MAGICPOINTSPERCENT
CONDITION_PARAM_PERIODICDAMAGE
CONDITION_PARAM_SKILL_MELEEPERCENT
CONDITION_PARAM_SKILL_FISTPERCENT
CONDITION_PARAM_SKILL_CLUBPERCENT
CONDITION_PARAM_SKILL_SWORDPERCENT
CONDITION_PARAM_SKILL_AXEPERCENT
CONDITION_PARAM_SKILL_DISTANCEPERCENT
CONDITION_PARAM_SKILL_SHIELDPERCENT
CONDITION_PARAM_SKILL_FISHINGPERCENT
CONDITION_PARAM_BUFF_SPELL
CONDITION_PARAM_SUBID
CONDITION_PARAM_FIELD
 
i need to relog with the especific addon in order to get the bonus, how can i make this work just by changing the outfit ingame?
btw this is working g8 with 1.3
 
41fa5ddb6110add39d7aeceb2b8ea72f.png

Yes
 
I think that the bonus should be reloaded onLogin aswell because the bonus is only being triggered if player changes his outfit.
 
I installed the script I get an error:

Lua:
Lua Script Error: [Test Interface]
data/creaturescripts/scripts/others/login.lua
data/creaturescripts/scripts/others/login.lua:186: attempt to index global 'player' (a nil value)
[Warning - Event::checkScript] Can not load script: scripts/others/login.lua

So then I removed what I added to Login.lua and my other error I get is:

Lua:
Lua Script Error: [Event Interface]
data/events/scripts/creature.lua:Creature@onChangeOutfit
data/lib/core/tables.lua:17: bad argument #1 to 'pairs' (table expected, got number)

Also in-game it won't let me change my outfit unless re-logging!

Any help is appreciated!
 
I installed the script I get an error:

Lua:
Lua Script Error: [Test Interface]
data/creaturescripts/scripts/others/login.lua
data/creaturescripts/scripts/others/login.lua:186: attempt to index global 'player' (a nil value)
[Warning - Event::checkScript] Can not load script: scripts/others/login.lua

So then I removed what I added to Login.lua and my other error I get is:

Lua:
Lua Script Error: [Event Interface]
data/events/scripts/creature.lua:Creature@onChangeOutfit
data/lib/core/tables.lua:17: bad argument #1 to 'pairs' (table expected, got number)

Also in-game it won't let me change my outfit unless re-logging!

Any help is appreciated!
did you place the code for onlogin inside the function?
 
how check addons, and add mounts? nice script bro thx
 
Code:
outfitBonuses = {
    [{1004, 1004}] = createBonusCondition(1, {
            {param = CONDITION_PARAM_STAT_MAGICPOINTS, value = 10},
            {param = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, value = 110}
        }
    ),
with this all working great hp going up and mlvl going up by 10
but with this

Code:
outfitBonuses = {
    [{1004, 1004}] = createBonusCondition(1, {
            {param = CONDITION_PARAM_HEALTHGAIN,  value = 20},
            {param = CONDITION_PARAM_HEALTHTICKS, value = 110}
        }
    ),
}
its not working at all did i fucked up or its a bug idk i also tried to remove "value = 20" and keep just "20" also not working
 
Code:
outfitBonuses = {
    [{1004, 1004}] = createBonusCondition(1, {
            {param = CONDITION_PARAM_STAT_MAGICPOINTS, value = 10},
            {param = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, value = 110}
        }
    ),
with this all working great hp going up and mlvl going up by 10
but with this

Code:
outfitBonuses = {
    [{1004, 1004}] = createBonusCondition(1, {
            {param = CONDITION_PARAM_HEALTHGAIN,  value = 20},
            {param = CONDITION_PARAM_HEALTHTICKS, value = 110}
        }
    ),
}
its not working at all did i fucked up or its a bug idk i also tried to remove "value = 20" and keep just "20" also not working
Forgot that certain things don't work with CONDITION_ATTRIBUTES, like regeneration.
You'd need to use CONDITION_REGENERATION instead for the conditions you want regen on, add this to the script and use createRegenCondition instead.
Lua:
function createRegenCondition(id, params)
    local condition = Condition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
    condition:setParameter(CONDITION_PARAM_TICKS, -1)
    condition:setParameter(CONDITION_PARAM_SUBID, id)
    for i = 1, #params do
        local param = params[i].param
        local value = params[i].value
        condition:setParameter(param, value)
    end
    return condition
end
 
Forgot that certain things don't work with CONDITION_ATTRIBUTES, like regeneration.
You'd need to use CONDITION_REGENERATION instead for the conditions you want regen on, add this to the script and use createRegenCondition instead.
Lua:
function createRegenCondition(id, params)
    local condition = Condition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
    condition:setParameter(CONDITION_PARAM_TICKS, -1)
    condition:setParameter(CONDITION_PARAM_SUBID, id)
    for i = 1, #params do
        local param = params[i].param
        local value = params[i].value
        condition:setParameter(param, value)
    end
    return condition
end

Thanks working good, if someone want to also use it add this(line 9) in the function onChangeOutfit(outfit) so the regeneration will not be permament
Code:
function Creature:onChangeOutfit(outfit)
if not self:isPlayer() then
        return true
    end
    local previousBonusCondition = getBonusCondition(self:getOutfit().lookType)
    local newBonusCondition = getBonusCondition(outfit.lookType)
    if previousBonusCondition then
        self:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, previousBonusCondition:getSubId())
        self:removeCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT, previousBonusCondition:getSubId()) <-- This line
    end
    if newBonusCondition then
        self:addCondition(newBonusCondition)
    end
    return true
end
 
help me pls. how can I make an outfit have two types of condition?
I have it like that but it only detects a single condition
example: citizen have speed and maglevel or regeneration

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

function createRegenCondition(id, params)
    local condition = Condition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
    condition:setParameter(CONDITION_PARAM_TICKS, -1)
    condition:setParameter(CONDITION_PARAM_SUBID, id)
    for i = 1, #params do
        local param = params[i].param
        local value = params[i].value
        condition:setParameter(param, value)
    end
    return condition
end

function createHasteCondition(id, params)
    local condition = Condition(CONDITION_HASTE, CONDITIONID_DEFAULT)
    condition:setParameter(CONDITION_PARAM_TICKS, -1)
    condition:setParameter(CONDITION_PARAM_SUBID, id)
    for i = 1, #params do
        local param = params[i].param
        local value = params[i].value
        condition:setParameter(param, value)
    end
    return condition
end

outfitBonuses = {
    [{128, 136}] = createBonusCondition(1, {
            {param = CONDITION_PARAM_STAT_MAGICPOINTS, value = 20},
            {param = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, value = 150}
        }
    ),
    [{128, 136}] = createHasteCondition(2, {
            {param = CONDITION_PARAM_SPEED, value = 100}
        }
    )
}

function getBonusCondition(outfit)
    for outfits, bonus in pairs(outfitBonuses) do
        if table.contains(outfits, outfit) then
            return bonus
        end
    end
    return nil
end


function Creature:onChangeOutfit(outfit)
if not self:isPlayer() then
        return true
    end
    local previousBonusCondition = getBonusCondition(self:getOutfit().lookType)
    local newBonusCondition = getBonusCondition(outfit.lookType)

    
    if previousBonusCondition then
        self:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, previousBonusCondition:getSubId())
        self:removeCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT, previousBonusCondition:getSubId())
        self:removeCondition(CONDITION_HASTE, CONDITIONID_DEFAULT, previousBonusCondition:getSubId())
    end
    if newBonusCondition then
        self:addCondition(newBonusCondition)
    end

    return true
end
 
I'am trying to use it for mounts bonus system but it didn't work.
Just use .lookMount instead of .lookType and change the ids to mount ids
didn't do anything different.
Code:
--Login.lua
    -- Outfit bonus
    local bonusCondition = getBonusCondition(player:getOutfit().lookMount)
    if bonusCondition then
        player:addCondition(bonusCondition)
    end

Code:
-- CREATURE.LUA
function createBonusCondition(id, params)
    local condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
    condition:setParameter(CONDITION_PARAM_TICKS, -1)
    condition:setParameter(CONDITION_PARAM_SUBID, id)
    for i = 1, #params do
        local param = params[i].param
        local value = params[i].value
        condition:setParameter(param, value)
    end
    return condition
end

outfitBonuses = {
    [{33, 33}] = createBonusCondition(1, {
            {param = CONDITION_PARAM_STAT_MAGICPOINTS, value = 10},
            {param = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, value = 110}
        }
    ),
    -- [{427, 426}] = createBonusCondition(2, {
            -- {param = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, value = 200}
        -- }
    -- )
}

function getBonusCondition(outfit)
    for outfits, bonus in pairs(outfitBonuses) do
        if table.contains(outfits, outfit) then
            return bonus
        end
    end
    return nil
end

function Creature:onChangeOutfit(outfit)
    if not self:isPlayer() then
        return true
    end
    local previousBonusCondition = getBonusCondition(self:getOutfit().lookMount)
    local newBonusCondition = getBonusCondition(outfit.lookMount)
    if previousBonusCondition then
        self:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, previousBonusCondition:getSubId())
    end
    if newBonusCondition then
        self:addCondition(newBonusCondition)
    end
    return true
end
no errors in console and no bonus couldn't understand the reason why i doesn't receive bonus?
 
I'am trying to use it for mounts bonus system but it didn't work.

didn't do anything different.
Code:
--Login.lua
    -- Outfit bonus
    local bonusCondition = getBonusCondition(player:getOutfit().lookMount)
    if bonusCondition then
        player:addCondition(bonusCondition)
    end

Code:
-- CREATURE.LUA
function createBonusCondition(id, params)
    local condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
    condition:setParameter(CONDITION_PARAM_TICKS, -1)
    condition:setParameter(CONDITION_PARAM_SUBID, id)
    for i = 1, #params do
        local param = params[i].param
        local value = params[i].value
        condition:setParameter(param, value)
    end
    return condition
end

outfitBonuses = {
    [{33, 33}] = createBonusCondition(1, {
            {param = CONDITION_PARAM_STAT_MAGICPOINTS, value = 10},
            {param = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, value = 110}
        }
    ),
    -- [{427, 426}] = createBonusCondition(2, {
            -- {param = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, value = 200}
        -- }
    -- )
}

function getBonusCondition(outfit)
    for outfits, bonus in pairs(outfitBonuses) do
        if table.contains(outfits, outfit) then
            return bonus
        end
    end
    return nil
end

function Creature:onChangeOutfit(outfit)
    if not self:isPlayer() then
        return true
    end
    local previousBonusCondition = getBonusCondition(self:getOutfit().lookMount)
    local newBonusCondition = getBonusCondition(outfit.lookMount)
    if previousBonusCondition then
        self:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, previousBonusCondition:getSubId())
    end
    if newBonusCondition then
        self:addCondition(newBonusCondition)
    end
    return true
end
no errors in console and no bonus couldn't understand the reason why i doesn't receive bonus?
Do you have onChangeOutfit set to enabled="1" in events.xml?
 
Back
Top