Forum

> > CS2D > Scripts > Press Button E
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Press Button E

2 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Press Button E

Man Of Steel
User Off Offline

Zitieren
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.

alt Re: Press Button E

-3Jlou_nTu4-
User Off Offline

Zitieren
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

alt Re: Press Button E

GeoB99
Moderator Off Offline

Zitieren
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).
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht