Flatlander
Species Developer
Here is my tutorial adding monster ViewRange.
This is how far a Monster can "see" you and start chasing you. (Not to be confused with Target Range, which is the distance a monster stands to attack you)
I HIGHLY suggest following my Pathfinding tutorial if you plan to have monsters follow players over 15 tiles away. You can locate this tutorial here:
Optimizing TFS Pathfinding
Now onto the ViewRange Source Edits:
In monsters.h add the following line:
in monsters.cpp add the following 2 lines:
Now that we have the value, we have to basically update the ViewRange in certain areas of TFS (Hope 1.X isn't much different than 0.X here)
In creature.cpp you will need to edit canSee: (I do this using Storage Values on 0.X, but i'm going to use mType here since I do not know if monsters can have storage values in 1.X)
Creature.cpp add:
Creature.cpp change:
We must change creatures to use the new viewRange (but not break other creaturetypes)
I THINK that is all the changes that are required. If it doesn't work, let me know.
Disclaimer:
I am self-taught, the way I do things most likely is terrible an inefficient and I also do not use TFS 1.X.
Feel free to give pointers, and provide optimizations and I'll gladly update the tutorial so everyone has a better time.
This is how far a Monster can "see" you and start chasing you. (Not to be confused with Target Range, which is the distance a monster stands to attack you)
I HIGHLY suggest following my Pathfinding tutorial if you plan to have monsters follow players over 15 tiles away. You can locate this tutorial here:
Optimizing TFS Pathfinding
Now onto the ViewRange Source Edits:
In monsters.h add the following line:
Code:
LightInfo light = {};
uint16_t lookcorpse = 0;
uint64_t experience = 0;
int32_t viewRange = 11; // Add this line, 11 is the Default viewRange for monsters in this case
uint32_t manaCost = 0;
in monsters.cpp add the following 2 lines:
Code:
} else if (strcasecmp(attrName, "runonhealth") == 0) {
mType->info.runAwayHealth = pugi::cast<int32_t>(attr.value());
} else if (strcasecmp(attrName, "viewRange") == 0) { //Add this line to find the flag viewRange
mType->info.viewRange = pugi::cast<int32_t>(attr.value()); //This line sets the value
Now that we have the value, we have to basically update the ViewRange in certain areas of TFS (Hope 1.X isn't much different than 0.X here)
In creature.cpp you will need to edit canSee: (I do this using Storage Values on 0.X, but i'm going to use mType here since I do not know if monsters can have storage values in 1.X)
Creature.cpp add:
Code:
extern Game g_game;
extern Monsters g_monsters; //Add this so we can get the mType
Code:
bool Creature::canSee(const Position& pos) const
{
return canSee(getPosition(), pos, Map::maxViewportX, Map::maxViewportY);
}
Code:
bool Creature::canSee(const Position& pos) const
{
int viewX = Map::maxViewportX
int viewY = Map::maxViewportY
MonsterType* mType = g_monsters.getMonsterType(this->getName());
if(mtype) {
viewX = mType->info.viewRange;
viewY = mType->info.viewRange;
}
return canSee(getPosition(), pos, viewX, viewY);
}
I THINK that is all the changes that are required. If it doesn't work, let me know.
Disclaimer:
I am self-taught, the way I do things most likely is terrible an inefficient and I also do not use TFS 1.X.
Feel free to give pointers, and provide optimizations and I'll gladly update the tutorial so everyone has a better time.