Forum

> > CS2D > Scripts > Buton Lua
Forums overviewCS2D overview Scripts overviewLog in to reply

English Buton Lua

5 replies
To the start Previous 1 Next To the start

old Buton Lua

Cons
User Off Offline

Quote
Well, i was working on my script, and i have a little trouble.
And sorry, i know i had already made a thread about this subject.

What i want is..
When a player press a certain button in game then it opens a menu.

I dont want...

1
2
3
4
addhook("use" , "DRESA")
function DRESA(id,title, button)
menu(id,"Shop Name,Tab1,Tab2")
end

Thanks if you could help!

old Re: Buton Lua

Obviously Exactly Myself
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
53
54
55
56
57
58
59
60
61
62
63
menu_title = EXAMPLE
menu_button1 = EXAMPLE
menu_description1 = EXAMPLE
menu_button2 = EXAMPLE
menu_description2 = EXAMPLE
menu_button3 = EXAMPLE
menu_description3 = EXAMPLE
menu_button4 = EXAMPLE
menu_description4 = EXAMPLE
menu_button5 = EXAMPLE
menu_description5 = EXAMPLE
menu_button6 = EXAMPLE
menu_description6 = EXAMPLE
menu_button7 = EXAMPLE
menu_description7 = EXAMPLE
menu_button8 = EXAMPLE
menu_description8 = EXAMPLE
menu_button9 = EXAMPLE
menu_description9 = EXAMPLE
menu_tile_x = EXAMPLE
menu_tile_y = EXAMPLE

--SCRIPT--

function menu_box(id)
	menu(id,""..menu_title..","..menu_button1.."|"..menu_description1..","..menu_button2.."|"..menu_description2..","..menu_button3.."|"..menu_description3..","..menu_button4.."|"..menu_description4..","..menu_button5.."|"..menu_description5..","..menu_button6.."|"..menu_description6..","..menu_button7.."|"..menu_description7..","..menu_button8.."|"..menu_description8..","..menu_button9.."|"..menu_description9..",")
end

addhook("menu","menu_press")
function menu_press(id,menu,sel)
	if (menu==""..menu_title.."") then
		if sel == 0 then
			---PUT STUFF HERE!
		elseif sel == 1 then
			---PUT STUFF HERE!
		elseif sel == 2 then
			---PUT STUFF HERE!
		elseif sel == 3 then
			---PUT STUFF HERE!
		elseif sel == 4 then
			---PUT STUFF HERE!
		elseif sel == 5 then
			---PUT STUFF HERE!
		elseif sel == 6 then
			---PUT STUFF HERE!
		elseif sel == 7 then
			---PUT STUFF HERE!
		elseif sel == 8 then
			---PUT STUFF HERE!
		elseif sel == 9 then
			---PUT STUFF HERE!
		end
	end
end

ddhook("use","zj_use")
function zj_use(id,x,y)
	if zj_ride[id] == 0 then
		if player(id, "tilex") == "..menu_tile_x.." and player(id, "tiley") == "..menu_tile_y.." then
			menu_box(id)
		end
	end
end

Just replace the 'EXAMPLE'

old Re: Buton Lua

EngiN33R
Moderator Off Offline

Quote
@user Obviously Exactly Myself: You deserve to be killed many times and then killed the same amount of times again and again. More precisely, stabbed in the back with a pink dildo at least a hundred times.

@user Cons: DON'T USE HIS CODE! It's awful and broken. This one may be complicated, but when you understand it you'll get what efficiency is.

Code >

old Re: Buton Lua

Obviously Exactly Myself
User Off Offline

Quote
@user EngiN33R: It was just a quick one. Actually, I'm dead

_-_-_-_

I think you want to know how to make a function when you press a button in a menu, right?
1
2
3
4
5
6
7
8
9
10
addhook("menu","menstruation")
function menstruation(id,menu,sel)
	if (menu=="EXAMPLE") then --Replace EXAMPLE with the menu title!
		if sel == 1 then --First one!
			--Stuff goes here!
		elseif sel == 2 then --Button 2!
			--Stuff goe- blah.. blah... blah...
		end
	end
end

old Re: Buton Lua

Cons
User Off Offline

Quote
@user EngiN33R: I was looking up for your replyes and i found what i wanted

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
addhook("usebutton","sleepbut")
function sleepbut(id,x,y)
     if entity(x,y,"name")=="sleep" then
          local sleepi=image("gfx/sprites/block.bmp",320,240,2,id)
          imagealpha(sleepi,0)
          local speed=player(id,"speedmod")
imagescale(sleepi,20,15)
parse("speedmod "..id.." -100")
timer(7000,"parse","speedmod "..id.." "..speed)
          tween_alpha(sleepi,1000,1)
          timer(6000,"parse","lua tween_alpha("..sleepi..",1000,0)") --delay of 6 seconds because fading takes up 1
          timer(6000,"parse","sethealth "..id.." "..player(id,"maxhealth"))
          timer(7000,"parse","lua freeimage("..sleepi..")") --delay of 7 seconds because both fades take up 2
     end
end

But i am gonna use it to press trigger_use and opens a lua_menu...

edited 1×, last 05.03.12 03:01:00 am

Admin/mod comment

note that it's "button" and NOT "buton" (just saying because you used "buton" in titles twice now!)
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview