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

[TFS 0.3/0.4 and 1.x] Vocation interval effect system - configurable in vocations.xml

Nenth

I'm just cleaning here;
Joined
Mar 20, 2016
Messages
46
Reaction score
12
Note: This code was orginally written for TFS 0.3 by Dantez from tibia.net.pl!
I just a little bit changed it to make it work on TFS 1.x.


2034045.png


Code allows you to set different effect for each vocation.
effect="29" <-- Here you can put effect ID
effectInterval="1000" <-- Here you can set Interval

The Forgotten Server 1.x version

Configuration:

Code:
effect="29" effectInterval="1000"

Player.cpp


after:
Code:
lastPong = lastPing;
add:
Code:
lastEffect = lastPong;
after:
Code:
int64_t timeNow = OTSYS_TIME();
add:
Code:
if (vocation && vocation->getEffect() && timeNow - lastEffect >= vocation->getEffectInterval())
    {
        g_game.addMagicEffect(getPosition(), vocation->getEffect());
        lastEffect = timeNow;
    }

Player.h

after:
Code:
uint64_t manaSpent;
add:
Code:
uint64_t lastEffect;

Vocation.cpp

after:
Code:
if ((attr = vocationNode.attribute("description"))) {
            voc.description = attr.as_string();
        }
add:
Code:
if ((attr = vocationNode.attribute("effect"))) {
            voc.effect = pugi::cast<uint32_t>(attr.value());
        }

        if ((attr = vocationNode.attribute("effectInterval"))) {
            voc.effectInterval = pugi::cast<uint32_t>(attr.value());
        }

Vocation.h

after:
Code:
uint64_t getReqMana(uint32_t magLevel);
add:
Code:
uint32_t getEffect() const { return effect; }
void setEffect(uint32_t _effect) { effect = _effect; }

uint32_t getEffectInterval() const { return effectInterval; }
void setEffectInterval(uint32_t _interval) { effectInterval = _interval; }
after:
Code:
uint32_t baseSpeed;
add:
Code:
uint32_t effect;
uint32_t effectInterval;

The Forgotten Server 0.3/0.4 version

Configuration:

Code:
effect="29" interval="1000"

Vocation.h


find:
Code:
uint32_t id, fromVocation, baseSpeed, attackSpeed;

change for:
Code:
uint32_t id, fromVocation, baseSpeed, attackSpeed, effect, effectInterval;

find:
Code:
uint64_t getReqMana(uint32_t magLevel);

add under:
Code:
uint32_t getEffect() const {return effect;}
void setEffect(uint32_t _effect) {effect = _effect;}
uint32_t getEffectInterval() const {return effectInterval;}
void setEffectInterval(uint32_t _interval) {effectInterval = _interval;}

Vocation.cpp

find:
Code:
name = description = "";

add under:
Code:
effect = 0;
effectInterval = 4000;    --here you can configure default interval value

find:
Code:
if(readXMLInteger(p, "lessloss", intValue))
        voc->setLessLoss(intValue);

add under:
Code:
if(readXMLInteger(p, "effect", intValue))
        voc->setEffect(intValue);
if(readXMLInteger(p, "interval", intValue))
    voc->setEffectInterval(intValue);

Player.h

find:
Code:
uint64_t lastAttack;

add under:
Code:
uint64_t lastEffect;

Player.cpp

find:
Code:
lastLoad = lastPing = lastPong = OTSYS_TIME();

change to:
Code:
lastLoad = lastPing = lastPong = lastEffect = OTSYS_TIME();

find:
Code:
int64_t timeNow = OTSYS_TIME();

add under:
Code:
if(vocation && vocation->getEffect() && timeNow - lastEffect >= vocation->getEffectInterval())
{
    g_game.addMagicEffect(getPosition(), vocation->getEffect());
    lastEffect = timeNow;
}

Note:
If your engine after adding this code will keep crashing, then go to your source directory and delete /obj folder and compile your server again. This only happens in TFS 0.3/0.4!

Enjoy!
 
Last edited:
Bump~
I will add TFS 0.3/0.4 and OTServ version on friday if someone is intrested.
 
u can use lua for this
something like this
Code:
function onThink(interval, lastExecution)
for _, name in ipairs(getOnlinePlayers()) do
local cid = getPlayerByName(name)
if isKnight(cid) then
doSendMagicEffect(getPlayerPosition(cid), 22)
doSendAnimatedText(getPlayerPosition(cid), "Knight", TEXTCOLOR_RED)
end
end
return true
end
 
@heba Ofcorse, but I think that C++ is faster and configuration in vocations.xml is more comfortable.
 
I guess you need to provide different position to this line
C++:
g_game.addMagicEffect(getPosition(), vocation->getEffect());
 
Back
Top