• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved !pz command - please help! :)

tivep91

New Member
Joined
Jul 1, 2012
Messages
39
Reaction score
2
Hello all!

Is there a script that checks if player is PZ?

! pz

12:33 You have to wait another 43 seconds.
 
Need Source edits.. i have finished the edits
here you are
in luascript.cpp
Code:
int32_t LuaInterface::luaGetInFightTicks(lua_State* L)
{
    ScriptEnviroment* env = getEnv();
    Creature* creature = env->getCreatureByUID(popNumber(L));
    Condition* condition = creature->getCondition(CONDITION_INFIGHT, (ConditionId_t)CONDITION_INFIGHT);

    if(creature)
    {
        condition->getEndTime();
        lua_pushnumber(L, true);

    }else{

        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushnumber(L, false);

    }

    return 1;
}

Code:
Code:
function onSay(cid, words, param, channel)
if not hasCondition(cid, CONDITION_INFIGHT) then
return doPlayerSendCancel(cid, "You Don't Have Pz") and doSendMagicEffect(getThingPos(cid), 2)
end

    doPlayerSendTextMessage(cid,27, "You Have To Wait "..getInFightTicks(cid).." Second For Pz.")
    return true
end

don't ask where to put or how.
 
Last edited:
When i compiling:

CMakeFiles/tfs.dir/src/luascript.cpp.o: In function `LuaScriptInterface::luaGetInFightTicks(lua_State*)':
luascript.cpp:(.text+0x1ba86): undefined reference to `ScriptEnvironment::getCreatureByUID(unsigned int)'
collect2: error: ld returned 1 exit status
make[2]: *** [tfs] Error 1
make[1]: *** [CMakeFiles/tfs.dir/all] Error 2
make: *** [all] Error 2


@edit

I must edit your source code to this:

PHP:
int32_t LuaScriptInterface::luaGetInFightTicks(lua_State* L)
{
    ScriptEnvironment* env = getScriptEnv();
    Creature* creature = env->getCreatureByUID(popNumber(L));
    Condition* condition = creature->getCondition(CONDITION_INFIGHT, (ConditionId_t)CONDITION_INFIGHT);

    if(creature)
    {
        condition->getEndTime();
        pushBoolean(L, true);

    }else{

        reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
        pushBoolean(L, false);

    }

    return 1;
}
 
Try This One
Code:
int32_t LuaScriptInterface::luaGetInFightTicks(lua_State* L)
{
    Creature* creature = g_game.getCreatureByID(cid);
    Condition* condition = creature->getCondition(CONDITION_INFIGHT, (ConditionId_t)CONDITION_INFIGHT);

    if(creature)
    {
        condition->getEndTime();
        pushNumber(L, true);

    }else{

        reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
        pushNumber(L, false);

    }

    return 1;
}
 
/home/ots/tfs/src/luascript.cpp: In static member function 'static int32_t LuaScriptInterface::luaGetInFightTicks(lua_State*)':
/home/ots/tfs/src/luascript.cpp:3034:49: error: 'cid' was not declared in this scope
 
Code:
int32_t LuaScriptInterface::luaGetInFightTicks(lua_State* L)
{
        uint32_t cid = popNumber(L);
    Creature* creature = g_game.getCreatureByID(cid);
    Condition* condition = creature->getCondition(CONDITION_INFIGHT, (ConditionId_t)CONDITION_INFIGHT);

    if(creature)
    {
        condition->getEndTime();
        pushNumber(L, true);

    }else{

        reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
        pushNumber(L, false);

    }

    return 1;
}
 
Segmentation fault - server is crashing.

I must edit code to this:
PHP:
function onSay(cid, words, param, channel)
if not getCreatureCondition(cid, CONDITION_INFIGHT) then -- before is hasCondition.
return doPlayerSendCancel(cid, "You Don't Have Pz") and doSendMagicEffect(getThingPos(cid), 2)
end

    doPlayerSendTextMessage(cid,27, "You Have To Wait "..getInFightTicks(cid).." Second For Pz.")
    return true
end

(hasCondition a nil value etc...)

i am waiting for help.

- - - Edited - - -

Solution: https://github.com/otland/forgottenserver/issues/197
 
Last edited by a moderator:
I know that you have solved this already but others may look for this as well.

Doesn't require any source edit (for TFS 1.0 users)
Code:
" .. (math.floor(Player(cid):getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT):getEndTime() / 1000) - os.time()) .. "

- - - Edited - - -

Added link to the source code fix in his last post
 
@Ninja in TFS 1.5 downgraded by nekiro i can use this?

LUA:
" .. (math.floor(Player(cid):getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT):getEndTime() / 1000) - os.time()) .. "

i tried but didint work
 
LUA:
    local pzTime = player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT)
    if pzTime then
        msg = msg ..
        "\n    Fight Timer: " ..
        player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT):getTicks() / 1000 .. " seconds"
    else
        msg = msg .. "\n    Fight Timer: " .. 0
    end
 
LUA:
/home/kompilacja/otserv/src/luascript.cpp:16870:9: error: no declaration matches ‘int32_t LuaScriptInterface::luaGetInFightTicks(lua_State*)’
16870 | int32_t LuaScriptInterface::luaGetInFightTicks(lua_State* L)
      |         ^~~~~~~~~~~~~~~~~~
/home/kompilacja/otserv/src/luascript.cpp:16870:9: note: no functions named ‘int32_t LuaScriptInterface::luaGetInFightTicks(lua_State*)’
In file included from /home/kompilacja/otserv/src/luascript.cpp:25:
/home/kompilacja/otserv/src/luascript.h:203:7: note: ‘class LuaScriptInterface’ defined here
  203 | class LuaScriptInterface
      |       ^~~~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/tfs.dir/build.make:621: CMakeFiles/tfs.dir/src/luascript.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:102: CMakeFiles/tfs.dir/all] Error 2
make: *** [Makefile:91: all] Error 2






Must ADD:
LUA:
static int32_t luaGetInFightTicks(lua_State* L);
to luascript.h

and

talkactions

Code:
function onSay(player, words, param)
    local condition = player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) or
                      player:getCondition(CONDITION_INFIGHT, 1) or
                      player:getCondition(CONDITION_PZBLOCK)

    if not condition then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Nie masz pz.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local remaining = math.ceil(condition:getTicks() / 1000)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "PZ zniknie za " .. remaining .. " sekund.")
    return false
end
 
Last edited:
Back
Top