25.02.2010, 20:04
Thanks alot
stock SetPlayerToFacePlayer(playerid, targetid)
{
new Float:pX,Float:pY,Float:pZ,
Float:X,Float:Y,Float:Z,
Float:ang;
if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetid)) return 0;
GetPlayerPos(targetid, X, Y, Z);
GetPlayerPos(playerid, pX, pY, pZ);
if( Y > pY ) ang = (-acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
else if( Y < pY && X < pX ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 450.0);
else if( Y < pY ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
if(X > pX) ang = (floatabs(floatabs(ang) + 180.0));
else ang = (floatabs(ang) - 180.0);
SetPlayerFacingAngle(playerid, ang);
}
stock SetPlayerToFacePlayer(playerid,targetid)
{
new Float:a[2];
GetPlayerFacingAngle(playerid,a[0]);
GetPlayerFacingAngle(playerid,a[1]);
SetPlayerFacingAngle(targetid,a[0]+180.0);
}
what is targetid? how to define it? because I get error like this:
C:\Users\user\Desktop\New folder (9)\gamemodes\lol.pwn(456) : error 017: undefined symbol "targetid" |
//a_angles.inc
//Geometric angle functions
//Created by:
//Tannz0rz
#if defined _a_angles_included
#endinput
#endif
#define _a_angles_included
#include <a_samp>
stock IsPlayerBehindPlayer(playerid, targetid, Float:dOffset)
{
new
Float:pa,
Float:ta;
if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetid)) return 0;
GetPlayerFacingAngle(playerid, pa);
GetPlayerFacingAngle(targetid, ta);
if(AngleInRangeOfAngle(pa, ta, dOffset) && IsPlayerFacingPlayer(playerid, targetid, dOffset)) return true;
return false;
}
stock SetPlayerToFacePlayer(playerid, targetid)
{
new
Float:pX,
Float:pY,
Float:pZ,
Float:X,
Float:Y,
Float:Z,
Float:ang;
if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetid)) return 0;
GetPlayerPos(targetid, X, Y, Z);
GetPlayerPos(playerid, pX, pY, pZ);
ang = 180.0-atan2(pX-X,pY-Y);
SetPlayerFacingAngle(playerid, ang);
return 1;
}
stock IsPlayerFacingPlayer(playerid, targetid, Float:dOffset)
{
new
Float:pX,
Float:pY,
Float:pZ,
Float:pA,
Float:X,
Float:Y,
Float:Z,
Float:ang;
if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetid)) return 0;
GetPlayerPos(targetid, pX, pY, pZ);
GetPlayerPos(playerid, X, Y, Z);
GetPlayerFacingAngle(playerid, pA);
ang = atan2(pX-X,pY-Y);
if(AngleInRangeOfAngle(-ang, pA, dOffset)) return true;
return false;
}
stock AngleInRangeOfAngle(Float:a1, Float:a2, Float:range)
{
a1 -= a2;
if((a1 < range) && (a1 > -range)) return true;
return false;
}
I don't really get it.. I'm trying to do, that when player looks at other player and presses middle mouse button and then at targets position create explosion. I'm doing it like this:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) { if (PRESSED( KEY_LOOK_BEHIND )) { if(IsPlayerFacingPlayer(playerid, targetid, 15.0)) { new Float: x, Float: y, Float: z; GetPlayerPos(targetid, x, y, z); CreateExplosion(x, y, z, 12, 10); } } return 1; } What's wrong? sorry for bad english. |