English Locate the center of an explosion

8 replies
Goto Page
To the start Previous 1 Next To the start
Up
FishyFinThing
User
Offline Off
Hi there!

I want to know if it is possible to locate the center of every kind of explosion in this game.
I'm experimenting on knockback function and I'm thinking of making explosion with knockback.

If I use a parse command to create an explosion, that will be easy. But what about grenade and mine?

How to know when and where a grenade or a mine explode?
file cs2d Fishy's Zombie Mod v0.2.0 Beta (Nov 27th 2019) (3) Join my server at "142.11.240.170". I hope you will have a good time. Please give some feedback.
14.10.19 09:25:24 am
Up
Well if you spawn grenades with trigger_if then in the command that you write stands the distance (in pixels) that projectile will travel before explosion/impact.
Hope thats helpfull enough.
When I make map for you feedback is apretiated (even bad one), don't be an asshole and say a litle "thank you".
14.10.19 12:11:00 pm
Up
Boolean
GAME BANNED
Offline Off
Make use of cs2d lua hook projectile.
14.10.19 02:30:35 pm
Up
Gaios
Security Supporter
Offline Off
user Boolean has written:
Make use of cs2d lua hook projectile.

This.
14.10.19 07:02:35 pm
Up
FishyFinThing
User
Offline Off
Thanks!
I used the hook you said and find out where grenade impact. But it will only work for projectile, not something on the ground like mine and laser mine.

Now one more thing left is to locate the explosion from mine and laser mine.
file cs2d Fishy's Zombie Mod v0.2.0 Beta (Nov 27th 2019) (3) Join my server at "142.11.240.170". I hope you will have a good time. Please give some feedback.
15.10.19 04:13:52 am
Up
Boolean
GAME BANNED
Offline Off
Make use of cs2d lua hook objectkill to get object ID and cs2d lua cmd object to get their location, also my advice is don't use player parameter from objectkill hook.
15.10.19 10:08:06 pm
Up
FishyFinThing
User
Offline Off
Thank @user Boolean: for the tip. Now I can also locate the mine.

However, I can't get the accurate angle to get the victim knockbacked toward the right direction.

All I know is that I need distance between the center of explosion and victim. Which mean:
distance_x = victim_x - object_x
distance_y = victim_y - object_y

I think that arctan of distance_x/distance_y is the angle.

But when the code run, it kind of mess up.
The knockback direction should be directly further away from the explosion. However, in some quadrant the direction isn't going as intended.
Perhaps, it's because of the inconsistency about x,y and direction

Here's the code that I use for testing.
It will spawn a mine at tile (4|4) or at x=128 y=128 in term of pixel and tell the player what the angle x,y,distance,direction are.

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
color = {'©255200000','©000255000','©160160255','©255000000','©240000240','©255128064','©255255255','©155255000','©100100255'}

--ARRAY GENERATOR
function initArray(size, iValue)
     local array = {}
     for i = 1, size do
          array[i]=iValue
     end
     return array
end

function cw_hud2(id,txtID,c,txt,x,y,a,v,s)
  local screen_h = player(id,"screenh")
  local screen_w = player(id,"screenw")
  local posX = 0
  local posY = 0

  local align = 0
  local valign = 0
  local size = 13
  local text = ""

  if (screen_h and screen_w) then
    posX = screen_h / 480 * x 
    posY = screen_w / 850 * y
  end

  if (a) then
    align = a
  end

  if (v) then
    valign = v
  end

  if (s) then
    size = s
  end

  if(player(id,"exists") and player(id,"bot") ~= true) then
    text = color[c] .. txt
    parse("hudtxt2 " ..id.. " " ..txtID.. ' "' ..color[c]..txt.. '" '  ..posX.. " " ..posY.. " " ..align.. " " ..valign.. " " ..size)
  end
end

addhook("ms100","hud_angle")
function hud_angle()
  parse("spawnobject 20 4 4 0 0 0")
  local cx = 128
  local cy = 128

  local px = 0
  local py = 0

  local disX = 0
  local disY = 0

  local angle = 0
  
  if(player(1,"exists")) then
    px = player(1,"x")
    py = player(1,"y")
     disX = px - cx
    disY = -(py - cy)
     angle = math.deg(math.atan(disX/disY))
  end

  cw_hud2(1,20,2,"Angle "..angle,200,200,0,0,13)
  cw_hud2(1,21,3,"px "..px,200,210,0,0,13)
  cw_hud2(1,22,4,"py "..py,200,220,0,0,13)
  cw_hud2(1,23,3,"cx "..cx,200,240,0,0,13)
  cw_hud2(1,24,4,"cx "..cy,200,250,0,0,13)
  cw_hud2(1,25,3,"disx "..disX,200,270,0,0,13)
  cw_hud2(1,26,4,"disy "..disY,200,280,0,0,13)
end

addhook("objectkill","cw_knockback_mine")
function cw_knockback_mine(obj)
  parse("spawnobject 20 4 4 0 0 0")
  local x = object(obj,"x")
  local y = object(obj,"y")
  local hitX
  local hitY
  local disX
  local disY
  local angle
  local toX = 0
  local toY = 0
  local knockback_distance = 48
  local hit_List = closeplayers(x,y,96)

  if(table.getn(hit_List) > 0) then
    for id = 1, table.getn(hit_List) do
      hitX = player(hit_List[id],"x")
      hitY = player(hit_List[id],"y")
      disX = hitX - x
      disY = -(hitY - y)
      angle = math.deg(math.atan(disX/disY))
      --adjusting angle to start at 3 o'clock counter clockwise
      --angle = 90 - angle
      --if (angle < 0) then angle = 360 + angle end

      if(player(id,"exists")) then
      toX = toX + knockback_distance * math.cos(angle)
      toY = toY + knockback_distance * math.sin(angle)
      end

      msg("target "..hit_List[id])
      msg("at x"..hitX.." y"..hitX)
      msg("angle "..angle)
      msg("impact center x"..x.." y"..y)
      msg("toX "..toX)
      msg("toY "..toY)
    end
  end
end
file cs2d Fishy's Zombie Mod v0.2.0 Beta (Nov 27th 2019) (3) Join my server at "142.11.240.170". I hope you will have a good time. Please give some feedback.
15.10.19 11:52:09 pm
Up
TrialAndError
User
Offline Off
Try this, it's untested but it should get the job done for mines. I don't really know how effective it will be against laser mines because the "explosion center" (x, y in the code) is where the object is placed.

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
local knockback_distance = 48

addhook("objectkill","cw_knockback_mine")
function cw_knockback_mine(obj)
    local x, y = object(obj,"x") + 16, object(obj,"y") + 16 -- add 16 to get the center of the tile
    local hit_List = closeplayers(x, y, 96)

    if(#hit_List > 0) then
        for id = 1, #hit_List do 
            local target = hit_List[id]
            if(player(target,"exists")) then
                local targetX = player(target, "x")
                local targetY = player(target, "y")
                local angle = math.atan2(targetY - y, targetX - x)
                toX = targetX + knockback_distance * math.cos(angle)
                toY = targetY + knockback_distance * math.sin(angle)
                parse("setpos "..target.." "..toX.." "..toY)
            end
        end
    end
end
16.10.19 03:24:45 am
Up
FishyFinThing
User
Offline Off
And that's is all I need to know for the knockback mechanism.

Thanks everyone!

Now I can enjoy doing rocket jump with my grenade launcher.
file cs2d Fishy's Zombie Mod v0.2.0 Beta (Nov 27th 2019) (3) Join my server at "142.11.240.170". I hope you will have a good time. Please give some feedback.
To the start Previous 1 Next To the start