English Press Button E

2 replies
Goto Page
To the start Previous 1 Next To the start
11.12.18 06:51:48 pm
Up
Man Of Steel
User
Offline Off
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.
FRiendly boYy.
11.12.18 07:22:27 pm
Up
-3Jlou_nTu4-
User
Offline Off
Code:
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
11.12.18 07:26:35 pm
Up
Fraizeraust
Moderator
Offline Off
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:
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