12.07.2010, 13:37
Headshot detection function - for sniper rifle 
it's very accurate, can't be more precise
and it only uses 1 loop (for looping trough all players)

it's very accurate, can't be more precise
and it only uses 1 loop (for looping trough all players)
Код:
#include <a_samp>
new bool:ShowHitCoords = false; //Set to 'true' to show where the bullet hits. (red ball is the center if the enemy's head)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
stock Float:Distance(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
{
new Float:result = floatsqroot(floatpower(floatsub(x2,x1),2)+floatpower(floatsub(y2,y1),2)+floatpower(floatsub(z2,z1),2));
return result;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys == 132 && GetPlayerWeapon(playerid) == 34)
{
new Float:Cvx, Float:Cvy, Float:Cvz;
new Float:Cvx2, Float:Cvy2, Float:Cvz2;
new Float:distance;
new Float:P2x, Float:P2y, Float: P2z;
new Float:Cx, Float:Cy, Float:Cz;
GetPlayerCameraPos(playerid, Cx, Cy, Cz);
GetPlayerCameraFrontVector(playerid, Cvx, Cvy, Cvz);
for(new i; i<MAX_PLAYERS; i++)
{
if((IsPlayerConnected(i) && i != playerid))
{
GetPlayerPos(i, P2x, P2y, P2z);
if(GetPlayerSpecialAction(i) == SPECIAL_ACTION_DUCK)
{
new Float:P2a;
GetPlayerFacingAngle(i, P2a);
P2a += 330;
P2x += 0.27 * floatsin(-P2a, degrees);
P2y += 0.27 * floatcos(-P2a, degrees);
P2z -= 0.08;
}
else P2z += 0.76;
distance = Distance(Cx, Cy, Cz, P2x, P2y, P2z);
Cvx2 = Cvx * distance + Cx;
Cvy2 = Cvy * distance + Cy;
Cvz2 = Cvz * distance + Cz;
if(ShowHitCoords == true)
{
CreateObject(2996, Cvx2, Cvy2, Cvz2, 0.0, 0.0, 0.0);
CreateObject(2997, P2x, P2y, P2z, 0.0, 0.0, 0.0);
}
if(Distance(Cvx2, Cvy2, Cvz2, P2x, P2y, P2z) < 0.18)
{
SetPlayerHealth(i, 0.0);
break;
}
}
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

