English Hover Image

5 replies
Goto Page
To the start Previous 1 Next To the start
15.03.16 03:23:04 am
Up
Rygna
User
Offline Off
Hi!
How to make (Hover Image)!
and Image is Mode HUD 2!

Example >


Thanks !
#SorryForMyEnglish.
Begone.
15.03.16 05:52:27 am
Up
Zeik
User
Offline Off
I think that the only way to do that is by asking the position of the cursor all the time, resulting in lots of lag.

You can do it by using any timer hook (cs2d lua hook ms100, cs2d lua hook second, etc) to call the cs2d lua cmd reqcld function (in mode 0), which calls the cs2d lua hook clientdata's hook function. So, in the cs2d lua hook clientdata function you will have to ask where the cursor is, and if it's at the image's position, then you swap images. Then you would want to ask for when the cursor leaves the image so you change it back to the original.

I think it's not worth doing such thing. The only way I think it wouldn't lag is if you use the cs2d lua hook second hook, though it may look very unresponsive.

You can use this post's responses as reference as how to do this: LINK
It's basically the same thing.
16.03.16 02:01:42 pm
Up
freon29
User
Offline Off
Just check this code >
16.03.16 03:07:30 pm
Up
Fraizeraust
Moderator
Offline Off
user freon29's code works but on the 23 line it triggers an error due of an unfinished string. It can be fixed very easily by just removing the unnecessary quote.
16.03.16 04:18:43 pm
Up
Ortimh
User
Offline Off
Probably won't work as expected.
Code:
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
64
65
-- You need to specify the position of the button manually
local buttonx, buttony = 320, 240 -- on the center of the screen
-- You need to specify the size of the button manually (based on the image)
local buttonwidth, buttonheight = 100, 50
local buttonexists, buttonimage, buttonhovered, mousepos = {}, {}, {}, {}

for id = 1, 32 do
     buttonexists[id] = false
     buttonimage[id] = 0
     buttonhovered[id] = false
     mousepos[id] = {0, 0}
end

addhook("spawn", "spawnhook")
addhook("clientdata", "clientdatahook")
addhook("ms100", "ms100hook")
addhook("die", "diehook")

function spawnhook(id)
     -- Button will appear and hoverable when spawning
     buttonexists[id] = true
     buttonimage[id] = image("path/to/your/button/image.png", buttonx, buttony, 2, id)
end

function clientdatahook(id, mode, data1, data2)
     if (mode == 0) then
          mousepos[id] = {data1, data2}
     end
end

function ms100hook()
     for index, id in ipairs(player(0, "tableliving")) do
          if (buttonexists[id]) then
               reqcld(id, 0)
               
               local x, y = unpack(mousepos[id])
               
               if ((x >= buttonx and x <= buttonx + buttonwidth) and (y >= buttony and y <= buttony + buttonheight)) then
                    if (not buttonhovered[id]) then
                         freeimage(buttonimage[id])
                         
                         buttonimage[id] = image("path/to/your/button/hovered/image.png", buttonx, buttony, 2, id)
                         buttonhovered[id] = true
                    end
               else
                    if (buttonhovered[id]) then
                         freeimage(buttonimage[id])
                         
                         buttonimage[id] = image("path/to/your/button/image.png", buttonx, buttony, 2, id)
                         buttonhovered[id] = false
                    end
               end
          end
     end
end

function diehook()
     -- Button will disappear when you die
     buttonexists[id] = false
     
     freeimage(buttonimage[id])
     
     buttonimage[id] = 0
     buttonhovered[id] = false
end
I'm awesome ... and I really cookies
18.03.16 08:37:48 am
Up
Rygna
User
Offline Off
Thanks, i will test it
maybe, I'm making a project / mod for this.
Begone.
To the start Previous 1 Next To the start