get player id behind the wall
4 replies



26.12.21 04:40:30 pm
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
1------[] 2
1 = shooter
2 = victim
[] = wall
2084729947754920835
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
attack hook (or any other hook):
retrieve mousemapxand mousemapy of player 1 with
player
create 2 variables id and distance,
iterate over all living players:
inside the loop calculate the distance of the player position (
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.
If yes you can do this in the





Code:
1
2
3
4
2
3
4
local playerlist=player(0,"tableliving")
for _,id in pairs(playerlist) do
' insert distance check logic here
end
for _,id in pairs(playerlist) do
' insert distance check logic here
end





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.
@
DC:

Code:
1
2
3
4
5
6
7
8
9
10
11
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
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
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
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
distance
Code:
1
math.sqrt((player(sid, "x") - player(vid, "x")) ^ 2 + (player(sid, "y") - player(vid, "y")) ^ 2))
2084729947754920835



