Forum

> > CS2D > Scripts > Image with HP?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Image with HP?

8 replies
To the start Previous 1 Next To the start

old Image with HP?

Quattro
GAME BANNED Off Offline

Quote
I made an image on the map:
guy = image("a_guy.png",posX,posY,0,id)

I use tween_move to move it around and I can get his location and other info with object(guy,'x'),object(guy,'y'), etc.

I would also like to make it "alive". How to assign HP to it and make it possible to hit with a gun?

old Re: Image with HP?

DC
Admin Off Offline

Quote
Adding HP: That's up to you. Just add a variable and store the HP. If you want to have multiple images with health you should think about an appropriate data structure with tables.

Make it possible to hit it:
• Use cs2d lua cmd imagehitzone to define a hit zone on hit
• Use the cs2d lua hook hitzone to react to hits (e.g.: reduce your health variable & destroy the image when health is <= 0)

old Re: Image with HP?

Masea
Super User Off Offline

Quote
I just wanted to indite user DC's contribution as a code, so here you go.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
img = {}

img.hp = 100
img.id = image("gfx/block.bmp", 1, 1, 0)
img.mode = 3 --squirts blood in this case

imagehitzone(img.id, img.blood)

addhook("hitzone", "img.hitzone")
function img.hitzone(imgId, id, objId, wpn, impX, impY, dmg)
	if imgId == img.id then
		img.hp = img.hp - dmg
		if img.hp <= 0 then
			freeimage(img.id)
			img.id = nil
		end		
	end
end

For more information, as you're aware, go to http://cs2d.com/help.php

old Re: Image with HP?

Quattro
GAME BANNED Off Offline

Quote
Thank you guys, these commands are just what I needed, I was about to write my own hit detection script

By the way, talking about death:
How would you create a blood splash upon death?
edited 1×, last 18.08.18 12:18:50 pm

old Re: Image with HP?

DC
Admin Off Offline

Quote
That's because I secretly added it a few minutes ago

old Re: Image with HP?

Quattro
GAME BANNED Off Offline

Quote
nice xd
I have also a suggestion:

Try to do a blood bomb effect with a radius like current bomb explosion. At the moment it is very limited and to achieve at least half of the effect I added many blood splatters around the dying player.

It should look like this with decent radius set:
https://youtu.be/Sd9McnrxVn4?t=3m24s

To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview