• 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 onThink(cid, interval) Questions

Xagul

deathzot.net
Joined
Jun 30, 2008
Messages
1,294
Solutions
3
Reaction score
1,037
So I have been using onThink(cid, interval) for some time now and it just dawned on me that "interval" must have something to do with how often the script will "think" however I have been trying to figure out how to actually utilize this and I can't seem to get it to execute any faster or slower than 500ms. Does anyone have an idea on how to make it work every 1500ms rather than every 500ms?
 
I have tried a few things to change the interval, I know how ms works but the problem is by default we have this:

Code:
<event type="think" name="Idle" event="script" value="idle.lua"/>

This idle script will execute every 500ms.
And if I change it to this:

Code:
<event type="think" interval="1000" name="Idle" event="script" value="idle.lua"/>

It will still execute every 500ms. So I am wondering if I am doing it wrong, or if the function is just broken in my version of TFS?
 
Global event is done for that interval scripts, bast for creature script it wont execute any faster or slower than 500ms as it is attached to a function in the sources that executes ever 500 ms. About the intervals it is of no use except with monsters it do something with using spells or something.
 
function onThink(cid, interval) -- execute every 2 sec

maybe a bit later but here it is :]

Code:
function onThink(cid, interval)
	if last_interval == nil then last_interval= os.clock() 	end

  	if (os.clock() - last_interval) > 2 then		--		execute every 2 sec
		--		your code HERE
		
		last_interval= os.clock()
		return true
	end
		
		return false
end
 
Back
Top