• 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] Some codes.

slaw

Software Developer
Joined
Aug 27, 2007
Messages
3,663
Solutions
125
Reaction score
1,109
Location
Germany
GitHub
slawkens
I'm just starting with c++, here i will be giving some tips to beginners.

List od TIPS:
1. Houses from LEVEL.
2. How to change guilds from LEVEL.


1. Houses from LEVEL.
Easy, simple code. Taked from another sources.

commands.cpp
after
Code:
if(player->isPremium())
{
put
Code:
if(player->getLevel() >= g_config.getNumber(ConfigManager::HOUSE_LEVEL))
{
before
Code:
else
player->sendCancel("You need a premium account.");
}
put
Code:
else
player->sendCancel("You need 25 level do buy a house.");
}

configmanager.cpp
after
Code:
m_confInteger[HOUSE_PRICE] = getGlobalNumber(L, "housePriceEachSQM", 1000);
put
Code:
m_confInteger[HOUSE_LEVEL] = getGlobalNumber(L, "houselevel", 25);
configmanager.h
after
Code:
HOUSE_PRICE,
put
Code:
HOUSE_LEVEL,
Gratz! Now you have house from level. ;) Now you just need add to config:
Code:
houselevel = 25

2. How to change guild from LEVEL.
Just search in commands.cpp
Code:
if(player->level > 7)
change to:
Code:
if(player->level >= [B]30[/B])
and you need too change this:
Code:
player->sendCancel("You have to be atleast Level 8 to form a guild.");
Where 30 you can change from which level do you want to guild creating.
 
Last edited:
Code:
else
player->sendCancel("You need a premium account.");
}
put
Code:
else
player->sendCancel("You need 25 level do buy a house.");
}

erm.. if i change in config.lua the level for buy house the cancel msg will stay at level 25? ;)

but ty ;*
 
Yes, you need too change it there ;) I don't know how to put there level from config.

Meybe somethink like this:
Code:
player->sendCancel("You need ."g_config.getNumber(ConfigManager::HOUSE_LEVEL)". level do buy a house.");

Didn't thied, i don't know how to glue this both ;s. In php it is ." so MEYBE it will work
 
Improved it a bit.

commands.cpp, find:
Code:
bool Commands::sellHouse(Creature* creature, const std::string& cmd, const std::string& param)
{
	Player* player = creature->getPlayer();
add after it:
Code:
	uint32_t requiredLevel = g_config.getNumber(ConfigManager::HOUSE_LEVEL); //Added manually
find:
Code:
		if(tradePartner->level < 1)
		{
			player->sendCancel("Trade player level is too low.");
			return false;
		}
replace with:
Code:
		if(tradePartner->level < requiredLevel) //Changed manually
		{
			char buffer[80]; //Added manually
			sprintf(buffer, "Trade player has to be at least Level %i to buy house.", requiredLevel); //Added manually
			player->sendCancel(buffer); //Changed manually
			return false;
		}
find:
Code:
bool Commands::buyHouse(Creature* creature, const std::string& cmd, const std::string& param)
{
	Player* player = creature->getPlayer();
add after it:
Code:
	uint32_t requiredLevel = g_config.getNumber(ConfigManager::HOUSE_LEVEL); //Added manually
find:
Code:
							if(player->isPremium())								{
add after it:
Code:
								if(player->getLevel() >= requiredLevel) //Added manually
								{
find:
Code:
										player->sendCancel("That house doesn't contain any house tile.");
								}
add after it:
Code:
								else
								{
									char buffer[80]; //Added manually
									sprintf(buffer, "You have to be at least Level %i to buy a house.", requiredLevel); //Added manually
									player->sendCancel(buffer); //Changed manually
								}
now follow slawkenks steps in configmanager.cpp and configmanager.h then compile the server.

Whats the difference? Code posted by slawkens has use, but minor.
It disallowed player only from buying an empty house, what means, he could still buy a house from other player.
Quite stupid, since I could ask a friend to buy house for me, then sell it for same price, and abrakadabra - i got the house.
My improvement disallows a player from buying house also from other player(s) - !sellhouse command.
hf ;)
 
@FightingElf
i cant add

967 C:\Documents and Settings\cybertel\Escritorio\theforgottenserver-r687-src\src\commands.cpp `buffer' was not declared in this scope
 
Back
Top