11.01.2011, 06:18
Hello people, I looked all around wiki, but nothing. Is there any method to detect if a player is aiming? General aiming, not where the player is aiming.
KEY_AIM* 128
[*] Key not defined in SA:MP includes. You must define this yourself.
You want to detect if the player has raised his gun to the aiming position? If so you can detect the aim button being pressed/held.
pawn Код:
|
#define KEY_AIM 132
#define HOLDING(%0) \
((newkeys & (%0)) == (%0))
if(pstate == PLAYER_STATE_ONFOOT)
{
if (HOLDING(KEY_AIM))
{
SetPlayerDrunkLevel(playerid,50000);
}
}
/home/SA-MP/Liberty and Vice City RP/United/gamemodes/LcVcRP2.pwn(1318) : warning 213: tag mismatch
if (HOLDING(KEY_AIM && PlayerInfo[playerid][pGunSkill] == 1))
stock IsPlayerAiming(playerid)
{
new anim = GetPlayerAnimationIndex(playerid);
switch(anim)
{
case 1167, 1365, 1643, 1453, 220:
{
return 1;
}
}
return 0;
}
stock IsPlayerAiming(playerid, aimid)
{
// Luby's function.
new Float:X1, Float:Y1, Float:Z1, Float:X2, Float:Y2, Float:Z2;
GetPlayerPos(playerid, X1, Y1, Z1);
GetPlayerPos(aimid, X2, Y2, Z2);
new Float:Distance = floatsqroot(floatpower(floatabs(X1-X2), 2) + floatpower(floatabs(Y1-Y2), 2));
if(Distance < 100)
{
new Float:A;
GetPlayerFacingAngle(playerid, A);
X1 += (Distance * floatsin(-A, degrees));
Y1 += (Distance * floatcos(-A, degrees));
Distance = floatsqroot(floatpower(floatabs(X1-X2), 2) + floatpower(floatabs(Y1-Y2), 2));
if(Distance < 0.5)
{
return true;
}
}
return false;
}