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

Windows Addition next to nick

divers

New Member
Joined
Jul 31, 2013
Messages
20
Reaction score
1
Hello, i want to ask you guys how i can add some information next to player nick?
I found out that it is in protocolgame.cpp.
I have somethink like this:

std::stringstream ss;
ss << creature->getName();
if(creature->getPlayer()->getplayerguild())
ss << " ["<< creature->getPlayer()->getplayerguild() <<"]";
msg->AddString(creature->getHideName() ? "" : ss.str());

getplayerguild doesn't exist because i dont know how to do it.
Please help me write this :x

TFS 8.54 (0.3.6pl)
 
Last edited:
It is not just a matter of adding a function to the stream to be outputted, the function needs 1st and foremost to exist, if it doesn't exist in the current file it needs to be included.

I don't know what distro that code is from so I can't even help you.

Make it a habit to post the distro your working in.. e.g. 0.4, 1.x etc
 
TFS 8.54 (0.3.6pl), the function doesnt exist, i dont know how to add function which will take data from guild table in mysql :/
 
You can use these function on object Player:
PHP:
uint32_t getGuildId() const {return guildId;}
uint32_t getRankId() const {return rankId;}

GuildLevel_t getGuildLevel() const {return guildLevel;}

const std::string& getGuildName() const {return guildName;}
const std::string& getRankName() const {return rankName;}

const std::string& getGuildNick() const {return guildNick;}
So it can be (display guild name):
PHP:
// FIRST MAKE SURE THAT IT IS A PLAYER! IT CAN BE MONSTER/NPC, IF YOU GET GUILD OF MONSTER SERVER WILL CRASH!
// line below check if creature is player and store 'Player' in 'tmpPlayer'
if(const Player* tmpPlayer = creature->getPlayer())
{
   ss << " ["<< tmpPlayer->getGuildName() <<"]";
}

I THINK IT WILL NOT WORK IN MOST CASES, BECAUSE WHEN YOU CLICK RIGHT MOUSE BUTTON ON PLAYER AND TRY TO MESSAGE HIM IT WILL TRY TO USE HIS NAME AND HIS GUILD NAME AS HIS NAME!

EDIT:

Modified code, so it uses 'const Player*'
 
Last edited:
Okey, now it works, but what about, when i want to add new functions like: getGuildName?
Add them in player.h (and in player.cpp if they are advanced).. or creature/NPC/monster, whatever you want to add.
You can use 'getNpc()' and 'getMonster()' or 'creature' same as you did with 'getPlayer' to check if this creature is player/monster/NPC and store it in 'Npc*' and 'Monster*'.

EDIT:
Of course list of functions is much longer:
PHP:
virtual RaceType_t getRace() const {
return RACE_NONE;
}
virtual Skulls_t getSkull() const {
return skull;
}
virtual Skulls_t getSkullClient(const Creature* creature) const {
return creature->getSkull();
}
void setSkull(Skulls_t newSkull);
Direction getDirection() const {
return direction;
}
void setDirection(Direction dir) {
direction = dir;
}
bool isHealthHidden() const {
return hiddenHealth;
}
void setHiddenHealth(bool b) {
hiddenHealth = b;
}
int32_t getThrowRange() const final {
return 1;
}
bool isPushable() const override {
return getWalkDelay() <= 0;
}
bool isRemoved() const final {
return isInternalRemoved;
}
virtual bool canSeeInvisibility() const {
return false;
}
virtual bool isInGhostMode() const {
return false;
}
int32_t getWalkDelay(Direction dir) const;
int32_t getWalkDelay() const;
int64_t getTimeSinceLastMove() const;
int64_t getEventStepTicks(bool onlyDelay = false) const;
int64_t getStepDuration(Direction dir) const;
int64_t getStepDuration() const;
virtual int32_t getStepSpeed() const {
return getSpeed();
}
int32_t getSpeed() const {
return baseSpeed + varSpeed;
}
void setSpeed(int32_t varSpeedDelta) {
int32_t oldSpeed = getSpeed();
varSpeed = varSpeedDelta;
if (getSpeed() <= 0) {
stopEventWalk();
cancelNextWalk = true;
} else if (oldSpeed <= 0 && !listWalkDir.empty()) {
addEventWalk();
}
}
void setBaseSpeed(uint32_t newBaseSpeed) {
baseSpeed = newBaseSpeed;
}
uint32_t getBaseSpeed() const {
return baseSpeed;
}
int32_t getHealth() const {
return health;
}
virtual int32_t getMaxHealth() const {
return healthMax;
}
uint32_t getMana() const {
return mana;
}
virtual uint32_t getMaxMana() const {
return 0;
}
(....)
PHP:
uint32_t getLevel() const {
return level;
}
uint32_t getMagicLevel() const {
return getPlayerInfo(PLAYERINFO_MAGICLEVEL);
}
uint32_t getBaseMagicLevel() const {
return magLevel;
}
uint8_t getSoul() const {
return soul;
}
bool isAccessPlayer() const {
return group->access;
}
bool isPremium() const;
void setPremiumDays(int32_t v);
uint16_t getHelpers() const;
bool setVocation(uint16_t vocId);
uint16_t getVocationId() const {
return vocation->getId();
}
PlayerSex_t getSex() const {
return sex;
}
void setSex(PlayerSex_t);
int32_t getPlayerInfo(playerinfo_t playerinfo) const;
uint64_t getExperience() const {
return experience;
}
time_t getLastLoginSaved() const {
return lastLoginSaved;
}
time_t getLastLogout() const {
return lastLogout;
}
const Position& getLoginPosition() const {
return loginPosition;
}
const Position& getTemplePosition() const {
return town->getTemplePosition();
}
Town* getTown() const {
return town;
}
void setTown(Town* _town) {
town = _town;
}
and many many others.
 
So i tried something like this:
player.h
const std::string& getGuildTag() const {return guildTag;}
void setGuildTag(const std::string& newName) {guildTag = newName;}

protocolgame.cpp

if(const Player* tmpPlayer = creature->getPlayer())
{
ss << " ["<< tmpPlayer->getGuildTag() <<"]";
}

and it crashes server when i try to log in.
 
So i tried something like this:
player.h
const std::string& getGuildTag() const {return guildTag;}
void setGuildTag(const std::string& newName) {guildTag = newName;}

protocolgame.cpp

if(const Player* tmpPlayer = creature->getPlayer())
{
ss << " ["<< tmpPlayer->getGuildTag() <<"]";
}

and it crashes server when i try to log in.
What is guild tag? Is it set at login of player? If you try to print 'null' value it will crash server.
Isn't it guild nick? There is already: getGuildNick()
 
Back
Top