PDA

View Full Version : Detect aim.


MechaTech
18/06/2012, 04:59 PM
I want if je aim at an object it will give you money. I have this:
stock IsPlayerAiming(playerid, aimid)
{
new Float:X1, Float:Y1, Float:Z1, Float:X2, Float:Y2, Float:Z2;
GetPlayerPos(playerid, X1, Y1, Z1);
GetObjectPos(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;
}

And if he is aiming:

new myobj;
myobj = CreateDynamicObject(2942, 2110.6797, -1791.0314, 14.3004, 0.00, 0.00, 0.00);

if(IsPlayerAiming(playerid, myobj))
{
GivePlayerMoney(playerid, 2000);
}

But if i am at the object it doesnt give money.