• 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 1.X+ Player visibility

Itutorial

Legendary OT User
Joined
Dec 23, 2014
Messages
2,391
Solutions
68
Reaction score
1,063
I want to make it so players can only see creatures in their visibility range. Right now creatures will only update when they leave or enter the screen area. However, I need it to update if they are within the screen area as well.

Here is the main part of the code I am trying to do.

In player.cpp Player::canSeeCreature()
C++:
int16_t visibility = getVisibility();
const Position& position = getPosition();
const Position& creaturePosition = creature->getPosition();
const uint8_t distance = position.getDistanceX(creaturePosition) + position.getDistanceY(creaturePosition);

if (visibility < 2) {
    visibility = 2;
}

if (distance > visibility) {
    return false;
}

It checks if the creature is within their visibility range. If the creature is too far away it returns false so the player cannot see the creature. Again this only happens once the creature is off the screen and the player moves back to the creature. It will not appear on the screen.

Then in Player::onWalk() where I want the code to check if the player can see the creature every time they walk
C++:
uint8_t distance = std::round(getVisibility() / 2);
SpectatorVec spectators;
map.getSpectators(spectators, getPosition(), false, false, 0, distance, 0, distance);
for (Creature* spectator : spectators) {
    if (canSeeCreature(spectator)) {
        sendCreatureAppear(spectator, spectator->getPosition());
    }
}

I know there is something with known creatures and unknown creatures however, it only seems to update creatures off the screen which I want it to be able to in real time.
 
A cool idea to add on to this project would be to actually have something similar to "fog of war" where if a tree/object is blocking the view of the monsters they wont be visible similar to how AOE spells work with walls ^^
 
A cool idea to add on to this project would be to actually have something similar to "fog of war" where if a tree/object is blocking the view of the monsters they wont be visible similar to how AOE spells work with walls ^^
You crazy man. I might use that idea for a pvp situation. Hopefully someone has some type of information for me. Even if its not a direct how to anything will help right now because I have tried everything I can think of and its not even close to working.
Post automatically merged:

Nvm its solved.
 
Last edited:
Back
Top