Forum

> > CS2D > Scripts > Press Button E
Forums overviewCS2D overview Scripts overviewLog in to reply

English Press Button E

2 replies
To the start Previous 1 Next To the start

old Press Button E

Man Of Steel
User Off Offline

Quote
Hello guys
I want some changing in the following lua,
I want to make Shop in my map and add the shop in specific place, when player press Button "E" at the tile (Example: 23|1 ) Instead saying !shop like in this lua code so Shop will be opened.

Spoiler >


Please help.

old Re: Press Button E

-3Jlou_nTu4-
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
local SHOP_POS_TX = 0	--position center of shop in TILE
local SHOP_POS_TY = 0
local SHOP_POS_RAD = 3 --radius of shop

addhook("use", "use_proc")

function use_proc(plid, event, data, tilex, tiley)
	if event==0 then
		if math.abs(tilex - SHOP_POS_TX)<=SHOP_POS_RAD and math.abs(tiley - SHOP_POS_TY)<=SHOP_POS_RAD then
			--Here open shop menu
		end
	end
end

old Re: Press Button E

GeoB99
Moderator Off Offline

Quote
You can use the cs2d lua hook usebutton hook to trigger a specific event such as showing a menu when the player presses the E key on a button of the map. Here is an example of code:
1
2
3
4
5
6
7
8
9
10
function MenuShopOnUse(id, x, y)
   local PosX = 0 -- The position in X coordination
   local PosY = 0 -- The position in Y coordination

   if (x == PosX and y == PosY) then
      -- Code here
   end
end

addhook('usebutton', 'MenuShopOnUse')
You've to fill
PosX
and
PosY
variables with the actual position of the button on the map. Keep in mind however that you need to set trigger_use entity on that position in order to make it work (as explained by the documentation).
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview