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
Print this error:
On sources i tried:
on luascript.cpp
line 2089
line 7390
and on on luascript.h
line 347
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
luascript.h - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
pastebin.com
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);