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
function Dot(a, b)
    return((a.x*b.x)+(a.y*b.y))
end
function Distance(a, b)
	return math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))
end
function PointToLine(pixelPos, vA, vB)
    local v0, v1 = {}, {}
    v0.x = vB.x - vA.x
    v0.y = vB.y - vA.y
    local sqrt = math.sqrt(v0.x * v0.x + v0.y * v0.y)
    v0.x = v0.x / sqrt
    v0.y = v0.y / sqrt
    v1.x = pixelPos.x - vA.x
    v1.y = pixelPos.y - vA.y
    local t = Dot(v0, v1)
    if (t <= 0) then
        return(vA)
    elseif (t >= Distance(vA, vB)) then
        return(vB)
    end
    local v2 = {}
    v2.x = vA.x + v0.x * t
    v2.y = vA.y + v0.y * t
    return(v2)
end
function PlayersFaceEachOther(pid1, pid2)
    if (player(pid1, "exists") == false or player(pid2, "exists") == false) then
        return(false);
    end
    if (player(pid1, "health") < 1 or player(pid2, "health") < 1) then
        return(false)
    end
    local p1, p2 = {}, {}
    local p1raycast, p2raycast = {}, {}
    -- needs check if player is in other player screen
    
    -- player 1
    p1.x = player(pid1, "x")
    p1.y = player(pid1, "y")
    p1.rot = math.rad(player(pid1, "rot") - 90)
    p1raycast.x = p1.x + math.cos(p1.rot) * 320
    p1raycast.y = p1.y + math.sin(p1.rot) * 320
    -- player 2
    p2.x = player(pid2, "x")
    p2.y = player(pid2, "y")
    p2.rot = math.rad(player(pid2, "rot") - 90)
    
    -- raycast offsets
    p2raycast.x = p2.x + math.cos(p2.rot) * 320
    p2raycast.y = p2.y + math.sin(p2.rot) * 320
    -- raycast p1
    p1vec = PointToLine(p1, p2, p2raycast)
    p2seeOther = Distance(p1vec, p1) < 16
    -- raycast p2
    p2vec = PointToLine(p2, p1, p1raycast)
    p1seeOther = Distance(p2vec, p2) < 16  
    
    -- combine results
    return(p1seeOther and p2seeOther)
end
function always() 
    seeEachOther = PlayersFaceEachOther(1, 2)
    if (seeEachOther) then
        parse("msg seeeachother *"..os.clock())
    end
    
end
addhook("always", "always")