Forum

> > CS2D > Scripts > Add delay to a use
Forums overviewCS2D overview Scripts overviewLog in to reply

English Add delay to a use

3 replies
To the start Previous 1 Next To the start

old Add delay to a use

The Smoker
User Off Offline

Quote
I am trying to create a feature to my script, but I can not, so I ask your help. I have a tile position on my map, I want that when a player press "E" he gets a gun. Okay, I did it. But now I want to have a break of 120 seconds for any other player to win this weapon. How can I do this?

See the code:
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
26
27
28
29
30
31
32
33
34
35
36
37
38
chests = {
	["1"] = {
		xPos = 6,
		yPos = 4,
		items = {10,30},
		chance = 40,
		delay = 30
	},
	["2"] = {
		xPos = 18,
		yPos = 12,
		items = {45,69},
		chance = 20,
		delay = 60	}
}

addhook("use","t_use")



function t_use(id)

	local r = math.random(0,100)

	for k,v in pairs(chests) do
		if player(id,"tilex")==chests[k].xPos and player(id,"tiley")==(chests[k].yPos+1) then

				if r <= chests[k].chance then
					local it = math.random(1,#chests[k].items)
					msg2(id,"You gained a weapon "..chests[k].items[it])
					parse("equip "..id.." "..chests[k].items[it])
				else
					msg2(id,"Empty")
				end

		end
	end
end

old Re: Add delay to a use

Mami Tomoe
User Off Offline

Quote
@user The Smoker:
More >


Try this.
I'm still new at scripting and I bet I made like 100 mistakes but here you go.
(not tested)

old Re: Add delay to a use

Yates
Reviewer Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
wait = 0

function _second()
	wait = wait - 1
	if wait < 0 then
		wait = 0
	end
end
addhook("second", _second)

-- Add this at the top of your use function
if wait > 0 then
	return 1
end

Set wait to whatever number you want after someone successfully gets a gun.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview