otland / forgottenserver

A free and open-source MMORPG server emulator written in C++
https://otland.net
GNU General Public License v2.0
1.56k stars 1.04k forks source link

How do Conditions work and why do we need them? #4681

Closed kevinkouketsu closed 2 months ago

kevinkouketsu commented 2 months ago

I am very new to tibia servers. I am trying to figure out why we need Conditions.

Like... A very simple example:

local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local condition = Condition(CONDITION_INVISIBLE)
condition:setParameter(CONDITION_PARAM_TICKS, 200000)
combat:addCondition(condition)

function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end

What is this doing? I don't get it. Another one:

    local condition = Condition(CONDITION_OUTFIT)
    condition:setOutfit(monsterType:getOutfit())
    condition:setTicks(time)
    self:addCondition(condition)

It sounds like changing the outfit to monsterType:getOutfit result after time ticks. But can't it be done by just setting the outfit? Sorry if this is not the right place to post or if there is documentation but I did not find any documentation related to that.

EvilHero90 commented 2 months ago

You could basicly say they're managed timer events. If you tried to achieve the same with addEvent you would stumble across different obstacles such as: You have to manage what happens when the Creature is not alive anymore (could lead to potential server crashes on calling invalid Creature data) or a Player has logged out at the right time and now logs back in and has the changes permanently. Conditions basicly cover all these problems as they're managed for those cases.

For more questions or such you can either use the support board at https://otland.net/forums/support.16/ or read through our Wiki: