English get player id behind the wall

4 replies
Goto Page
To the start Previous 1 Next To the start
26.12.21 04:40:30 pm
Up
Unknown_Cheater
User
Offline Off
when player shot or trigger attack hook pointer to other player behin the wall then msg the id

1------[] 2

1 = shooter
2 = victim
[] = wall
2084729947754920835
26.12.21 05:26:06 pm
Up
DC
Admin
Offline Off
So if the mouse pointer of player 1 is pointing at player 2, you want to display the id of player 2?

If yes you can do this in the cs2d lua hook attack hook (or any other hook):
• retrieve mousemapxand mousemapy of player 1 with cs2d lua cmd player
• create 2 variables id and distance,
• iterate over all living players:
Code:
1
2
3
4
local playerlist=player(0,"tableliving")
for _,id in pairs(playerlist) do
   ' insert distance check logic here
end

• inside the loop calculate the distance of the player position (cs2d lua cmd player x and y) and mouse position from the first step. You can probably skip player 1 (the one you got the mouse cursor position from)
• if the the id variable is still 0 or if the calculated distance is smaller than the value in the distance variable, save the player id and the distance to the variables
• at the end of the loop the id variable will contain the id of the closest player to the cursor and the distance variable will contain the distance between that player and the cursor
• in the end you can check if the distance is close enough (<= 32 for instance) and then display the ID

If this should also work when the mouse cursor of player 1 is NOT pointing exactly at player 2 but also when player 1 is just looking at player 2 you have to use some math and check which player is closest to the invisible line of sight of player 1.
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
26.12.21 05:44:30 pm
Up
Unknown_Cheater
User
Offline Off
@user DC:
Code:
1
2
3
4
5
6
7
8
9
10
11
vid = 0

addhook("attack", "attack_")
function attack_(sid)
     if player(sid, "weapon") == 32 then
          if player(sid, "rot") ==  -- its victim position idk how to do it
               vid = -- idk how to get victim id, dont using hit hook
               msg2(sid, "ID: "..vid)
          end
     end
end
2084729947754920835
26.12.21 05:59:24 pm
Up
DC
Admin
Offline Off
So you also want to get the ID of players the player is "looking at" without pointing at them with the cross hair?

In either way you have to iterate over all other players and do a distance check. Either the distance to the mouse pointer of player 1 or the distance to the line of sight of player 1.
https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
26.12.21 06:23:28 pm
Up
Unknown_Cheater
User
Offline Off
distance
Code:
1
math.sqrt((player(sid, "x") - player(vid, "x")) ^ 2 + (player(sid, "y") - player(vid, "y")) ^ 2))
2084729947754920835
To the start Previous 1 Next To the start