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

Fix/Patch Turn off monster moving!

slaw

Software Developer
Joined
Aug 27, 2007
Messages
3,663
Solutions
125
Reaction score
1,109
Location
Germany
GitHub
slawkens
If you want to be monster was only moving when player is on same floor.

Creature.cpp

Change this:
Code:
bool Creature::canSee(const Position& pos) const
{
	const Position& myPos = getPosition();

	if(myPos.z <= 7)
	{
		//we are on ground level or above (7 -> 0)
		//view is from 7 -> 0
		if((pos.z > 7) || (std::abs(myPos.z - pos.z) > 1))
			return false;
	}
	else if(myPos.z >= 8)
	{
		//we are underground (8 -> 15)
		//view is +/- 2 from the floor we stand on
		if(std::abs(myPos.z - pos.z) > 1)
			return false;
	}

	int offsetz = myPos.z - pos.z;
	if((pos.x >= myPos.x - Map::maxViewportX + offsetz) && (pos.x <= myPos.x + Map::maxViewportX + offsetz) &&
		(pos.y >= myPos.y - Map::maxViewportY + offsetz) && (pos.y <= myPos.y + Map::maxViewportY + offsetz))
		return true;

	return false;
}
to this:
Code:
bool Creature::canSee(const Position& pos) const
{
	const Position& myPos = getPosition();

	if(myPos.z == pos.z)
		return true;

	return false;
}
 
Are you aware of how many bugs and how much higher CPU usage this will cause?
 
No i dont understand, why?

So, how to do it correctly? ;)

Ahh, meybe you mean that this shouldnt be removed?
Code:
	int offsetz = myPos.z - pos.z;
	if((pos.x >= myPos.x - Map::maxViewportX + offsetz) && (pos.x <= myPos.x + Map::maxViewportX + offsetz) &&
		(pos.y >= myPos.y - Map::maxViewportY + offsetz) && (pos.y <= myPos.y + Map::maxViewportY + offsetz))
		return true;

Just say me how to change to be only monsters on same floor was moving.
 
Last edited:
No i dont understand, why?

Monsters will target you if you're only in the same floor as them, you can be on town and the monsters in a hunting ground, no big difference.

You can invite players to party by sending the packets for that, the target player only has to be on the same floor.

You can look at an item which is very far from you, just on the same floor.

You can create a path to an area very far from you, it's enough that it's on the same floor.

Clients will recieve alot of actions that happens on the same floor even if it's very far from them.

It's alot more than that, just let me say that removing the check for x and y position wasn't really smart.
 
Ok, so if i want only to be monsters was using it. That they will move only on same floor. How to do it? Meybe if i'll create this:
bool Creature::canSeePlayer
Code:
bool Creature::canSeePlayer(const Position& pos) const
{
	if(myPos.z != pos.z)
		return false;

	int offsetz = myPos.z - pos.z;
	if((pos.x >= myPos.x - Map::maxViewportX + offsetz) && (pos.x <= myPos.x + Map::maxViewportX + offsetz) &&
		(pos.y >= myPos.y - Map::maxViewportY + offsetz) && (pos.y <= myPos.y + Map::maxViewportY + offsetz))
		return true;

	return false;
}

So where should i also replace canSee with canSeePlayer?


#Edit

Tala please help me :( I want only enable monsters moving only when player is on same floor. Or try search any other memory leak, i just want to be more players was able to play on my server :(

#Edit2

When you are on floor 7 then monster on floor 8, 9 are moving, but you dont see it. So for what is it?

#Edit3

Ahhaha, it was it! :D

I have only 10 min uptime with 50 players, but i see results! It really take not that much CPU. I will see after more uptime.
 
Last edited:
so does this actully work pretty good.. because im thinking im getting lag from hidden monsters and stuff underground.. wondering if this is properly written
 
If you want enable monster moving only on same floor:
In creature.cpp after:
Code:
bool Creature::canSee(const Position& pos) const
{
	const Position& myPos = getPosition();
add
Code:
	const Monster* isMonster = getMonster();

	if(isMonster && myPos.z != pos.z)
		return false;
 
i think this will work

Code:
bool Creature::canSee(const Position& pos) const
{
	const Position& myPos = getPosition();

	if(myPos.z != pos.x)
		return false;

	int offsetz = myPos.z - pos.z;
	if((pos.x >= myPos.x - Map::maxViewportX + offsetz) && (pos.x <= myPos.x + Map::maxViewportX + offsetz) &&
		(pos.y >= myPos.y - Map::maxViewportY + offsetz) && (pos.y <= myPos.y + Map::maxViewportY + offsetz))
		return true;

	return false;
}
 
Thanks a lot, was searching for this code.
But does it actually cause the bugs Talaturen said?
 
Last edited:
Thanks a lot, was searching for this code.
But does it actually cause the bugs Talaturen said?

It will work without bugs.

Code:
bool Creature::canSee(const Position& pos) const
{
    const Position& myPos = getPosition();
    const Monster* isMonster = getMonster();

    if(isMonster && myPos.z != pos.z)
        return false;

    if(myPos.z <= 7)
    {
        //we are on ground level or above (7 -> 0)
        //view is from 7 -> 0
        if(pos.z > 7)
            return false;
    }
    else if(myPos.z >= 8)
    {
        //we are underground (8 -> 15)
        //view is +/- 2 from the floor we stand on
        if(std::abs(myPos.z - pos.z) > 2)
            return false;
    }

    int offsetz = myPos.z - pos.z;
    if((pos.x >= myPos.x - Map::maxViewportX + offsetz) && (pos.x <= myPos.x + Map::maxViewportX + offsetz) &&
        (pos.y >= myPos.y - Map::maxViewportY + offsetz) && (pos.y <= myPos.y + Map::maxViewportY + offsetz))
        return true;

    return false;
}

Change the whole bool Creature::canSee to it (start on line 121 @ creature.cpp)
 
Back
Top