Forum

> > CS2D > Scripts > Lua wait command?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lua wait command?

8 replies
To the start Previous 1 Next To the start

old Lua wait command?

Alistaire
User Off Offline

Quote
So I've made a wait command in Lua; it should make the player stop spamming a button which triggers a part of the script BUT instead it.. well find that out for yourself.

1
2
3
4
5
6
7
8
9
function wait(seconds)
	local start = os.time()
	repeat until os.time() > start + seconds
end

addhook('spawn','spawnwait')
function spawnwait
	wait(10)
end

(This of course is not the true code).

----

So how can I make it so that the code only stops the button from reacting for some seconds? Or is that only possible in the map?

old Re: Lua wait command?

Alistaire
User Off Offline

Quote
user TimeQuesT has written
As I know os.time() returns a string. You have to format it into an int.


?

----

When I run this script, the whole game pauses for 10 seconds. Is there a way to make the button unclickable for 10 seconds in Lua? Else I'd add some trigger_delays etc..

old Re: Lua wait command?

TimeQuesT
User Off Offline

Quote
The reason is that cs2d don't executes lua in a thread( I think so).

edit:

Some pseudo code how to solve this problem:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
timeExpired = 0;

function CallEveryUse
{
if (TimeExpired>=10)
{

set TimeExpired to 0;
trigger button;

}

}

function CallEverySecond
{

if (timeExpired<10)
{

increase timeExpired by 1

}

}
edited 1×, last 22.01.12 04:58:03 pm

old Re: Lua wait command?

EngiN33R
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function wait(n,tn)
	parse("trigger "..tn)
	timer(n*1000,"parse","trigger "..tn)
end

function btnname(x,y)
	return entity(x,y,"name")
end

addhook("usebutton","test")
function test(id,x,y)
	if (x==1 and y==1) then
		wait(10,btnname(x,y))
	end
end

Not the best code, but it'll work I think. What you were doing didn't work, because repeat is a loop and it doesn't work over time - it just loops through instantaneously.

old Re: Lua wait command?

Alistaire
User Off Offline

Quote
I found out it's easier to just put 2 trigger_delays and then make the script trigger them for a delay.

old Re: Lua wait command?

Deleted User

Quote
Use TIMERS!?
timer(millisecs, "function", "arguments")

old Re: Lua wait command?

Apache uwu
User Off Offline

Quote
I find it difficult to use lua to prevent button spamming ([e] spamming is easy though) since usebutton, use, do not accept return values...

I'm assuming you're using the hook trigger:
     but using the map editor is much easier
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview