• 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] Custom Conditions or Another Way

Otfan125

Well-Known Member
Joined
Mar 1, 2008
Messages
169
Solutions
1
Reaction score
55
Location
Thais
TFS VERSION: 1.3
Hey guys,
I'm trying to create an onLogin script that reads the 'players' database and sets a special condition/effect/attribute to a player until s/he logs out.
However, I want these attributes to be unique... for example: if a player has the value for column 'blade' in his 'players' database, the onLogin script should set a condition/effect/attribute (e.g., "CONDITION_BLADE") on the player that can be read by other lua scripts as 'if player:hasCondition(CONDITION_BLADE)'

I've tried to register a new condition called "CONDITION_BLADE" in enums.h and registred it in luascript.cpp.
Here is my current onLogin code:

Lua:
function onLogin(player)
    local res = db.storeQuery("SELECT `blademaster` FROM `players` WHERE `name` = \"Angel\";")
    if res == 1 then
        local condition = Condition(CONDITION_BLADEMASTER)
        condition:setParameter(CONDITION_PARAM_TICKS, -1)
        player:addCondition(condition)
    end
    return true
end

The idea is that it reads the player database for player=Angel and sees if the column "blademaster" is set to 1.
If yes, it should set the condition "CONDTIION_BLADEMASTER" and have it tick for "-1", meaning it forever.
Though, CONDITION_BLADEMASTER returns the following:

Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/blademaster.lua:onLogin
data/creaturescripts/scripts/blademaster.lua:8: attempt to index local 'condition' (a nil value)
stack traceback:
    [C]: in function '__index'
    data/creaturescripts/scripts/blademaster.lua:8: in function <data/creaturescripts/scripts/blademaster.lua:2>

This doesn't happen if I test with CONDITION_INVISIBLE.
Any pointers in creating new conditions and/or a better way of setting specific attributes/effects to a player until logout is greatly appreciated!
Thanks
 
Solution
adding a few lines to luascript doesnt mean you added them but instead you tried to register them.
You need to create a new one here: otland/forgottenserver (https://github.com/otland/forgottenserver/blob/master/src/condition.cpp)
I'm a little busy but take a look at a simple one and try to replicate it.
If you run into some problems keep updating this thread and I will come.

Thanks for pointing me to condition.cpp; I should have known that simply registering conditions doesn't do anything -_-
Whenever I get some time today I'll attempt to implement a new condition. :)
Post automatically merged:

Okay so, the solution (on top of what I've tried) is to create a case for your new condition in conditions.cpp in the function:
C++:
Condition* Condition::createCondition(ConditionId_t id, ConditionType_t type, int32_t ticks, int32_t param/* = 0*/, bool buff/* = false*/, uint32_t subId/* = 0*/, bool aggressive/* = false */)
 
Last edited:
Back
Top