English Check if two players are facing each other

26 replies
Goto Page
To the start Previous 1 2 Next To the start
01.06.21 12:17:00 pm
Up
SQ
Moderator
Offline Off
@user Mami Tomoe: Can you screenshot both scenarios of player positions so I can test?
01.06.21 07:31:10 pm
Up
Mami Tomoe
User
Offline Off
I don't know if that's totally required, all you need to do is have a bot (with A.I. disabled, of course) standing while holding a Tactical Shield.

Then just give him something like Medic Armour and 250 Health Points.

Also, you'd need to have the function get called on the cs2d lua hook hit hook, and have it print the output.

Once you've done that, just try and hit the bot from different places, and you'd notice that the function will sometimes print true when it's not supposed to, or vice-versa.

But if you urgently need images, I can try and get some, perhaps even a video.
fish
01.06.21 07:41:07 pm
Up
Gaios
Security Supporter
Offline Off
@user Mami Tomoe: Dude, we just wasted the time to help you writting an algorithm to detect if players are facing each other. And now you're trying to solve totally another problem. Just do use cs2d lua hook hit and cs2d lua hook shieldhit to detect if you hit the bot. But just don't need any shield or whatsoever, because you can deny all hits to the bots by returing
return 1
on the cs2d lua hook hit hook. I have no idea what do you want to achieve, a bot to help train scanning?
> https://youtu.be/zmprNKisMWQ
01.06.21 07:54:15 pm
Up
SQ
Moderator
Offline Off
@user Mami Tomoe: It doesn't mean my algorithm is not consistent.
Solving "facing each other" does not replicate shield behavior whatsoever.
01.06.21 07:54:58 pm
Up
Mami Tomoe
User
Offline Off
@user Gaios: To have shield work against more than just bullets, those won't trigger the cs2d lua hook shieldhit hook, therefore I have to use the cs2d lua hook hit, and I have to use a check (that I don't know how to make) to know if the hit was in front of the player (where the shield is held).

@user SQ: Well yeah, but originally on the first post, I said that I want to have my own Tactical Shield logic... I thought that was easy to understand, my bad.
fish
01.06.21 08:44:27 pm
Up
SQ
Moderator
Offline Off
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
-- pid1 - source
-- pid2 - victim
-- works only after bullet hit check
function ShieldHit(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 = {}, {}

    p1.x = player(pid1, "x")  -- + weapon offset
    p1.y = player(pid1, "y")  -- + weapon offset

    p2.x = player(pid2, "x") 
    p2.y = player(pid2, "y")
    p2.rot = player(pid2, "rot")

    local rot = math.deg(math.atan2(p1.x - p2.x, p2.y - p1.y))

    local angleDif = ((p2.rot - rot + 180) % 360) - 180

    return(math.abs(angleDif) < 55)
end

function always() 
    
    if ShieldHit(1, 2) then
        parse("msg shieldhit *"..os.clock())
    end
   
end

addhook("always", "always")
edited 5×, last 02.06.21 10:36:00 am
01.06.21 09:23:43 pm
Up
Mami Tomoe
User
Offline Off
@user SQ, that works well! Thank you.
fish
To the start Previous 1 2 Next To the start