• 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 0.X Remove Battle when in a PZ

potinho

Intermediate OT User
Joined
Oct 11, 2009
Messages
1,397
Solutions
17
Reaction score
148
Location
Brazil
Hello everyone, everything good?

I saw a common question but I couldn't find a way to remove it in the sources, without having to do some LUA script. I managed to get the battle to be removed when the player enters a Protection Zone, but if he leaves soon after, the battle blocks the char again. Is there any way to take out the battle when the player steps on a PZ?

Here's follow:

Im fighting
1666742612039.png

Goes to a PZ (battle gone and i can log out)
1666742647133.png

And after this, when i go out, battle lock returns:

1666742688807.png

Follow my function who removes battle in PZ:

C++:
bool ProtocolGame::logout(bool displayEffect, bool forceLogout)
{
    //dispatcher thread
    if(!player)
        return false;

    if(player->hasCondition(CONDITION_EXHAUST, 1))
    {
        player->sendTextMessage(MSG_STATUS_SMALL, "You have to wait a while.");
        return false;
    }

    if(!player->isRemoved())
    {
        if(!forceLogout)
        {
            if(!IOLoginData::getInstance()->hasCustomFlag(player->getAccount(), PlayerCustomFlag_CanLogoutAnytime))
            {
                if(player->getTile()->hasFlag(TILESTATE_NOLOGOUT))
                {
                    if(Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_EXHAUST, 500, 0, false, 1))
                        player->addCondition(condition);

                    player->sendCancelMessage(RET_YOUCANNOTLOGOUTHERE);
                    return false;
                }

                if(player->getZone() != ZONE_PROTECTION && player->hasCondition(CONDITION_INFIGHT))
                {
                    if(Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_EXHAUST, 500, 0, false, 1))
                        player->addCondition(condition);

                    player->sendCancelMessage(RET_YOUMAYNOTLOGOUTDURINGAFIGHT);
                    return false;
                }

                if(!g_creatureEvents->playerLogout(player, false)) //let the script handle the error message
                    return false;
            }
            else
                g_creatureEvents->playerLogout(player, true);
        }
        else if(!g_creatureEvents->playerLogout(player, true))
            return false;

        if(displayEffect && !player->isGhost())
            g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
    }

    player->client->clear(true);
    disconnect();
    if(player->isRemoved())
        return true;

    return g_game.removeCreature(player);
}
 
Solution
@potinho
Even in oldest engines there was event onChangeZone (in C++, not Lua event) ex. in 0.4:
Above:
Code:
    sendIcons();
add:
Code:
if(zone == ZONE_PROTECTION)
{
    if(Condition* condition = getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT))
    {
        removeCondition(condition);
    }
}
Every time player walks into PZ, it will remove in-fight condition.
It's pretty good feature, ex. if you teleport by GM player with PZ lock (killed other player) into PZ, it will be removed and he will be able to walk.
I believe this is normal (default). but if I'm not mistaken if you relog the pz disappear.
No, if i relog in a shortly, battle comes back. I want to remove this but when a player enter in a PZ and try to use a item who its not possible to use in a battle, it fails
 
I managed to get the battle to be removed when the player enters a Protection Zone
You said that you got script, that removes battle, when players walks into PZ (like on new Tibia version).
but if he leaves soon after, the battle blocks the char again.
Ok. He leaves, monsters attack him, he get logout blocked again. Is

Are you sure, that you remove his battle lock (in-fight condition), not hide 'X icon' send to client in your script?
You posted logout code. Totally not related to removing in-fight condition.
 
You said that you got script, that removes battle, when players walks into PZ (like on new Tibia version).

Ok. He leaves, monsters attack him, he get logout blocked again. Is

Are you sure, that you remove his battle lock (in-fight condition), not hide 'X icon' send to client in your script?
You posted logout code. Totally not related to removing in-fight condition.
When i attack monster and goes to PZ, i can logout. But, even loggin out, after a short time, if i leave PZ, battle symbol comes back and i cant logout (even with no monster on screen).

Where can i find this fighting condition to change @Gesior.pl ?

I changed:

C++:
if(player->hasCondition(CONDITION_INFIGHT))
for
C++:
if(player->getZone() != ZONE_PROTECTION && player->hasCondition(CONDITION_INFIGHT)
 
Last edited:
@potinho
Even in oldest engines there was event onChangeZone (in C++, not Lua event) ex. in 0.4:
Above:
Code:
    sendIcons();
add:
Code:
if(zone == ZONE_PROTECTION)
{
    if(Condition* condition = getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT))
    {
        removeCondition(condition);
    }
}
Every time player walks into PZ, it will remove in-fight condition.
It's pretty good feature, ex. if you teleport by GM player with PZ lock (killed other player) into PZ, it will be removed and he will be able to walk.
 
Solution
@potinho
Even in oldest engines there was event onChangeZone (in C++, not Lua event) ex. in 0.4:
Above:
Code:
    sendIcons();
add:
Code:
if(zone == ZONE_PROTECTION)
{
    if(Condition* condition = getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT))
    {
        removeCondition(condition);
    }
}
Every time player walks into PZ, it will remove in-fight condition.
It's pretty good feature, ex. if you teleport by GM player with PZ lock (killed other player) into PZ, it will be removed and he will be able to walk.
Yeah, its exactly i looking for. Will test and compile
Post automatically merged:

Thanks once again @Gesior.pl , works!
 
Last edited:
@potinho
Even in oldest engines there was event onChangeZone (in C++, not Lua event) ex. in 0.4:
Above:
Code:
    sendIcons();
add:
Code:
if(zone == ZONE_PROTECTION)
{
    if(Condition* condition = getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT))
    {
        removeCondition(condition);
    }
}
Every time player walks into PZ, it will remove in-fight condition.
It's pretty good feature, ex. if you teleport by GM player with PZ lock (killed other player) into PZ, it will be removed and he will be able to walk.
Gesior, there's a way to remove all conditions? I realize when player go to PZ he still got burning or poisoned, and it prevent him to use things who need nothing of pz lock.
 
There are several functions overloading removeCondition

One of them is this, which remove conditions by type

So simply do:
C++:
removeCondition(CONDITION_POISON);
 
There are several functions overloading removeCondition

One of them is this, which remove conditions by type

So simply do:
C++:
removeCondition(CONDITION_POISON);
So basically i need to change:

C++:
if(zone == ZONE_PROTECTION)
{
    if(Condition* condition = getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT))
    {
        removeCondition(condition);
    }
}

to

C++:
if(zone == ZONE_PROTECTION)
{
    if(Condition* condition = getCondition(CONDITION_BLEEDING, CONDITION_PARALYZE, CONDITION_DRUNK, CONDITION_DROWN, CONDITION_CURSED, CONDITION_DAZZLED, CONDITION_FREEZING, CONDITION_ENERGY, CONDITION_POISON, CONDITION_FIRE, CONDITION_INFIGHT, CONDITIONID_DEFAULT))
    {
        removeCondition(condition);
    }
}

?

Cause the way above dont work.
 
Last edited:
Back
Top