Check if a player is behind a player
#1

Hello, I'm in need of a function that checks if a player is behind another player (Making an achievement for killing someone from behind with knife)

So... is there any?
Reply
#2

https://sampwiki.blast.hk/wiki/Stocks

Sorry, not doing all the work for you, but work with OnPlayerDeath; check out GetXYInFrontOfPlayer and set the distance to -1, then check if killerid is InRangeOf that Point. Also, make sure that reason == 4 and (not necessary) that GetPlayerWeapon of killerid is 4.
Reply
#3

Quote:
Originally Posted by Grand_Micha
View Post
https://sampwiki.blast.hk/wiki/Stocks

Sorry, not doing all the work for you, but work with OnPlayerDeath; check out GetXYInFrontOfPlayer and set the distance to -1, then check if killerid is InRangeOf that Point. Also, make sure that reason == 4 and (not necessary) that GetPlayerWeapon of killerid is 4.
Already knew most of that, but what function is GetXYInFrontOfPlayer, how does it work? Can you link it?
Reply
#4

...you didn't even bother with the link, did you? Just open the page, look at "Returning multiple values". You do not even have to be familiar with trigonometry, just copy and paste and experiment until you get the hang of it.
Reply
#5

Use IsPlayerInRangeOfPoint
Reply
#6

Quote:
Originally Posted by Kitten
View Post
That checks if the player is near, not behind.

Probs need to get the angle, and then compare the angle to the other players pos.
Shouldn't be too hard.
Reply
#7

My boys, I've already posted EVERYTHING he needs...but alas, we cannot heal sloth.
Reply
#8

Quote:
Originally Posted by milanosie
View Post
That checks if the player is near, not behind.

Probs need to get the angle, and then compare the angle to the other players pos.
Shouldn't be too hard.
Yeah misread the topic anyways this should do it,

pawn Code:
stock IsPlayerBehindPlayer(playerid, targetid, Float:dOffset) {
    new Float:playera,Float:playert;
    if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetid)) return 0;
    GetPlayerFacingAngle(playerid, playera);
    GetPlayerFacingAngle(targetid, playert);
    if(AngleInRangeOfAngle(playera, playert, dOffset) && IsPlayerFacingPlayer(playerid, targetid, dOffset)) return true;
    return false;
}
Reply
#9

Quote:
Originally Posted by Kitten
View Post
Yeah misread the topic anyways this should do it,

pawn Code:
stock IsPlayerBehindPlayer(playerid, targetid, Float:dOffset) {
    new Float:playera,Float:playert;
    if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetid)) return 0;
    GetPlayerFacingAngle(playerid, playera);
    GetPlayerFacingAngle(targetid, playert);
    if(AngleInRangeOfAngle(playera, playert, dOffset) && IsPlayerFacingPlayer(playerid, targetid, dOffset)) return true;
    return false;
}
Wouldnt this work if the player is in front of someone and facing them aswell



Quote:
Originally Posted by Grand_Micha
View Post
...you didn't even bother with the link, did you? Just open the page, look at "Returning multiple values". You do not even have to be familiar with trigonometry, just copy and paste and experiment until you get the hang of it.
You are not even telling me how the function works
Reply
#10

The most precise reading you would get by checking for the animation index of the "knifing," then setting a boolean and a timer which will check if the target is dead and next to the killer. Oh well, have fun with your wasted resources, in case you choose this way.

Edit: Sigh. This function returns two values with the help of the ampersand symbols. First, you get the playerpos. Then you get their facing angle and then you get the sin and cos of x and y respectively. As to why you do....ever heard of sohcahtoa?
Reply
#11

Quote:
Originally Posted by Grand_Micha
View Post
The most precise reading you would get by checking for the animation index of the "knifing," then setting a boolean and a timer which will check if the target is dead and next to the killer. Oh well, have fun with your wasted resources, in case you choose this way.

Edit: Sigh. This function returns two values with the help of the ampersand symbols. First, you get the playerpos. Then you get their facing angle and then you get the sin and cos of x and y respectively. As to why you do....ever heard of sohcahtoa?
Can you just give me an example of this code under OnPlayerDeath? Some of your words are too complicated for me.
Reply
#12

I am with my SGS2, so I'll try to explain. The link I sent you - there are two boxes under Returning multiple values. For your code, you need the first box with GetXYInFrontOfPlayer without the vehicle check. OnPlayerDeath, you type

new Float, Float:y, Float:z;
GetPlayerPos(playerid,x,y,z);
GetXYInFrontOfPlayer(playerid,x,y,-1);//-1 checks coords behind playerid.
IsPlayerInRangeOfPoint(killerid,...);//Here you check if killerid is next to the point behind playerid.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)