Check if player is standing behind other player
#1

******d it, no results found. Have anybody thought about it? I can't really think of the way of checking when player is behind other player and other player is not facing him?
Reply
#2

this is an example and hope you understand it:
PHP Code:
#include <a_samp>
#include <zcmd>
CMD:kill(playeridparams[])
{
new 
player1string[128], rname[24];
if(!
IsNumeric(params)) player1 ReturnPlayerID(params);
else 
player1 strval(params);
if(
GetDistanceBetweenPlayers(playerid,player1) > 3) {
GetPlayerName(player1rname24);
format(stringsizeof(string), "%s Is not close enough",rname);
SendClientMessage(playerid, -1string);
} else {
SetPlayerHealth(player10);
}
return 
1;
}
forward Float:GetDistanceBetweenPlayers(p1,p2);
public 
Float:GetDistanceBetweenPlayers(p1,p2){
    new 
Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    if (!
IsPlayerConnected(p1) || !IsPlayerConnected(p2))
    {
        return -
1.00;
    }
    
GetPlayerPos(p1,x1,y1,z1);
    
GetPlayerPos(p2,x2,y2,z2);
    return 
floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}
stock IsNumeric(string[])
{
    for (new 
0strlen(string); ji++)
    {
        if (
string[i] > '9' || string[i] < '0') return 0;
    }
    return 
1;
}
stock ReturnPlayerID(PlayerName[])
{
    for(new 
0MAX_PLAYERSi++)
    {
        if(
IsPlayerConnected(i))
        {
            if(
strfind(pName(i),PlayerName,true)!=-1) return i;
        }
    }
    return 
INVALID_PLAYER_ID;
}
stock pName(playerid)
{
  new 
plname[MAX_PLAYER_NAME];
  
GetPlayerName(playeridplnamesizeof(plname));
  return 
plname;
}
stock Float:GetPosInFrontOfPlayer(playerid, &Float:x, &Float:yFloat:distance)
{
    new 
Float:a;
     
GetPlayerPos(playeridxya);
      switch(
IsPlayerInAnyVehicle(playerid))
       {
        case 
0GetPlayerFacingAngle(playerida); // maybe add -180 to this
          
case 1GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    }
    
+= (distance floatsin(-adegrees));
    
+= (distance floatcos(-adegrees));
    return 
a;

Reply
#3

Hmm, you could modify this function:
pawn Code:
stock Float:GetPosInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
    new Float:a;
    GetPlayerPos(playerid, x, y, a);
    switch(IsPlayerInAnyVehicle(playerid))
    {
        case 0: GetPlayerFacingAngle(playerid, a); // maybe add -180 to this
        case 1: GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    }
    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
    return a;
}
Reply
#4

Quote:
Originally Posted by dominik523
View Post
Hmm, you could modify this function:
pawn Code:
stock Float:GetPosInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
    new Float:a;
    GetPlayerPos(playerid, x, y, a);
    switch(IsPlayerInAnyVehicle(playerid))
    {
        case 0: GetPlayerFacingAngle(playerid, a); // maybe add -180 to this
        case 1: GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    }
    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
    return a;
}
Thanks for Notice + Updated
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)