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

Should We Start Learn TFS Coding ?

Should We Start Doing it?


  • Total voters
    47
  • Poll closed .

EvilSkillz

Back
Joined
Jul 12, 2012
Messages
1,810
Solutions
2
Reaction score
388
Location
Egypt - Cairo
Guys
Should we try it together?
like we take the files from tfs source
and explain it step by step ?

What Do i gain from this?
well for fact i wanna do this to increase my experience with source

What Do otlander can gain from this?
well , we will help each other to understand how to code the source
what can this function do in source
how to change it , how to add new functions to source .

Why Do I take this step?
well , i'm bored
and i won't say i'm expert at it
but we can explain to each other
help each other
and guess what :)

we can understand how to make the perfect server :)

this Poll has 7 days to end
after it end
i will see result if i should begin or not
 
What a great initiative! I am not good at all in TFS source so I can not help with this.
But, we have a lot of guys here on OTLand that are good with this.

So if you start with this, be sure to always be up to date with newest tfs 1.0 codes.
 
ofc. i will use tfs 1.0
i will explain tfs 1.0

but it's not a big problem with other revs
this will be for every one to understand how can tfs work
how can the function work

so if u understand it here , u are able to understand it at any rev
and i hope after my explain
people won't only understand source
but they can able to create own system :)


after i finish this tfs explain .. and i saw that's i'm good :) and people like it
i will try to learn otclient and explain otclient so we can do what ever we imagine
 
This would be something I could help out with, would be a learning experience for me also because I have no knowledge of network programming.
 
i will start it tomorrow instead of 12/4
because i have family problems :( my uncle is near to death
so i will do all my best to finish it today till tomorrow

because i don't think i can be here for few coming months
 
Yes this will be great!

And will keep your Uncle in our prayers
 
Last edited:
i will start it tomorrow instead of 12/4
because i have family problems :( my uncle is near to death
so i will do all my best to finish it today till tomorrow

because i don't think i can be here for few coming months
I wish you best luck with both your family problems and your tutorial, I'll sure follow this.

Keep it up m8! :)
 
I will be watching this closely :).

When you start going through TFS Source, you find ALL SORTS of things you want to fix or make better.
 
not really
I'd rather focus on lua scripting and stay up to date with official sources.
I edit sources only when there is no other way to make my script working.
 
not really
I'd rather focus on lua scripting and stay up to date with official sources.
I edit sources only when there is no other way to make my script working.

I used to be like you, making complex LUA scripts you can do some amazing things.
Then I started editing sources....

Now I have Monsters that can open doors, chase you down and up stairs, seagulls can fly through windows and over bushes and trees, ghosts can go through walls, my monsters have aggro and don't follow a random targeting system. Orcs and Minotaurs and other creatures are hostile to each other will attack each other, and if a friendly Orc Shaman is about to cast Fireball, other orcs will run out of the way so they do not get hit by the splash damage.
Once you start editing the source, literally anything is possible as long as it logically could happen in a 2d tile based game.
 
Would be cool, don't know alot about the source code here, not alot about c++ either. But its always nice knowing when the day comes, you need help and otland has nothing to give :)
 
I think it is good idea, I was fixing 0.4 source by myself, step by step, so I think it may help you to improve C++ skill at all.

As @Flatlander said, you will be able to edit it by yourself and add some things whatever you want to do, which is not avaiable in LUA.
 
so i will start with 9 files now
guys ofc. i won't write the whole code
i will explain functions

if you understand one you have to understand the others
like i look in source
and i can see 4 functions but them need the same idea to work
so i take the hard one of them and explain it :)
i can't explain 1234567890 letters explained in 1234567890 lines :)
this will take a years xD

and after this end i will make a good list
with every thing you may need in TFS
like actions , attr from all files
 
Welcome OTLand to my SourceTuTEx
EvilSkillz here !!

Why do i make this tutorial before the poll time end ?
because i have my reasons .. my uncle is very near to death .. and i won't be here in these coming days , so i decided to make it in these days


so let's start with few identify

as you know every programming language contain source files
and in this TFS source you can find files with 2 extensions
*.cpp && *.h
what are these extensions back for?

well the *.cpp files are the data in source to explain what does code represent for
the *.h files are the definitions of data you already typed in *.cpp files

and sometimes you can see #include "*.h"
this to include headers files to get the definitions to the data you typed

so let's start and let's understand what do i mean ....

account.h

as you can see it's include this file "enums.h"

ofc. you understand that account.h need few things from enums.h , but what are these things?
we can see that account.h include data for other things too
but there something not explained into it
what is it ?

as you see code
Code:
Account() {
            id = 0;
            accountType = ACCOUNT_TYPE_NORMAL;
        }

that's mean if accountID = 0 == nothing
it should return type with ACCOUNT_TYPE_NORMAL

but how can it understand this type ?
let's go now to enums.h

here it the definition of account types
Code:
enum AccountType_t {
        ACCOUNT_TYPE_NORMAL = 1,
        ACCOUNT_TYPE_TUTOR = 2,
        ACCOUNT_TYPE_SENIORTUTOR = 3,
        ACCOUNT_TYPE_GAMEMASTER = 4,
        ACCOUNT_TYPE_GOD = 5
    };


little info .. you can find in all *.cpp in this TFS source something included #include "otpch.h"
i won't explain this because it's explain itself

now let's start with actions.cpp

first we can see "extern" word .. what does it mean?

extern tells the compiler that the variable is defined somewhere else , so it doesn't complain about it being undefined.

and we should understand now why to use include files

now after extern we can see actionInterface and actionClear
so here we start
Code:
inline void Actions::clearMap(ActionUseMap& map)

this function based to clear map

and here we start action to understand it
Code:
bool Actions::registerEvent(Event* event, const pugi::xml_node& node)

we can see there the attr can be used in actions :)
for example
itemid , fromid - toid , uniqueid , fromuid - touid , actionid , fromaid - toaid

ofc you knew these things :)
now we need to understand few things why we get few messages like [ can't use , not possible , first do something ]

here we can see a little explain in this function
Code:
ReturnValue Actions::canUse(const Player* player, const Position& pos)
inside it we can see this

Code:
        if (playerPos.z != pos.z) {
            return playerPos.z > pos.z ? RET_FIRSTGOUPSTAIRS : RET_FIRSTGODOWNSTAIRS;
        }
it's explain if player floor not the same as the thing you need to use will give you 2 messages
first if your pos > thing pos .. you get goDown
esle you get goUp
these are defined in enums.h

and this code
Code:
        if (!Position::areInRange<1, 1>(playerPos, pos)) {
            return RET_TOOFARAWAY;
        }
if pos not in range will say TooFarAway ;

if every thing is good
as if (pos.x != 0xFFFF)

it will return NO_ERROR

and doors :
Code:
    if (Door* door = item->getDoor()) {
        if (!door->canUse(player)) {
            return RET_CANNOTUSETHISOBJECT;
        }
    }
if it door but can't be used you get message

if scripted or functioned
Code:
if (action->isScripted()) {
            if (action->executeUse(player, item, posEx, posEx, false, 0)) {
                return RET_NOERROR;
            }
        } else if (action->function) {
            if (action->function(player, item, posEx, posEx, false)) {
                return RET_NOERROR;
            }
        }
no error :)

and then the same with beds , containers , readable items
NOTE -- Some Attribute from const.h , item.h , container.h , etc.. we will explain them when we go for other files

now actions.h
read it to understand more about how to configure and define data you typed in actions.cpp

for example
this function in actions.cpp that give you if onUse items with goUp or goDown
Code:
ReturnValue Actions::canUse(const Player* player, const Position& pos)
is identified in actions.h
Code:
class Actions : public BaseEvents
    public:
        Actions();
        virtual ~Actions();
       
    ReturnValue canUse(const Player* player, const Position& pos);

and other already explained just need your read :)
if you understood 1 function you should understand how to make yours

now let's go to ban.cpp
it included ban.h and database.h and tools.h
with your smart brain you have understood ofc. what can be included in these 3 headers :)

ban.h to define data
database.h use for this thing

Code:
bool IOBan::isAccountBanned(uint32_t accountId, BanInfo& banInfo)

Database* db = Database::getInstance();

    std::ostringstream query;
    query << "SELECT `reason`, `expires_at`, `banned_at`, `banned_by`, (SELECT `name` FROM `players` WHERE `id` = `banned_by`) AS `name` FROM `account_bans` WHERE `account_id` = " << accountId;

select it from database to ban the MotherFucker :)
Code:
int64_t expiresAt = result->getNumber<int64_t>("expires_at"); // expire date
and after time expire
it auto delete ban from database
query << "DELETE FROM `account_bans` WHERE `account_id` = " << accountId;

and ban.h contain ban.cpp explain

now with baseevents.cpp
this is to choose path of scripts to let the TFS read them

and here something like this
Code:
    if (getScriptInterface().loadFile(basePath + "lib/" + scriptsName + ".lua") == -1) {
        std::cout << "[Warning - BaseEvents::loadFromXml] Can not load " << scriptsName << " lib/" << scriptsName << ".lua" << std::endl;
    }

bath of basePath it's already defined as "Data/" folder <3
Code:
    std::string scriptsName = getScriptBaseName();
    std::string basePath = "data/" + scriptsName + "/";

so if it find path == -1 means nothing found
it will return can't load because TFS can't find it

now beds.cpp

this is here to make explain of how to use beds
so someone was asking how to make bed for free accounts and don't require premium

so let's start with functions
Code:
bool BedItem::canUse(Player* player)
who can use the bed?

Code:
    if (!player || !house || !player->isPremium()) {
        return false;
    }
if not player or not house or player is not premium
will return false

to remove premium require just delete || !player->isPremium() so it will be like this
Code:
    if (!player || !house) {
        return false;
    }

Code:
    if (sleeperGUID == 0) {
        return true;
    }
if there is no one sleep return true == u can sleep :)

Code:
    if (house->getHouseAccessLevel(player) == HOUSE_OWNER) {
        return true;
    }

if house owner return true
Code:
    if (house->getHouseAccessLevel(&sleeper) > house->getHouseAccessLevel(player)) {
        return false;
    }
if house sleep require level and you don't have it will return false :)

so now we can go down a little bit
this to regenerate player while sleep
Code:
void BedItem::regeneratePlayer(Player* player) const
and configuration based here
Code:
            regen = std::min<int32_t>((condition->getTicks() / 1000), sleptTime) / 30;
            const int32_t newRegenTicks = condition->getTicks() - (regen * 30000);

please give me feedback if i should continue or just start to make functions list
TFS 1.0
 
I used to be like you, making complex LUA scripts you can do some amazing things.
Then I started editing sources....

Now I have Monsters that can open doors, chase you down and up stairs, seagulls can fly through windows and over bushes and trees, ghosts can go through walls, my monsters have aggro and don't follow a random targeting system. Orcs and Minotaurs and other creatures are hostile to each other will attack each other, and if a friendly Orc Shaman is about to cast Fireball, other orcs will run out of the way so they do not get hit by the splash damage.
Once you start editing the source, literally anything is possible as long as it logically could happen in a 2d tile based game.
And funniest thing is that everything you described here can be done in creaturescripts without source edit.

For example:
I have a boss which recovers his full hp when he kills his target, he may throw your character causing some damage or even cast healing spell which affects only selected creatures. Destroying mwalls and placing his own is simple thing too.

There are a lot of possibilities which don't need source edits. All you need is knowledge.
 
Back
Top