Forum

> > CS2D > Scripts > Images as HUD
Forums overviewCS2D overview Scripts overviewLog in to reply

English Images as HUD

11 replies
To the start Previous 1 Next To the start

old Images as HUD

Dousea
User Off Offline

Quote
As the title, actually I want to request something.

How to make images as HUD? I mean the images is numbers images, like 1.png, 2.png, 3.png as the HUD number. I can't actually do this. Well for example, my health are 51 in the game and I want the HUD (images) shows 51. I don't want to create 1.png to 100.png, it's wasting of time.

Remember, I've got cookie, cookie or even cookies, cookies .

old Re: Images as HUD

Necr0
User Off Offline

Quote
cs2d lua cmd image has written
Parameters:
     "path"
     x
     y
     mode
     [pl] (optional)

[...]

Possible modes:
     Mode 0: floor image (covered by players etc)
     Mode 1: top image (covering players)
     Mode 2: HUD image (covering everything, part of the interface)
     Mode 3: super top image (covering everything on the map)
     Mode 101-132: draw under this player (id+100)
     Mode 201-232: draw over this player (id+200)
     Mode 133-164: draw over this player and over entities (id+132)


1
image("path",x,y,2,id)

old Re: Images as HUD

Apache uwu
User Off Offline

Quote
You won't need to make the numbers 1.png to 100.png, only 0.png to 9.png and you'll be able to make all the numbers.

old Re: Images as HUD

Zeik
User Off Offline

Quote
I want to add that you also can disable things shown in the normal HUD in the server settings. Just in case you didn't know...

old Re: Images as HUD

Dousea
User Off Offline

Quote
Thank you guys for the replies.

What I mean is I want to make images as numbers. I knew how to change images mode into the part of the interface (HUD) long time ago. Well, for example to explain my mean:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
addhook([[always]], [[updateImages]])
function updateImages()
	for _, pl in pairs(player(0, [[table]])) do
		while player(pl, [[exists]]) do
			local function checkNumbers(pl, num)
				images([[gfx/numbers/]]..num..[[.png]], 0, 0, 2, pl)
			end
			if player(pl, [[health]]) > 0 then
				local img = checkNumbers(pl, player(pl, [[health]]))
				imagepos(img, 320, 240, 0)
			end
		end
	end
end

This function maybe works, but I don't want to create 1 to 100 images, it's waste of time. Please, is there any other option if I have only 0 to 9 images? I can create the numbers as the HUD with 10 images only but this is gonna waste of code.

old Re: Images as HUD

Zeik
User Off Offline

Quote
I don't know if I understand you but you can use 0 to 9 images.
You need to reefresh everyone's HP with the HIT hook everytime they're hit.
You could get the two numbers to draw doing something like this:
If for example the HP is 48, you do 48/10=4 (integer) and 48-(4*10)=8, there you have the two numbers to draw. And if HP is 100 it is an exception and you should do and specific condition for it. Then it's like, if [unit]=8, draw 8; if [tenth]=4, draw 4.

Is the only thing I could think quickly.

old Re: Images as HUD

Apache uwu
User Off Offline

Quote
For this to work with only 10 images (0.png - 9.png), you should have 3 images for every player.

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
addhook("hit", "_hit")
addhook("die", "_die")
addhook("spawn", "_spawn")
addhook("leave", "_leave")

local images = {}

function removeImages(id)
    images[id] = images[id] or {}
    for i = 1, #images[id] do
        freeimage(images[id][i])
    end
    images[id] = {}
end

function _hit(id, source, wpn, hpdmg)
    removeImages(id)
    local newHP = tostring(player(id, "health") - hpdmg)
    for i = 1, #newHP do
        local img = image("gfx/numbers/"..newHP:sub(i,i)..".png", 0, 0, 2, id)
        imagepos(img, 320 + (i-1) * 50, 240, 0)
        table.insert(images[id], img)
    end
end

function _spawn(id)
    _hit(id, 0, 0, 0)
end

function _die(id)
    removeImages(id)
end

function _leave(id)
    removeImages(id)
end

This loops through the player's health, for example, 78, it takes the 7 and places it on the HUD and then the 8 with a padding of 50 pixels. The image IDs are then placed in a multidimensional table where it can be freed if the health changes.

EDIT: Yeah you'll need hooks to remove images if the player dies or quits. The code above is edited, go ahead and copy that version.
edited 1×, last 07.02.14 07:51:30 am

old Re: Images as HUD

Pagyra
User Off Offline

Quote
IMG:https://s017.radikal.ru/i427/1402/36/8f52ac08606a.png

so as you can see - all numbers\icons\hudbars in quake mod is hud images.
Create a table for each type of image with specific coordinates.

old Re: Images as HUD

Apache uwu
User Off Offline

Quote
The code is written neatly, if you grab a copy of it, it can show you the specific functions that you can incorporate into your own script.

Also the code from the last post was edited a few days ago to fix any problems.

old Re: Images as HUD

RisingXD
User Off Offline

Quote
user Pagyra, that screenshot is awesome!
Anyway, if you want to just edit the hud but in colors, just use layers. That is glitch work.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview