• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Simple tool for addEvent

Mock

Mock the bear (MTB)
Joined
Jul 29, 2008
Messages
619
Reaction score
106
Location
Brazil
If you are a script you know how to delay some actions using addEvent, but if you use something like:
Code:
addEvent(doCreatureSay,5000,cid,'hail',1)
you know if the player logout durig the interval you will got a error in console and you have to do it to avoid errors:
Code:
addEvent(function(cid,msg,typ)
   if isPlayer(cid) then
          doCreatureSay(cid,msg,typ)
   end
end,5000,cid,'hail',1)
But no more...

Add this function in your lib
Code:
function valid(f)
	return function(p,...)
		if isCreature(p) then
			return f(p,...)
		end
	end
end
and then use like this way to not get errors:
Code:
addEvent(valid(doCreatureSay),5000,cid,'hail',1)


PS: work only if the first param is the creature id
 
Pretty nice, I'd use this if I didn't already change all my scripts to do player checks :/
 
Thanks man, however i did this way:

Code:
function vae(f, cid)
	return (
		function(...)
			if isCreature(cid) then
				return f(...)
			end
		end
	)
end

So it does not depend that the used functions uses cid as first argument.

addEvent(vae(doCreatureSay, cid),5000,cid,'hail',1)
 
Back
Top