Forum

> > CS2D > Scripts > Hitzone Hook
Forums overviewCS2D overview Scripts overviewLog in to reply

English Hitzone Hook

7 replies
To the start Previous 1 Next To the start

old Hitzone Hook

Casper-
User Off Offline

Quote
I am having a problem with Hitzone Hook.
I've created this :

> https://i.imgur.com/tujqMKW.jpg

My goal is that whatever hits the circle, within the circle or anything behind it; doesn't get damaged.

1
2
3
4
5
6
7
8
9
10
11
addhook("spawn", "OverCharacter")
function OverCharacter(id)
	if player(id,"team") == 1 then
	freeimage(id)
	id=image("gfx/sprites/flare2.bmp",1,1,100+id)
	imagehitzone(id,104)
	end
end

addhook("hitzone", "ShotFlare")
function ShotFlare(NEED HELP AT THIS PART)

I've looked up on
> http://www.cs2d.com/help.php?hookcat=all&hook=hitzone#hook
and got confused on these parameters

• image id: dynamic object id of image with hitzone
• player id: id of player who shot (or player who built the shooting object)
• id of dynamic object that shot (or 0 if shot is from a player)
• impact x: impact x position (in pixels)
• impact y: impact y position (in pixels)

I don't know what to write on these parameters

old Re: Hitzone Hook

Joni And Friends
User Off Offline

Quote
You dont need that cs2d lua hook hitzone, Just use this code for your image:
1
imagehitzone(<imgid>,<mode>,-<xsize>/2,-<ysize>/2,<xsize>,<ysize>)
The mode should be 101,102,103 or 104. check at cs2d lua cmd imagehitzone.

But it doesnt work with RPG,Bomb,Rocket. Just work with normal weapon like Assault,SMG,Pistol.

Hope that answer your problem

old Re: Hitzone Hook

Devil-Thanh
GAME BANNED Off Offline

Quote
The most important things you should care about are those lines in cs2d lua cmd imagehitzone
1
2
3
Attention: The hitzone is always rectangular. Image rotation does not affect the hitzone unless you change it manually!
Attention: Defining a huge number of hitzones can have a bad impact on the game performance (when shooting)!
Attention: Hitzones do not work with images which are drawn as HUD (image mode 2)!

old Re: Hitzone Hook

Casper-
User Off Offline

Quote
Still didn't get what to do here.

My script now looks like this

1
2
3
4
5
6
7
8
addhook("spawn", "OverCharacter")
function OverCharacter(id)
	if player(id,"team") == 1 then
	freeimage(id)
	id=image("gfx/sprites/flare2.bmp",1,1,100+id)
	imagehitzone(id,104,47,47,95,95)
	end
end

My goal is to stop any bullets causing damage to the player and anything behind it.

I'm getting green blood (mode 104) but the damage is still there.
I've added some parameters to imagehitzone

1
2
3
...
imagehitzone(id,104,47,47,95,95)
...

And that didn't work. It's same effect.

UPDATE :

Nevermind.
Fixed it *facepalm*
1
2
3
...
imagehitzone(id,104,-47,-47,95,95)
...

old Re: Hitzone Hook

Masea
Super User Off Offline

Quote
Before you are about to do that, we first need to fix all those stuff. Seems like you're making your very first script.

freeimage(id)
Here you are trying to free image that doesn't exist. Either the image id selection is true nor the sequence where you're using it.

Id selection is not correct just because you're using id as for spawn function parameter. Change the parameter of spawn function or of the freeimage function. And I myself never free image if I'm not sure if that image really exists or not since this may give an error input at the console. To avoid from that, you should do something like this:
if imageid then
	freeimage(imageid)
	imageid = nil
end


Whenever you are freeing images, you also should nil their ids in order to refrain further issues.

After all, I'm happy that you fixed your actual issue. But read suggests of mine as well.

old Re: Hitzone Hook

Casper-
User Off Offline

Quote
I've been staring at your post for an hour now, trying to figure out what you were saying haha.
Yes, I'm a total newbie, I think I've understood something from your post... ?

Just a quick question to drop if possible to answer?

Is this a variable ?
...
id=image("gfx/sprites/flare2.bmp",1,1,100+id)
...


So my guess is that id is the name of the variable and after '=' is what this variable holds ? image("gfx/sprites/flare2.bmp",1,1,100+id)

If not a variable, then why is the '=' there ?

I've got SOO many questions actually.

old Re: Hitzone Hook

Masea
Super User Off Offline

Quote
Yes, it is a variable. cs2d lua cmd image is actually a function that returns a number. So we're calling an existing function with that variable.

They are variable types. Function, string, number and table(and even more). You need to learn them from an official tutorial or something.

old Re: Hitzone Hook

Casper-
User Off Offline

Quote
Oh, so when I typed in :

1
imagehitzone(id,104,-47,-47,95,95)

id in the parameter is actually calling that image to be displayed. I got it now.

But then what did I do at :

1
2
3
addhook("spawn", "OverCharacter")
function OverCharacter(id)
	if player(id,"team") == 1 then

You said something about id's for spawn and freeimage
Quote
Id selection is not correct just because you're using id as for spawn function parameter. Change the parameter of spawn function or of the freeimage function.


What you're saying is that I'm calling that variable both in the spawn function and in the image function?

So, for spawn function I should rename the "id" to idk ... "playerId" ?
or rename the variable for image?

Sorry if this is a bother :S
I literally just download a script, experiment with it and try to learn something.
I'm reading a bit by bit from Starkkz's post [GUIDE] How to script or just whatever I find interesting to read
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview