Forum

> > CS2D > Scripts > Click button in game/map = Opens a menu (lua)
Forums overviewCS2D overview Scripts overviewLog in to reply

English Click button in game/map = Opens a menu (lua)

15 replies
To the start Previous 1 Next To the start

old closed Click button in game/map = Opens a menu (lua)

EndDead
User Off Offline

Quote
Hey there,,
I used the search function but didn't find anything useful about this,,
For example of what i want:
1
On use button x==1715 and y==369 then menu(id,"Buy,blah|1$")

Pretty simple but am still learning some new things in lua.

Sorry for wasting time and for anything done wrong,
Thanks in advance

old Re: Click button in game/map = Opens a menu (lua)

Alistaire
User Off Offline

Quote
user Avo has written
Also possible with "use" hook.

EDIT: user Jynxxx I wanted to ask the same.


If you use the 'use' hook it's possible that the button is disabled but you still open a menu which was never meant to open at that moment.

----

user Jynxxx has written
@user Alistaire: why do you always use AA_ in the function, just saying nothing wrong with it.


1. In the console you know exactly which script uses which hook.

2. You call the function same as the hook so that you don't get things like a 'saycommands' function and an 'adminsay' function' where you have to find out if they use the same hook etc.

3. It stuck, just like the way I only use apastrophes in my scripts. There's not one quotation mark where I could've put an apastrophe in my current version of the Gore Extension (where every function and value has GE_ before it)

4. Functions and values will NEVER conflict with my other scripts if they don't have double hooks.

5. You can easily blend scripts together by replacing the AA_ and BB_ to whatever script you want, like CC_. GE_ = GoreExtension_, MM_ = MedievalMod, etc etc etc.

old Re: Click button in game/map = Opens a menu (lua)

EndDead
User Off Offline

Quote
somehow dosnt work? i tried:
1
2
3
4
5
6
7
addhook('usebutton', 'AA_usebutton')

function AA_usebutton(id, x, y)
     if x == 1715 and y == 369 then
          menu(id,"[my menu here]")
     end
end
is there any wrong? >.>
I tried JeT's too,,
i also used the tile pos thingy,,

old Re: Click button in game/map = Opens a menu (lua)

Alistaire
User Off Offline

Quote
user EndDead has written
somehow dosnt work? i tried:
1
2
3
4
5
6
7
addhook('usebutton', 'AA_usebutton')

function AA_usebutton(id, x, y)
     if x == 1715 and y == 369 then
          menu(id,"[my menu here]")
     end
end
is there any wrong? >.>
I tried JeT's too,,
i also used the tile pos thingy,,


1715 is an x position. You need a tile position, just copy the position from the button entity.

old Re: Click button in game/map = Opens a menu (lua)

EngiN33R
Moderator Off Offline

Quote
user EndDead has written
somehow dosnt work? i tried:
1
2
3
4
5
6
7
addhook('usebutton', 'AA_usebutton')

function AA_usebutton(id, x, y)
     if x == 1715 and y == 369 then
          menu(id,"[my menu here]")
     end
end
is there any wrong? >.>
I tried JeT's too,,
i also used the tile pos thingy,,


Are you sure the positions are tile positions? Sometimes the usebutton hook breaks down for reasons unknown. If nothing works, try this:

1
2
3
4
5
6
7
addhook("use","usebuttonworkaround")
function usebuttonworkaround(id)
	local x,y=player(id,"tilex"),player(id,"tiley")
	if x==1715 and y==369 then
		menu(id,"Buy,blah|$1")
	end
end

old Re: Click button in game/map = Opens a menu (lua)

EndDead
User Off Offline

Quote
Oh i founded whats my wrong, i went to the editor and higlighted the button and the pos was 51 11 (maybe) and i changed it, Now it works. Thanks for the help.

Close this thread if you want, its needless now.. i think
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview