23.06.2012, 22:15
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?
So... is there any?
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. |
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. |
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;
}
Yeah misread the topic anyways this should do it,
pawn Code:
|
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? |