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