English Hitzone not work in some map.

11 replies
Goto Page
To the start Previous 1 Next To the start
24.06.14 08:14:12 am
Up
-DIE Wolf-
User
Offline Off
Ok ! This is simple image and hit zone scripts :

Code:
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
function initArray(m,v)
     local array = {}
     for i = 1, m do
          array[i]=v
     end
     return array
end

monster=initArray(32,0)


addhook("startround","start")
function start()
     i=1
     monster[i]=image("gfx/cs2d.bmp",320,320,0)--------Image at 320 320
     imagehitzone(monster[i],104,-92/2,-92/2,92,92)
end
start()

addhook("second","second")
function second()
     tween_rotate(monster[i],1000,math.random(-50,50))
end

addhook("hitzone","hz")
function hz(i,player,obj,wpn,x,y)
     freeimage(monster[i])
end


If u run this scripts in official map ( Or any map with no Env_Building) Image will disappear if u shot it.
But if u run this scripts in any maps has turrets(Env_building), It will not.

So weird.
Why ?
IMG:https://www.gametracker.com/images/game_icons64/csgo.png
24.06.14 11:16:51 am
Up
AlcatrazZ
BANNED
Offline Off
Interesting. Maybe those maps, have builted lua to the map.
Ban Reason: Multiple Accounts
24.06.14 11:26:46 am
Up
-DIE Wolf-
User
Offline Off
user AlcatrazZ Not. I'm tested in mapeditor.
IMG:https://www.gametracker.com/images/game_icons64/csgo.png
24.06.14 01:53:57 pm
Up
AlcatrazZ
BANNED
Offline Off
@user -DIE Wolf-: omg, somethink like de_dust2.map and de_dust2.lua in maps folder.
Ban Reason: Multiple Accounts
24.06.14 02:02:59 pm
Up
Masea
Super User
Offline Off
oh die wolf ty, I understand image hit zone system now.
Create your UI easy and fast: UI Framework | Go deeper into the darkness and test your bravery: file cs2d Outlast 2 Modification (27)
24.06.14 02:14:21 pm
Up
-DIE Wolf-
User
Offline Off
user Masea Yw. Also, problem solved if i change freeimage(monster[i]) to freeimage(monster[i-5]). And i have no idea why.
Can anyone explain it ?
IMG:https://www.gametracker.com/images/game_icons64/csgo.png
24.06.14 04:49:42 pm
Up
ohaz
User
Offline Off
Quote:
addhook("startround","start")
function start()
i=1
monster[i]=image("gfx/cs2d.bmp",320,320,0)--------Image at 320 320
imagehitzone(monster[i],104,-92/2,-92/2,92,92)
end
start()

First of all: You only give player 1 the image?
Second: Why do you call "start()" yourself?
Third: You read the documentation, but you didn't think about it anyways.
Quote:
function hz(i,player,obj,wpn,x,y)
freeimage(monster[i])
end
. You used the first parameter (i), which is the image id, not the player ID. Use freeimage(monster[player]) instead
https://ohaz.engineer - Software Engineering
25.06.14 09:16:23 am
Up
-DIE Wolf-
User
Offline Off
user ohaz:
The image spawn at 320 320 and not follow anyone.
I call start() because for some reason, hook startround doesnt work.

The image not follow any player. So use freeimage(monster[i]) is right.
IMG:https://www.gametracker.com/images/game_icons64/csgo.png
25.06.14 09:32:05 am
Up
EngiN33R
Moderator
Offline Off
user -DIE Wolf- has written:
user Masea Yw. Also, problem solved if i change freeimage(monster[i]) to freeimage(monster[i-5]). And i have no idea why.
Can anyone explain it ?


This is because the i argument that the hitzone hook provides is the image ID. If there are env_building entities on the map, then there also exist dynamic objects which have image IDs assigned to them. It works with -5 because there are 5 dynamic objects on the map to which image IDs from 1 to 5 are assigned to.

Code:
1
2
3
4
5
6
addhook("startround","start")
function start()
     monster[1]=image("gfx/cs2d.bmp",320,320,0) --Image at 320 320
     imagehitzone(monster[1],104,-92/2,-92/2,92,92)
end
start()


First of all, there's no need to set a global i to 1 to assign something to monster[1]. I won't question why you hardcode one entry, I suppose you'll create a spawning algorithm later. Also, the startround hook doesn't work for you on a listen server because you have to restart a round for it to actually start, and for the hook to be called. You could leave the function call in, or you could just execute restart in the console.

Code:
1
2
3
4
5
6
7
8
addhook("hitzone","hz")
function hz(img,player,obj,wpn,x,y)
     for i = 1, #monster do -- check all monster entries
          if (img == monster[i]) then
               freeimage(img)
          end
     end
end


The keys in monster don't actually depend on anything, not player, not object, nothing - they're separate, which is why you simply have to compare the image that a person hit with all monster images. If a match is found then you hit one of the monster images and you can freely remove it.

A couple more additions:

Code:
1
2
3
4
5
6
addhook("second","second")
function second()
     for i = 1, #monster do -- Again, don't hardcode values
          tween_rotate(monster[i],1000,math.random(-50,50))
     end
end


And you don't have to use initArray() for your monster table. You could simply replace lines 1 to 9 in your original code with this:

Code:
1
monster = {}


Complete code >
I code, therefore I exist. | Visit my blog for Lua tips and other interesting info
25.06.14 09:50:39 am
Up
-DIE Wolf-
User
Offline Off
Oh ok, but how do u spawn more than 2 monsters ?
IMG:https://www.gametracker.com/images/game_icons64/csgo.png
25.06.14 11:04:04 am
Up
EngiN33R
Moderator
Offline Off
Well, you could use a loop and spawn them at random positions on the map. Here's a simple spawning algorithm:

Code:
1
2
3
4
5
6
7
8
9
10
11
12
function spawnmonster(img)
     local x, y = math.random(0, map("xsize")), math.random(0, map("ysize"))
     if (tile(x, y, "walkable")) then
          monster[#monster+1] = image(img, x*32+16, y*32+16, 0)
     else
          spawnmonster(img)
     end
end

for i = 1, 3 do -- As many as you want really
     spawnmonster("gfx/cs2d.bmp")
end
I code, therefore I exist. | Visit my blog for Lua tips and other interesting info
25.06.14 11:16:26 am
Up
-DIE Wolf-
User
Offline Off
Thank user EngiN33R alot !
IMG:https://www.gametracker.com/images/game_icons64/csgo.png
To the start Previous 1 Next To the start