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

Server log shows how much other player hits (remove)

Lopaskurwa

Active Member
Joined
Oct 6, 2017
Messages
870
Solutions
2
Reaction score
49
Hi, by default tfs 1.2 have this function if you stand to next player you can see his dmg in server-log which makes no sense because it should only show yours not someone else who stands next to you and deals so dmg to monster. Im not talking about when he hits you.
 
This worked for me, removed the spectatorMessage, player vs player still normally, now it just show when player get experience.
Omfg im so stupid i didnt added if statement to all spectators now it works for me to. He said that its kinda ugly solution so if im not going to use this spectator stuff in my entire life maybe its possible to completely remove it from source because now its unnecessary code usage, same with gained experience.
 
From experience I just removed the statement because I didn't know where to add this solution he gave, and seems that's working well.

I dont know why it's an ugly solution, but if haven't any bug for me it's ok... If you discover anything else please post here
 
You wont encounter any bugs in the previous solution and I called it ugly because we don't have to create the spectatorMessage at all if we aren't going to use it anywhere. You could change otland/forgottenserver (https://github.com/otland/forgottenserver/blob/1.2/src/game.cpp#L4003-L4041) to:
C++:
if (message.primary.color != TEXTCOLOR_NONE || message.secondary.color != TEXTCOLOR_NONE) {
    std::string damageString = std::to_string(realDamage) + (realDamage != 1 ? " hitpoints" : " hitpoint");

    for (Creature* spectator : list) {
        Player* tmpPlayer = spectator->getPlayer();
        if (tmpPlayer->getPosition().z != targetPos.z) {
            continue;
        }

        if (tmpPlayer == attackerPlayer && attackerPlayer != targetPlayer) {
            message.type = MESSAGE_DAMAGE_DEALT;
            message.text = ucfirst(target->getNameDescription()) + " loses " + damageString + " due to your attack.";
            tmpPlayer->sendTextMessage(message);
        } else if (tmpPlayer == targetPlayer) {
            message.type = MESSAGE_DAMAGE_RECEIVED;
            if (!attacker) {
                message.text = "You lose " + damageString + '.';
            } else if (targetPlayer == attackerPlayer) {
                message.text = "You lose " + damageString + " due to your own attack.";
            } else {
                message.text = "You lose " + damageString + " due to an attack by " + attacker->getNameDescription() + '.';
            }
            tmpPlayer->sendTextMessage(message);
        }
    }
}
 
You wont encounter any bugs in the previous solution and I called it ugly because we don't have to create the spectatorMessage at all if we aren't going to use it anywhere. You could change otland/forgottenserver (https://github.com/otland/forgottenserver/blob/1.2/src/game.cpp#L4003-L4041) to:
C++:
if (message.primary.color != TEXTCOLOR_NONE || message.secondary.color != TEXTCOLOR_NONE) {
    std::string damageString = std::to_string(realDamage) + (realDamage != 1 ? " hitpoints" : " hitpoint");

    for (Creature* spectator : list) {
        Player* tmpPlayer = spectator->getPlayer();
        if (tmpPlayer->getPosition().z != targetPos.z) {
            continue;
        }

        if (tmpPlayer == attackerPlayer && attackerPlayer != targetPlayer) {
            message.type = MESSAGE_DAMAGE_DEALT;
            message.text = ucfirst(target->getNameDescription()) + " loses " + damageString + " due to your attack.";
            tmpPlayer->sendTextMessage(message);
        } else if (tmpPlayer == targetPlayer) {
            message.type = MESSAGE_DAMAGE_RECEIVED;
            if (!attacker) {
                message.text = "You lose " + damageString + '.';
            } else if (targetPlayer == attackerPlayer) {
                message.text = "You lose " + damageString + " due to your own attack.";
            } else {
                message.text = "You lose " + damageString + " due to an attack by " + attacker->getNameDescription() + '.';
            }
            tmpPlayer->sendTextMessage(message);
        }
    }
}
So if i change into this, i still need to add if statements in player.cpp on spectators? And anyway
C++:
1>..\src\game.cpp(3914): error C2065: 'MESSAGE_DAMAGE_DEALT': undeclared identifier
1>..\src\game.cpp(3918): error C2065: 'MESSAGE_DAMAGE_RECEIVED': undeclared identifier
 
So if i change into this, i still need to add if statements in player.cpp on spectators? And anyway
C++:
1>..\src\game.cpp(3914): error C2065: 'MESSAGE_DAMAGE_DEALT': undeclared identifier
1>..\src\game.cpp(3918): error C2065: 'MESSAGE_DAMAGE_RECEIVED': undeclared identifier
bump
 
Simple google search would tell you that you're trying to use a variable that is not defined.
You must have deleted MESSAGE_DAMAGE_DEALT and MESSAGE_DAMAGE_RECEIVED completely, either re-add them or remove the lines that require it since you want to remove the ability to see other's hits.
 
Simple google search would tell you that you're trying to use a variable that is not defined.
You must have deleted MESSAGE_DAMAGE_DEALT and MESSAGE_DAMAGE_RECEIVED completely, either re-add them or remove the lines that require it since you want to remove the ability to see other's hits.
If i remove MESSAGE_DAMAGE_DEALT and MESSAGE_DAMAGE_RECEIVED isnt it gonna to remove entire damage hit from server-log not only for spectators? Since it should effect only spectators
 
Change this:
C++:
for (Creature* spectator : spectators) {
                Player* tmpPlayer = spectator->getPlayer();
                if (tmpPlayer->getPosition().z != targetPos.z) {
                    continue;
                }

                if (tmpPlayer == attackerPlayer && attackerPlayer != targetPlayer) {
                    ss.str({});
                    ss << ucfirst(target->getNameDescription()) << " loses " << damageString << " due to your attack.";
                    message.type = MESSAGE_STATUS_DEFAULT;
                    message.text = ss.str();
                } else if (tmpPlayer == targetPlayer) {
                    ss.str({});
                    ss << "You lose " << damageString;
                    if (!attacker) {
                        ss << '.';
                    } else if (targetPlayer == attackerPlayer) {
                        ss << " due to your own attack.";
                    } else {
                        ss << " due to an attack by " << attacker->getNameDescription() << '.';
                    }
                    message.type = MESSAGE_STATUS_DEFAULT;
                    message.text = ss.str();
                } else {
                    message.type = MESSAGE_STATUS_DEFAULT;

                    if (spectatorMessage.empty()) {
                        ss.str({});
                        ss << ucfirst(target->getNameDescription()) << " loses " << damageString;
                        if (attacker) {
                            ss << " due to ";
                            if (attacker == target) {
                                if (targetPlayer) {
                                    ss << (targetPlayer->getSex() == PLAYERSEX_FEMALE ? "her own attack" : "his own attack");
                                } else {
                                    ss << "its own attack";
                                }
                            } else {
                                ss << "an attack by " << attacker->getNameDescription();
                            }
                        }
                        ss << '.';
                        spectatorMessage = ss.str();
                    }

                    message.text = spectatorMessage;
                }
                tmpPlayer->sendTextMessage(message);
            }
        }

        if (realDamage >= targetHealth) {
            for (CreatureEvent* creatureEvent : target->getCreatureEvents(CREATURE_EVENT_PREPAREDEATH)) {
                if (!creatureEvent->executeOnPrepareDeath(target, attacker)) {
                    return false;
                }
            }
        }

        target->drainHealth(attacker, realDamage);
        addCreatureHealth(spectators, target);
    }

    return true;
}

To this:
C++:
for (Creature* spectator : spectators) {
                Player* tmpPlayer = spectator->getPlayer();
                if (tmpPlayer->getPosition().z != targetPos.z) {
                    continue;
                }

                if (tmpPlayer == attackerPlayer && attackerPlayer != targetPlayer) {
                    ss.str({});
                    ss << ucfirst(target->getNameDescription()) << " loses " << damageString << " due to your attack.";
                    message.type = MESSAGE_STATUS_DEFAULT;
                    message.text = ss.str();
                } else if (tmpPlayer == targetPlayer) {
                    ss.str({});
                    ss << "You lose " << damageString;
                    if (!attacker) {
                        ss << '.';
                    } else if (targetPlayer == attackerPlayer) {
                        ss << " due to your own attack.";
                    } else {
                        ss << " due to an attack by " << attacker->getNameDescription() << '.';
                    }
                    message.type = MESSAGE_STATUS_DEFAULT;
                    message.text = ss.str();
                } else {
                    message.type = MESSAGE_STATUS_DEFAULT;

                    message.text = spectatorMessage;
                }
                tmpPlayer->sendTextMessage(message);
            }
        }

        if (realDamage >= targetHealth) {
            for (CreatureEvent* creatureEvent : target->getCreatureEvents(CREATURE_EVENT_PREPAREDEATH)) {
                if (!creatureEvent->executeOnPrepareDeath(target, attacker)) {
                    return false;
                }
            }
        }

        target->drainHealth(attacker, realDamage);
        addCreatureHealth(spectators, target);
    }

    return true;
}
 
Back
Top