• 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 ping functions

warriorfrog

Active Member
Joined
Jul 29, 2015
Messages
334
Reaction score
35
I tried to add ping functions in my 8.6 server (0.4) it would be so useful to so many functions
But i couldn't put it to work, is anyone with more experience could help me?

When i try to test:
!ping
Code:
function onSay(cid, words, param, channel)
    local sendping = doPlayerSendPing(cid)
    print(sendping)
    local ping = getPlayerLastPing(cid)
    print(ping)
    local pong = getPlayerLastPong(cid)
    print(pong)
    local otsys = getOtsysTime(cid)
    print(otsys)
end

Print this error:
Code:
[3:57:59.939] [Error - TalkAction Interface] 
[3:57:59.939] data/talkactions/scripts/ping.lua:onSay
[3:57:59.939] Description: 
[3:57:59.939] data/talkactions/scripts/ping.lua:2: attempt to call global 'doPlayerSendPing' (a nil value)
[3:57:59.939] stack traceback:
[3:57:59.939]     data/talkactions/scripts/ping.lua:2: in function <data/talkactions/scripts/ping.lua:1>

On sources i tried:

on luascript.cpp
line 2089
Code:
    // ping 1
    //doPlayerSendPing(cid)
    lua_register(m_luaState, "doPlayerSendPing", LuaInterface::luaDoPlayerSendPing);
    //getPlayerLastPing(cid)
    lua_register(m_luaState, "getPlayerLastPing", LuaInterface::luaGetPlayerLastPing);
    //getPlayerLastPong(cid)
    lua_register(m_luaState, "getPlayerLastPong", LuaInterface::luaGetPlayerLastPong);
    //getOtsysTime(cid)
    lua_register(m_luaState, "getOtsysTime", LuaInterface::luaGetOtsysTime);
    // /ping 1

line 7390
Code:
// ping 2
// Adaptado by Yan Liima(Night for tibiaking.com)
int32_t LuaInterface::luaDoPlayerSendPing(lua_State* L)
{
    //doPlayerSendPing(cid)
    ScriptEnviroment* env = getEnv();
    Player* player = env->getPlayerByUID(popNumber(L));
    if(!player)
    {
        lua_pushboolean(L, false);
        return 1;
    }
    int64_t timeNow = OTSYS_TIME();
    player->lastPing = timeNow;
    if(player->client)
    {
            void sendPing();
            lua_pushboolean(L, true);
    }else{
          lua_pushboolean(L, false);        
          }
    lua_pushboolean(L, true);
 
    return 1;
}
int32_t LuaInterface::luaGetOtsysTime(lua_State* L)
{
    //getOtsysTime()
    lua_pushnumber(L, OTSYS_TIME());
    return 1;
}
int32_t LuaInterface::luaGetPlayerLastPing(lua_State* L)
{
    //getPlayerLastPing(cid)
    ScriptEnviroment* env = getEnv();
    Player* player = env->getPlayerByUID(popNumber(L));
    if(!player)
    {
        errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
         lua_pushboolean(L, false);
        return 1;
    }
    int64_t timeNow = OTSYS_TIME();
    lua_pushnumber(L, player->lastPing);
    return 1;
}
int32_t LuaInterface::luaGetPlayerLastPong(lua_State* L)
{
    //getPlayerLastPong(cid)
    ScriptEnviroment* env = getEnv();
    Player* player = env->getPlayerByUID(popNumber(L));
    if(!player)
    {
        errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
         lua_pushboolean(L, false);
        return 1;
    }
    lua_pushnumber(L, player->lastPong);
    return 1;
}
// /ping



and on on luascript.h
line 347
Code:
        // Ping
        static int32_t luaDoPlayerSendPing(lua_State* L);
        static int32_t luaGetPlayerLastPing(lua_State* L);
        static int32_t luaGetPlayerLastPong(lua_State* L);
        static int32_t luaGetOtsysTime(lua_State* L);
 
u dont added in source or lua correct way, the error show that u dont have this function "doPlayerSendPing"

Pls tell me, what i did wrong?
I don't know C++, just try to do by grab some codes...

Thats the original script (to 0.3.6)

I need to use functions like this: GlobalEvent - Auto kick lagged players + DDoS protection (https://otland.net/threads/auto-kick-lagged-players-ddos-protection.121492/#post-1187916)
I also alrealdy added this lib: [Lua & C++] Ping lib -- ping.getPing(cid,storage) (https://otland.net/threads/lua-c-ping-lib-ping-getping-cid-storage.121183/)
 
I know it may sound obvious, but have you recompiled everything? the error is saying that the function doPlayerSendPing doesn't exists, so it seems that the compilation didn't succeed
 
Back
Top