edited 1×, last 26.01.17 11:33:13 am
Forum
CS2D Scripts Open a menu when you say hello on a specific spotOpen a menu when you say hello on a specific spot
18 replies 1
file:///home/yates/games/cs2d/sys/lua/menu.lua
Edit: Good, you figured it out. Upload your screenshot to an image hosting website such as imgur.com then share that link.
So
Lua Scripting in CS2D
Lua Tutorial
edited 1×, last 26.01.17 04:16:15 pm
1
2
3
4
5
6
7
8
9
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
Here's something more go to the link
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
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
']' @ 5
',' @ 6
double menu call @ 19
65/100 an okay code for an example.
@ NeptooN: If you bothered to read, you'd know that he gave you an example, not an actual working code. He did the hard part for you and now you need to fill the easy part with commands and whatnot.
The comma is valid on line 6.
But line 16 declares "pos" again
Fixed code now
@ NeptooN:
me has written
If you find bugs, post your console log in here (especially the lua error).
you has written
@ 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:
@ NeptooN:
Please try again. I changed the code and it works now
edited 2×, last 27.01.17 03:47:12 pm
Thank you everything works.
http://i.imgur.com/clvh4Gq.jpg
http://i.imgur.com/3KrIkf7.jpg
1
2
3
4
5
6
2
3
4
5
6
-- which positions will open a menu when saying !hello ? pos = { [1] = {37,19}, -- stay on Tile 37|19 [2] = {37,20}, -- stay on Tile 37|20 ---... as much you like }
edited 2×, last 27.01.17 04:27:18 pm
1