1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
addhook("move", "collisionThink")
function collisionThink(ply, x, y)
for _, ply2 in pairs(player(0, "table")) do
if (ply ~= ply2 and player(ply2, "health") > 0) then
local x2, y2 = player(ply2, "x"), player(ply2, "y")
local d = math.sqrt((x2-x)^2 + (y2-y)^2) -- Calculate distance between the two players
if (d < 30) then
local a = -(math.atan2(x2-x,y2-y)+math.pi/2)%(2*math.pi) -- Calculate angle between two players and convert it from the CS2D unit circle (from 0 on the Y plane and 90 on the X clockwise to 0 on the X plane and 90 on the Y anticlockwise)
local nx, ny = x2 + math.cos(a)*30, y2 + math.sin(a)*30 -- Calculate position as 30 pixels away from the centre of the second player along the angle calculated above
if (tile(math.floor(nx/32), math.floor(ny/32), "walkable")) then
parse("setpos " .. ply .. " " .. nx .. " " .. ny)
end
end
end
end
end