Forum

> > CS2D > Scripts > When i press a key twice?
Forums overviewCS2D overview Scripts overviewLog in to reply

English When i press a key twice?

3 replies
To the start Previous 1 Next To the start

old When i press a key twice?

Louie
User Off Offline

Quote
How can i do this?
When a player presses a key twice(like u press the "E" button 2 times) then that player will become very fast and go through walls and at the same time shooting many grenades,how do i do that?

old Re: When i press a key twice?

Bowlinghead
User Off Offline

Quote
http://www.cs2d.com/help.php?hookcat=all&hook=usebutton#hook

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
-- Creates an array
function initArray()
	local array = {}
	for i = 1, 32 do -- count from 1 to 32 (For every player ID)
		array[i]=0 -- Every value is "0"
	end
	return array
end
check_button = initArray()
button = {x=50,y=50} -- Button x and y (in tiles)

addhook("usebutton","godmode")
function godmode(id,x,y)
	if x==button[x] and y==button[y] then -- If its the button
		check_button[id] = check_button[id]+1 -- set player array +1
	end
	if check_button[id] >= 2 then -- if he pressed it the second time
		check_button[id] = 0 -- set it to 0
		parse("speedmod "..id.." 200") -- make him fast
		-- Code for moving through walls and shooting many grenades
	end
end

-- Not tested

Edit:
Do you want to have more than one button?
Do you mean a button on the map or just the "E" key on the keyboard?
Does the player have to press the button 2 times in general or 2 times in a certain time distance?

old Re: When i press a key twice?

Louie
User Off Offline

Quote
Quote
Do you mean a button on the map or just the "E" key on the keyboard?

The "E" key in the keyboard
Quote
Does the player have to press the button 2 times in general or 2 times in a certain time distance?

Pressing the "E" key 2 times.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview