Forum

> > CS2D > Scripts > Open a menu when you say hello on a specific spot
Forums overviewCS2D overview Scripts overviewLog in to reply

English Open a menu when you say hello on a specific spot

18 replies
To the start Previous 1 Next To the start

old Re: Open a menu when you say hello on a specific spot

Scott
BANNED Off Offline

Quote
It can be something like that ? this is something simple.

1
2
3
4
5
6
7
8
9
addhook("say","_say")
function _say(p,txt)
	-- Hello
	if (txt=="hello") then menu(p,"Hello,add menu"); return 1 end

	-- Nice
	if (txt=="nice") then menu(p,"Nice,add menu"); return 1 end
	
end

old Re: Open a menu when you say hello on a specific spot

Bowlinghead
User Off Offline

Quote
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
47
48
49
50
51
52
-- NEW code: tested & working

-- which positions will open a menu when saying !hello ?
pos = {
     [1] = {5,9},   -- stay on Tile 5|9
     [2] = {12,12}, -- stay on Tile 12|12
     ---... as much you like
}


addhook("say","mySay")
function mySay(id,txt)
     if (txt == "!hello") then
          local px = player(id,"tilex")
          local py = player(id,"tiley")
          for iposi, posi in pairs(pos) do
               if (px == posi[1]) then
                    if (py == posi[2]) then
		
                         --menu(id,tostring(iposi)..". Menu, Energy Drink, Smartphone, E-Cigs.") -- this is the same menu for all positions (probably not what you want)
                         if (iposi == 1) then -- look if player is standing @Market position
                              menu(id,"NEW MARKET, Fresh Fish|ezpz, Apples|lmsqz, Bread | without butter") -- change as you like
                         elseif (iposi == 2) then -- modify as you like: The "" String has to match with the names you gave in pos = {} array
                              menu(id,"AMMONATION, Swords, Rifles, Gunblades, Ammo")
                         end
                    end
               end
          end
     end
end


addhook("menu", "myMenu")
function myMenu(id,txt,b) -- id, txt, button
     if (txt == "NEW MARKET") then
          if (b == 1) then
               -- if button 1 pressed
          elseif (b== 2) then
               -- if button 2 pressed
          elseif (b== 3) then
               -- ...
          end
     elseif (txt =="AMMONATION") then
          if (b == 1) then
               -- if button 1 pressed
          elseif (b== 2) then
               -- if button 2 pressed
          elseif (b== 3) then
               -- ...
          end
     end
end

Its just an example, you have to edit it to your likes.
If you find bugs, post your console log in here (especially the lua error).

EDIT: Fixed code syntax mistakes. Still shitty code because its written in the textfield of the website (NO TABS
edited 4×, last 27.01.17 03:46:17 pm

old Re: Open a menu when you say hello on a specific spot

Bowlinghead
User Off Offline

Quote
@user Rainoth:
The comma is valid on line 6.
But line 16 declares "pos" again
Fixed code now

@user NeptooN:
me has written
If you find bugs, post your console log in here (especially the lua error).

you has written
@user Bowlinghead: Bowlinghead Does not work.

You find your console log by pressing your console button (default: ^ the key next to ESC and 1).
You can then right click -> copy all.
This will copy the text that you see in your clipboard.
Now you can paste that text with CTRL + V or rightclick onto the textfield and choose "Paste".

Note that this will only call a menu. The menu itself does not do anything! You have to program that in in the lines 36 and so on. Please look at the whole code to be able to edit code properly.

EDIT:
@user NeptooN:
Please try again. I changed the code and it works now
edited 2×, last 27.01.17 03:47:12 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview