Forum

> > CS2D > Scripts > If player health...then image
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch If player health...then image

9 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt If player health...then image

Mora
User Off Offline

Zitieren
Hello
I want ask for script,
i cant make screenshots,but i make bad with paint
addhook("hit","ifhit")
function ifhit()
if player(id,'health')==100 then
freeeimage[id]
image=("gfx/mchp/100.bmp",32,64,2+id)
elseif player(id,'health')==90 then
freeeimage[id]
image=("gfx/mchp/90.bmp",32,64,2+id)
elseif player(id,'health')==80 then
freeeimage[id]
image=("gfx/mchp/80.bmp",32,64,2+id)
elseif player(id,'health')==70 then
freeeimage[id]
image=("gfx/mchp/90.bmp",32,64,2+id)

...etc
this images as hud.
Spoiler >

alt Re: If player health...then image

EngiN33R
Moderator Off Offline

Zitieren
Assuming you have an image for each health value from 0 to 100 with a step of 10 (0.png, 10.png, 20.png, etc.), you can do the following:

1
2
3
4
5
6
7
8
healthimage = {}

addhook("hit","changehealthimage")
function changehealthimage(id)
	local tenhealth = math.floor(player(id,"health")/10)*10 -- Round health to nearest ten
	if healthimage[id] then freeimage(healthimage[id]) end -- free the existing image if it exists
	healthimage[id] = image("gfx/mchp/"..tenhealth..".png",320,200,2,id) -- create a new image
end

alt Re: If player health...then image

EngiN33R
Moderator Off Offline

Zitieren
@user Mora: If by "a method" you mean your method, then yes, it's probably simpler to newbies. This is more compact and efficient.

healthimage is a table that stores health images for all players.

1
local tenhealth = math.floor(player(id,"health")/10)*10
This rounds the health down to the next ten. So anything from 99 to 91 will become 90, 89 to 81 will be 80 and so on.
How it works >


1
if healthimage[id] then freeimage(healthimage[id]) end
This removes the health image displayed to a player if it already exists.

1
healthimage[id] = image("gfx/mchp/"..tenhealth..".png",320,200,2,id)
This creates a new health image according to the health value we defined previously. So, if we have 90 health, it will load 90.png, if we have 80 - it'll load 80.png.

alt Re: If player health...then image

Mora
User Off Offline

Zitieren
then we need make + one hook?
spawn...
because when i spawn i have display image.
when w/o this hook then
image display only we got hurt and 90health.
when we spawn we dont have image...then slap.and we got full health in image ( five ),but health is 90.if we hurt in spawn then we have 100 hp and image ( five )
and when i slap myself then i have display image (five ) but not image,where (4,5 ).
Sorry my english is .
P,s- yes,i mean my method.

alt Re: If player health...then image

Rainoth
Moderator Off Offline

Zitieren
True, if you're saying that actions beside hitting the enemy can affect player health, you could change the hook to example second or movetile or similar to those.

alt Re: If player health...then image

EngiN33R
Moderator Off Offline

Zitieren
@user Mora: Fair point.

1
2
3
4
5
6
7
8
9
10
11
12
13
healthimage = {}

addhook("spawn","createhealthimage")
function createhealthimage(id)
	healthimage[id] = image("gfx/mchp/100.png",320,200,2,id) -- I would make with player(id,"health") to allow for custom starting health values 
end

addhook("hit","changehealthimage")
function changehealthimage(id)
	local tenhealth = math.floor(player(id,"health")/10)*10 -- Round health to nearest ten
	if healthimage[id] then freeimage(healthimage[id]) end -- free the existing image if it exists
	healthimage[id] = image("gfx/mchp/"..tenhealth..".png",320,200,2,id) -- create a new image
end

Concerning the hearts bug - I don't know why that happens, it shouldn't do. Try slapping yourself down to 80 or 70 - is it also half a heart above how much it needs to be?

alt Re: If player health...then image

Mora
User Off Offline

Zitieren
I don't know about and why I'm looking for an easy way to create the script.
when i spawn i dont have image,then i think add hook spawn. is my logic,or it wrong.
...
aw.
when i slap myself i have image,but image start display 100.bmp but not 90.bmp ( i use bmp files images)

i think need make + one hook
dead,die
when i dead then
freeimage[id]

i bad scripter,and learn it hard for me.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht