Forum

> > CS2D > Maps/Editor > Pressing the button simultaneously
Forums overviewCS2D overview Maps/Editor overviewLog in to reply

English Pressing the button simultaneously

3 replies
To the start Previous 1 Next To the start

old Re: Pressing the button simultaneously

Vehk
User Off Offline

Quote
I think the only way to do it is with a script.

Put this script in the maps folder. Name it: <mapname>.lua

You'll need to change map.b1name, map.b2name, and map.trigger to the entity names of the buttons and what should be triggered.

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
39
40
41
42
43
44
45
46
map = {}

map.b1name = "button1"	-- entity name for button 1
map.b2name = "button2"	-- entity name for button 2
map.trigger = "entity"		-- entity name to trigger
-- because of latency and that players can't possibly press the buttons at the exact same time, a delay must be allowed between button presses
map.pressdelay = 300		-- milliseconds
map.pressdelay = map.pressdelay / 1000

map.pressedtime = 0	-- keep track of when buttons where pressed
map.firstpressed = false
map.pressid = 0

addhook("usebutton", "map.usebutton")
function map.usebutton(id, x, y)
	local e = entity(x, y, "name")
	local t = os.clock()

	-- return if it's neither of the buttons
	if e ~= map.b1name and e ~= map.b2name then
		return
	end

	-- is it the first button pressed?
	if not map.firstpressed then
		map.firstpressed = e
	end

	-- if the first one is pressed again, reset the timer and player id
	-- this is also done on the first button press
	if e == map.firstpressed then
		map.pressedtime = t
		map.pressid = id
		return
	end

	-- the second button was pressed. check if they where pressed quickly enough and by different players
	if (t - map.pressedtime) <= map.pressdelay and map.pressid ~= id then
		parse('trigger "' .. map.trigger ..'"')
	end

	-- reset everything
	map.pressedtime = 0
	map.firstpressed = false
	map.pressid = 0
end
edited 3×, last 06.03.18 12:03:54 am

old Re: Pressing the button simultaneously

VADemon
User Off Offline

Quote
You can do it with only entities but it's not easy (because Trigger_If)
IMG:https://i.imgur.com/dSYL3gs.png


You have 2 Images (Env_Sprite), 2 Buttons, 2 Delays, 2 Trigger_If, 1 Dynwall, 1 Trigger_Start

• cs2d entity trigger_start disables images (white)
• cs2d entity trigger_use enable images, trigger delay (how much time do you want between 2 button presses) and both trigger the first Trigger_If and disable themselves, so you can't break the system by pressing one button many times (light red)
• cs2d entity trigger_delay re-enable buttons and disable images (yellow)
• First cs2d entity trigger_if checks if Entity(A,B) (the first image) is enabled, then triggers the 2nd Trigger_If (green)
• Second trigger_if checks if 2nd image is enabled, if yes - triggers Dynwall, (disable buttons, images etc.)
To the start Previous 1 Next To the start
Log in to reply Maps/Editor overviewCS2D overviewForums overview