• 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!

[Lua & C++] Ping lib -- ping.getPing(cid,storage)

Mock

Mock the bear (MTB)
Joined
Jul 29, 2008
Messages
619
Reaction score
106
Location
Brazil
First you need do it:
Lua Function getOtsysTime() + getPlayerPing(cid) + doPlayerSendPing(cid)

and next add this lib on data/lib:

123-pinglib.lua

Lua:
---Pinglib by mock the bear
ping = {
	_VERSION = "1.0";
	_AUTHOR = "Mock the bear";
	test = function()
		if not getPlayerLastPong then
			print('Error! Cannot run this lib without source changes.')
			return false
		else 
			return true
		end
	end,
	CONST_WATING_RESPONSE = -3,
	CONST_DISCONECTED = -2,
}

function ping.CheckPing(cid) -- getPlayerPing By mock
	local c = getPlayerLastPong(cid)
	local l = getPlayerLastPing(cid)
	if not c or not l then
		return -2
	end
	local ping = math.floor((c-l)/10)
	if ping < 0 then
		if ping*-1 > 2000 then
			return -2
		end
		return -3
	end
	return ping
end

function ping.loop(cid,storage,f,...) -- check
	if not isPlayer(cid) then
		return false
	end
	local p_ing = ping.CheckPing(cid)
	if p_ing ~= CONST_WATING_RESPONSE then
		if not tonumber(p_ing) then
			doPlayerSetStorageValue(cid,storage,ping.CONST_DISCONECTED)
			return
		else 
			doPlayerSetStorageValue(cid,storage,p_ing)
                        f(cid,storage,p_ing,...)
			return
		end
	end
	addEvent(ping.loop,100,cid,storage,f,...)
end

function ping.getPing(cid,storage,f,...) --- This function will send a ping request and wait the response, so then will add an value on a storage.
	if ping.test() then
		doPlayerSetStorageValue(cid,storage,ping.CONST_WATING_RESPONSE)
		doPlayerSendPing(cid)
		ping.loop(cid,storage,f,...)
	end
end

ping.getPing - Reference.

This function got 3 params.
cid -- Creature id INT
storage -- Storage id INT
f -- function to execute when got a response FUNCTION
the f function got 3 params
cid -- Creature id
storage -- Storage id INT
ping -- Ping in MS INT

Example:
http://otland.net/f81/command-ping-check-if-player-got-lag-121185/
 
Last edited:
nice, esse sim é bom , fiz um bom aproveito dele fiz tipo de um cs system anti-ping alto que kicka so que misturei com idle system do tibia e colokei uma configuração perfeita fico 10.
 
Last edited:
how do you set the storage in this script? I tried to change storage id to a number but i either get an error saying "..." exptected near (storageid#) or

17:06 Your ping is -3 ms.
17:06 Sending an request...
 
thanks but that golden shovel still doesn't answer my question... lol :D
 
how do you set the storage in this script? I tried to change storage id to a number but i either get an error saying "..." exptected near (storageid#) or

17:06 Your ping is -3 ms.
17:06 Sending an request...
This is because THERE IS NO STORAGE in this lib.


http://otland.net/threads/getotsystime-getplayerping-cid-doplayersendping-cid.121182/
 
function ping.getPing(cid,storage,f,...) --- This function will send a ping request and wait the response, so then will add an value on a storage.

doPlayerSetStorageValue(cid,storage,ping.CONST_WATING_RESPONSE)

?
 
Last edited:
Back
Top