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

onThink(non-TFS based servers)

Ispiro

New Member
Joined
Oct 1, 2007
Messages
129
Reaction score
2
Since evolution-based server and clean SVN does not have onThink, I decided to create one. I tested it and it works perfectly fine ;)

Credits: Ispiro

Comments please

login.lua
Code:
local intervalTime = 2000 -- time between onThink() for player.

function onLogin(cid)
	onThinkPrepare(cid)
	return 1
end

-- do not edit what's below this line.

function onThinkPrepare(cid)
	if(isPlayer(cid) == FALSE) then
		return false
	end	
	onThinkCallback(cid)
	addEvent(onThinkPrepare, intervalTime, cid)
end

dofile("./data/creaturescripts/scripts/onthink.lua")

function onThinkCallback(cid)
	if(onThink(cid, intervalTime) == FALSE) then
		doRemoveCreature(cid)
	end
end

onthink.lua
Code:
function onThink(cid, interval)
	-- return FALSE will kick the player
	return TRUE
end

Fix: Fixed a bug where it wouldn't cancel player's addEvents if he logged out 2 seconds immediatly after he logged in
Fix2: Fixed a bug where it would take more than the interval time to trigger onThink.
update: changed onThink(cid) to onThink(cid, interval). So it's possible to know the interval time using a script.
update2: interval time is now configurable by changing the variable "intervalTime" to the time in miliseconds.
update3: returning "FALSE" in the onThink() function will now kick the player off the server.
update4: removed global variable, using local variable instead
fix3: removing playing by returning onThink didn't trigger his onLogout, so instead, used isPlayer check.
update5: removed eventsForOnThink variable, isPlayer check moved to function "onThinkPrepare(cid)" to avoid events for offline players.
 
Last edited:
You must've done something wrong. I tested this script and it was working fine.
Anyways, updated the script a bit, changes made is at the bottom of the post.
 
Back
Top