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

how to add new spell effects into source code

whitevo

Feeling good, thats what I do.
Joined
Jan 2, 2015
Messages
3,452
Solutions
1
Reaction score
625
Location
Estonia
Soon i get back home, but already trying to find examples how make custom spells for my server. But i cant find any thread what has guide / example how to add new spell effects into game.

For example i want to add spell; gives 50% physical protection for next physical hit you take.
I know that i can modify protection value in vocation with Lua scripts, but i dont know how could i remove the protection value when being hit with specific damage

Thats why my though went to source code alteration.

It would be dope if someone shows the code for this effect to happen, but showing me how to register new spell and what files i have to change is a start.

Full details about the spell:
Ingame command: !Rocksolid
Your character gets 5sec buff (new Sprite? In the ongoing effect area, im talking about the area what shows, what field spells are affecting you)
Character takes 50% less damage from next physical hit (if target would do double physical attack it would only protect the first hit of double attack)
Spell goes on exhaust on 5 sec cast.
Spell does not share cooldown with anything else
Spell looses effect only when 5sec passes after cast or player takes physical damage.
Some items icrease/decrease the %Value
Extraction
Extra info, im using tfs 1.0
 
I have problems with compiling atm, so i cant check does my changes do anything and does the spell work.
But here are the codes. Maybe someone already finds issue here:
PHP:
enum ConditionType_t {
CONDITION_NONE            = 0,
    CONDITION_POISON        = 1,
......
    CONDITION_PHYSICAL_R     = 10001
};
PHP:
bool Game::combatChangeHealth(Creature* attacker, Creature* target, CombatDamage& damage)
// ### custom for physical reduction spell
....  .... ....
    if (target->hasCondition(CONDITION_PHYSICAL_R) && damage.primary.type == COMBAT_PHYSICALDAMAGE) {
      realDamage /= 2;
      target->removeCondition(CONDITION_PHYSICAL_R);
    }
   
    // ###

.... .... ....
PHP:
Condition* Condition::createCondition(ConditionId_t _id, ConditionType_t _type, int32_t _ticks, int32_t param/* = 0*/, bool _buff/* = false*/, uint32_t _subId/* = 0*/)
{
    switch (_type) {
....
        //new
        case CONDITION_PHYSICAL_R:
            return new ConditionGeneric(_id, _type, _ticks, _buff, _subId);
           
        default:
            return nullptr;
    }

The rest are .xml and .lua file
But these are not hard to add. Source code is a lil more tricky
 
No offense but it would help if you knew C++, editing a script is not the same thing as editing the server's source, changing 1 thing in a server's source code can break the entire program or lead to unexpected results if you don't know what your doing :(
 
i had some clue what im doing.

i can read a line, understand it and trace the methods/classes its calling

its simply just harder for me to create new lines

i try to put as much logic into it as i can, but not sure does the program understands my logic.
 
The reason I know you don't know C++ is because the value you assigned to your constant it's last number is not divisible by 2
Code:
CONDITION_PHYSICAL_R = 10001
 
Last edited:
this is not value, this is id (imo)

the value i xut in half is RealDamage
You don't understand if you look at the enum ConditionType_t list you will see that all the entries values assigned to those enums are divisible by 2 and yours is not which will make your entry not work at all.. so just stop editing right there and read a book on C++.

You need to learn a whole lot before you even edit 1 line of code in the server's source, like i said editing the sources is not the same as editing a script.

Besides what you want to accomplish doesn't require a source edit.
 
Besides what you want to accomplish doesn't require a source edit.
well i have no idea what else helps.

and why it must be divided by 2??
and if it rly a must, most likely console will give me error, this value is incorrect.
the poison field has value 1. why is that legit then??
 
well i have no idea what else helps.

Learning helps, if you do everything half-ass you get half-ass results, so pick up a book or watch a video on C++ or lua or whatever and see what you have been missing.. I guarantee you will have an ahh ha moment.
 
Code:
    const Position& position = creature->getPosition();
    g_game.addMagicEffect(position, CONST_ME_POFF);

Not sure that it will work, but I think so haha not the best with tfs functions or c++ at all.
You need to include the g_game aswell if it isen't included into the cpp file.
 
Back
Top