I did this function by things that already exist on open tibia.
for tfs 03.6
If you dont know the tibia client already got a ping system so i am using it.
And getOtsystime is like os.time() + os.clock(), you got year, month, day, hour, minut, second, miliseconds
All functions by me ^^
Just open luascripts.cpp and add it:
Near:
Add:
Almost in the end add:
In luascript.h near some another thing like this add it:
In 050-functions.lua add:
So you can get the player ping in ms
And if you want a safe ping result you can add this lib:
http://otland.net/f163/lua-c-ping-lib-ping-getping-cid-storage-121183
for tfs 03.6
If you dont know the tibia client already got a ping system so i am using it.
And getOtsystime is like os.time() + os.clock(), you got year, month, day, hour, minut, second, miliseconds
All functions by me ^^
Just open luascripts.cpp and add it:
Near:
Code:
//doSetMonsterOutfit(cid, name, time)
lua_register(m_luaState, "doSetMonsterOutfit", LuaScriptInterface::luaSetMonsterOutfit);
Code:
//doPlayerSendPing(cid)
lua_register(m_luaState, "doPlayerSendPing", LuaScriptInterface::luadoPlayerSendPing);
//getPlayerLastPing(cid)
lua_register(m_luaState, "getPlayerLastPing", LuaScriptInterface::luagetPlayerLastPing);
//getPlayerLastPong(cid)
lua_register(m_luaState, "getPlayerLastPong", LuaScriptInterface::luagetPlayerLastPong);
//getOtsysTime(cid)
lua_register(m_luaState, "getOtsysTime", LuaScriptInterface::luagetOtsysTime);
Code:
int32_t LuaScriptInterface::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)
{
player->client->sendPing();
lua_pushboolean(L, true);
}else{
lua_pushboolean(L, false);
}
lua_pushboolean(L, true);
return 1;
}
int32_t LuaScriptInterface::luagetOtsysTime(lua_State* L)
{
//getOtsysTime()
lua_pushnumber(L, OTSYS_TIME());
return 1;
}
int32_t LuaScriptInterface::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 LuaScriptInterface::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;
}
In luascript.h near some another thing like this add it:
Code:
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);
In 050-functions.lua add:
Lua:
function getPlayerPing(cid) -- getPlayerPing By mock
local c = getPlayerLastPong(cid)
local l = getPlayerLastPing(cid)
if not c or not l then
return 'Disconected'
end
local ping = math.floor((c-l)/10)
if ping < 0 then
if ping*-1 > 2000 then
return 'Disconected'
end
return 'Wating response'
end
return ping
end
So you can get the player ping in ms
And if you want a safe ping result you can add this lib:
http://otland.net/f163/lua-c-ping-lib-ping-getping-cid-storage-121183
Last edited: