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

Help me fix the target switching in monster

sevengym

Member
Joined
Aug 27, 2014
Messages
76
Reaction score
7
Location
Poland
Hello I use TFS 1.5 by Nekiro, on my ots Trainers are made as monsters. I added a house trainer and I edited source code to allow interactions with it inside PZ. Everything works as excepted but not one thing. If i spawn the trainer in house it keeps switching targets if they are standing away from trainer it alternates between 2 targets. (if the hug the trainer its fine it keeps the target on 1 person)
walk.webp
but when I spawn this trainer for test not in PZ it properly sticks to one target from all ranges. Maybe something is wrong here? I would also like to make so that monster dont grant CONDITION_ONFIGHT to players.
C++:
bool Monster::isTarget(const Creature* creature) const
{
    // Check if the creature is removed, not attackable, or not visible
    if (creature->isRemoved() || !creature->isAttackable() || !canSeeCreature(creature)) {
        return false;
    }

    // Check if the creature is in a protection zone
    if (creature->getZone() == ZONE_PROTECTION) {
        // Allow the House Training Dummy to bypass this check
        if (getName() != "House Training Dummy") {
            return false; // Only disallow targeting in PZ for other monsters
        }
    }

    // Check if the creature is on the same z-coordinate (floor level)
    if (creature->getPosition().z != getPosition().z) {
        return false;
    }
 
    return true; // The creature can be targeted
}
Post automatically merged:

bump
 
Last edited:
Solution
The issue is if players stand 2 sqm away from Trainer. Trainer keeps switching target (if spawned in PZ). It allows players to use 1 Dummy to skill Defense/Shielding for 2 person. If I spawn the dummy outside house(pz) it properly sticks to 1 target as i wanted here
LUA:
<targetchange interval="1000" chance="0"/>
I literally tried to change all source code for PZ to make Dummy bypass PZ logic. Cause outside PZ it works as intended. But inside PZ it switches targets like crazy when i stand 2 sqm away. Nothing helps. And yea next thing is people from outside house get PZ when they see Trainer in house.
you would use something like this
C++:
       if (getName() == "House Training Dummy") {
        if (getZone() == ZONE_PROTECTION...
I’m not quite sure I understand the issue??? Can you clarify what's happening? Do you really need the training to stop attacking the player if they’re not in the area?
 
I’m not quite sure I understand the issue??? Can you clarify what's happening? Do you really need the training to stop attacking the player if they’re not in the area?
The issue is if players stand 2 sqm away from Trainer. Trainer keeps switching target (if spawned in PZ). It allows players to use 1 Dummy to skill Defense/Shielding for 2 person. If I spawn the dummy outside house(pz) it properly sticks to 1 target as i wanted here
LUA:
<targetchange interval="1000" chance="0"/>
I literally tried to change all source code for PZ to make Dummy bypass PZ logic. Cause outside PZ it works as intended. But inside PZ it switches targets like crazy when i stand 2 sqm away. Nothing helps. And yea next thing is people from outside house get PZ when they see Trainer in house.
Post automatically merged:
 
Last edited:
The issue is if players stand 2 sqm away from Trainer. Trainer keeps switching target (if spawned in PZ). It allows players to use 1 Dummy to skill Defense/Shielding for 2 person. If I spawn the dummy outside house(pz) it properly sticks to 1 target as i wanted here
LUA:
<targetchange interval="1000" chance="0"/>
I literally tried to change all source code for PZ to make Dummy bypass PZ logic. Cause outside PZ it works as intended. But inside PZ it switches targets like crazy when i stand 2 sqm away. Nothing helps. And yea next thing is people from outside house get PZ when they see Trainer in house.
you would use something like this
C++:
       if (getName() == "House Training Dummy") {
        if (getZone() == ZONE_PROTECTION && creature->getZone() != ZONE_PROTECTION) {
            return false;
        }
    }
you would use it in Monster::isTarget, Monster::doAttacking to check the target if it's in protection zone
and 2nd thing Adds a check at the beginning of the function to verify that the target remains in the same Protection Zone as the dummy if the target has moved outside by setting setAttackedCreature(nullptr);.
C++:
 if (getName() == "House Training Dummy") {
        if (getZone() == ZONE_PROTECTION && attackedCreature->getZone() != ZONE_PROTECTION) {
            setAttackedCreature(nullptr);
            return;
        }
    }
 
Solution
you would use something like this
C++:
       if (getName() == "House Training Dummy") {
        if (getZone() == ZONE_PROTECTION && creature->getZone() != ZONE_PROTECTION) {
            return false;
        }
    }
you would use it in Monster::isTarget, Monster::doAttacking to check the target if it's in protection zone
and 2nd thing Adds a check at the beginning of the function to verify that the target remains in the same Protection Zone as the dummy if the target has moved outside by setting setAttackedCreature(nullptr);.
C++:
 if (getName() == "House Training Dummy") {
        if (getZone() == ZONE_PROTECTION && attackedCreature->getZone() != ZONE_PROTECTION) {
            setAttackedCreature(nullptr);
            return;
        }
    }
Thanks! It worked.
 
Back
Top