• 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+ Unable to pzLock players

Dries390

Well-Known Member
Joined
Sep 8, 2007
Messages
91
Solutions
4
Reaction score
70
Hello again everyone,

I've been trying to resolve an issue related to skulling players recently and I've run into another problem; I cannot pzLock players! Here's an example of a script I've been trying:

Lua:
local fight = createConditionObject(CONDITION_INFIGHT)
fight:setParameter(CONDITION_PARAM_TICKS, 60000)

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    print("test")
    player:addCondition(fight)
end

As far as I know, this should lock players out of PZ's and prevent them from logging out for 60 seconds but nothing happens. Other conditions such as drunkness work just fine. I'm using Nekiro's 8.60 downgraded 1.3 TFS.
 
The ability to PZ-lock players was apparantly removed and the code above is for logout blocks. I managed to solve this problem by reintroducing a function to PZ-lock players.

WARNING: untested past several basic tests, use at your own risk!

luascript.cpp, around line 2224
C++:
    registerMethod("Player", "getSkullTime", LuaScriptInterface::luaPlayerGetSkullTime);
    registerMethod("Player", "setSkullTime", LuaScriptInterface::luaPlayerSetSkullTime);
    registerMethod("Player", "setPzLockTime", LuaScriptInterface::luaPlayerSetPzLockTime); // NEW LINE
    registerMethod("Player", "getDeathPenalty", LuaScriptInterface::luaPlayerGetDeathPenalty);

luascript, around line 7655
C++:
int LuaScriptInterface::luaPlayerSetSkullTime(lua_State* L)
{
    // player:setSkullTime(skullTime)
    Player* player = getUserdata<Player>(L, 1);
    if (player) {
        player->setSkullTicks(getNumber<int64_t>(L, 2));
        pushBoolean(L, true);
    } else {
        lua_pushnil(L);
    }
    return 1;
}

int LuaScriptInterface::luaPlayerSetPzLockTime(lua_State* L) //NEW FUNCTION
{
    // player:setPzLockTime(locktime)
    Player* player = getUserdata<Player>(L, 1);
    if (player) {
        player->addInFightTicks(true, getNumber<int64_t>(L, 2));
        pushBoolean(L, true);
    }
    else {
        lua_pushnil(L);
    }
    return 1;
}
luascript.h, around line 830
C++:
        static int luaPlayerGetSkullTime(lua_State* L);
        static int luaPlayerSetSkullTime(lua_State* L);
        static int luaPlayerSetPzLockTime(lua_State* L); //NEW LINE
        static int luaPlayerGetDeathPenalty(lua_State* L);

player.h, around line 591
C++:
        void addInFightTicks(bool pzlock = false, uint64_t ticks = 0); // CHANGED addInFightTicks to allow a second, optional, parameter

player.cpp, around line 2037
C++:
void Player::addInFightTicks(bool pzlock /*= false*/, uint64_t ticks)
{
    if (hasFlag(PlayerFlag_NotGainInFight)) {
        return;
    }

    if (pzlock) {
        pzLocked = true;
    }

    if (ticks == 0) {     // NEW CONDITIONAL, REFERS TO GAME CONFIGURATION FOR STANDARD PZ LOCKOUT TIME
        ticks = g_config.getNumber(ConfigManager::PZ_LOCKED);
    }

    Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_INFIGHT, ticks, 0); // FUNCTION CAN NOW BE CALLED FOR X TICKS
    addCondition(condition);
    sendIcons();
}

This allows use of the metamethod player:setPzLockTime(timePZ) which will set a PZ lock for timePZ ticks.
 
Back
Top