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

Solved How to delay a loop

Drakens

New Member
Joined
Jul 10, 2008
Messages
19
Reaction score
0
Hi

I need to delay a loop for this script:

Code:
function onSay(cid, words, param)
   if words == "open" then
      pos = getPlayerPosition(cid)
      repeat
         doSendMagicEffect(pos,5) 
         sleep(1000)
      until
         words == "stop"
      end
   end
end
What should I place instead of sleep??

Thx for help
Drakens
 
Well, you can't actually delay it, making it spend longer time to finish, that would just make the server freeze until the script is done.

What you need to do is to is to use the function addEvent to run a second function (Assuming you're using TFS or an other server with this function). You should search for the word addEvent and try to see how it's used since I'm not going to explain it here for you ;)

addEvent(nameOfFunction, delayInMilliSeconds, parameters)
 
Impossible to do it like this ;o, but im not sure

Code:
local storageValue = 3005

function repeatEffect(cid, effect, delay)
	if getPlayerStorageValue(cid, storageValue) == TRUE then
		doSendMagicEffect(getPlayerPosition(cid), effect)
		addEvent(repeatEffect, delay, cid, effect, delay)
	end
end

function onSay(cid, words, param)
	if words == "open" then
		setPlayerStorageValue(cid, storageValue, TRUE)
		repeatEffect(cid, 5, 1000)
	elseif words == "stop" then
		setPlayerStorageValue(cid, storageValue, FALSE)
	end
end
 
I moded you script Slawkens cuz addEvent wont work. Now i have this.

local storageValue = 3005

function repeatEffect(cid, effect, delay)
x = {cid = cid, effect = effect, delay = delay}
if getPlayerStorageValue(cid, storageValue) == TRUE then
doSendMagicEffect(getPlayerPosition(cid), effect)
addEvent(repeatEffect, delay, x)
end
end

function onSay(cid, words, param)
if words == "open" then
setPlayerStorageValue(cid, storageValue, TRUE)
repeatEffect(cid, 5, 1000)
elseif words == "stop" then
setPlayerStorageValue(cid, storageValue, FALSE)
end
end

And i don't know why getPlayerStorageValue can't find Player.
I always get Error:
luaGetPlayerStorageValue(). Player not found.

Any sugestions??
 
On TAGS no, but on trunk it will.

Try this then:
Code:
local storageValue = 3005

function repeatEffect(cid, effect, delay)
	parameters = {_cid = cid, _effect = effect, _delay = delay}
	if getPlayerStorageValue(parameters._cid, storageValue) == TRUE then
		doSendMagicEffect(getPlayerPosition(parameters._cid), parameters._effect)
		addEvent(repeatEffect, parameters._delay, parameters)
	end
end

function onSay(cid, words, param)
	if words == "open" then
		setPlayerStorageValue(cid, storageValue, TRUE)
		repeatEffect(cid, 5, 1000)
	elseif words == "stop" then
		setPlayerStorageValue(cid, storageValue, FALSE)
	end
end
 
Hyhy, try now :p
Code:
local storageValue = 3005

function repeatEffect(parameters)
	if getPlayerStorageValue(parameters.cid, storageValue) == TRUE then
		doSendMagicEffect(getPlayerPosition(parameters.cid), parameters.effect)
		addEvent(repeatEffect, parameters.delay, parameters)
	end
end

function onSay(cid, words, param)
	if words == "open" then
		setPlayerStorageValue(cid, storageValue, TRUE)
		repeatEffect({cid = cid, effect = 5, delay = 1000})
	elseif words == "stop" then
		setPlayerStorageValue(cid, storageValue, FALSE)
	end
end
 

Similar threads

Back
Top Bottom