Forum

> > CS2D > Scripts > How to use buttons with mp hudscale = 3
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch How to use buttons with mp hudscale = 3

9 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt How to use buttons with mp hudscale = 3

Denisgrad
User Off Offline

Zitieren
Is it possible to use mp hudscale = 3 with file Datei existiert nicht (17532) ?

For some reason the image location fits to screen but the trigger .OnClick does not.

I have no idea how to make the x,y location of img sync with trigger on the button

EDIT:
1
2
3
4
5
6
7
local bid = #gui.imageButton + 1
    local newresx = player(id,"screenw") / 1600
    local newresy = player(id,"screenh") / 900
    b.x = x * newresx 
    b.y = y * newresy
...
b.img = image(path, b.x, b.y, 2, id)

This made it fit better but its still not perfect. Any suggestions?
1× editiert, zuletzt 05.12.17 08:13:15

alt Re: How to use buttons with mp hudscale = 3

Gaios
Reviewer Off Offline

Zitieren
I suggest to use cs2d cmd mp_hudscale 1 because it has auto-scaling for each resolution.

You can use this framework which has a lot of functionalities such as Visual Lua, Screen Aligns, OOP Images, Auto freeimage at players leave, Custom skin loader, Main Menu system, Map Pointers (GPS system), Setter and Getters for player instance, Math library, and so on which I will add later (you can suggest me any update ideas).

Example
> https://github.com/gajosadrian/Gajos-Framework/blob/master/app/test.lua

alt Re: How to use buttons with mp hudscale = 3

VaiN
User Off Offline

Zitieren
I also recommend to use cs2d cmd mp_hudscale 1

You have the right idea with calculating, just in the wrong way. Keep in mind that players can have either Standard or Wide resolutions. The hudscale will auto-scale, but you will need to adjust depending on which one they use. What I do is store a value for it in a table for each player id, and then have two sets of coords for each. It makes things more complex for sure, but also ensures that it works for everyone. The Y coordinate will always be the same, so it isn't needed for both, but it's easier to include it.

example:
1
2
res = {}
for i = 1,32 do res[i] = "wide" end

when a player joins, get which one they use
1
2
3
4
5
function check_res(id)
	local ar = player(id,"screenw") / player(id,"screenh")
	if ar < 1.4 then res[id] = "standard" else res[id] = "wide" end
end
addhook("join","check_res")

then you can reference which coords to use from that table
1
2
3
4
5
6
7
8
9
coord = {}
coord.button1 = {
	["wide"] = {x = 425, y = 2},
	["standard"] = {x = 320, y = 2}
}

-- and when you use the coords:
local x = coord.button1[ res[id] ].x
local y = coord.button1[ res[id] ].y
This will ensure that it'll be positioned the same for all players.

The coordinates are pretty simple once you know where to start. With mp_hudscale 1 you use 850x480 for wide, 640x480 for standard. As long as your coordinates are based on those, then it'll all work the same.

I'm not familiar with the GUI framework you are using, so this approach may not be compatible with it. If not, I'd recommend you post a comment to the author where you downloaded it and link to this post.

Edit: I'm wrong. You can't calculate aspect ratio this way. The height for "standard" resolutions is adjusted to make it fair and the screenh returned is not including the borders it adds. Only way to calculate it is with a best guess based on the screen width.
1× editiert, zuletzt 10.12.17 01:26:40

alt Re: How to use buttons with mp hudscale = 3

Denisgrad
User Off Offline

Zitieren
I fixed the issue now. I wrote the script for two resolutions 1. 1920x1080 and 2. 1600x900. The location of images changes based on user's resolution.

One question though. Most CS2D users play on these resolutions right?

alt Re: How to use buttons with mp hudscale = 3

Gaios
Reviewer Off Offline

Zitieren
user Denisgrad hat geschrieben
I fixed the issue now. I wrote the script for two resolutions 1. 1920x1080 and 2. 1600x900. The location of images changes based on user's resolution.

One question though. Most CS2D users play on these resolutions right?

If they would have those monitors, the will have money for better games than CS2D
And all modern games use automatic hud scaling, so you just should use cs2d cmd mp_hudscale 1. Also for me default resolution in-game should be 1366x768 than 850x480.

alt Re: How to use buttons with mp hudscale = 3

Masea
Super User Off Offline

Zitieren
@user Denisgrad: You do not have to update it though. The functions you need existed in the old versions as well. Nevertheless, updating it would cause tons of change if you did much with old versions. If I were you, I'd definitely update it to ensure the new features!
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht