SA-MP Forums Archive
Calculating if a text draw is colliding with a object. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Calculating if a text draw is colliding with a object. (/showthread.php?tid=88974)



Calculating if a text draw is colliding with a object. - [TG]Chase - 30.07.2009

If its even possible with mathematical functions.. Could someone tell me how I would detect if a text draw is pointing at a object?

I want to put a very small text draw object onto the aiming dot. And using advanced calculating techniques, I would like to detect when a player is aiming their gun at the object. Using just the object's position and angle, with the text draw's position on the screen.


Re: Calculating if a text draw is colliding with a object. - paytas - 30.07.2009

It isn't possible with samp.


Re: Calculating if a text draw is colliding with a object. - Joe Staff - 30.07.2009

Yes it is. But it requires a plugin to create a function that returns the player's X rotation (as in, aiming up and down) and then it requires some trigonometry.


Re: Calculating if a text draw is colliding with a object. - paytas - 30.07.2009

Quote:
Originally Posted by Joe Staff
a plugin to create a function that returns the player's X rotation (as in, aiming up and down)
I think you mean pitch and still no, not possible.



Re: Calculating if a text draw is colliding with a object. - Joe Staff - 30.07.2009

Yeah it is. Give me a reason why it's not?

You can determine the pitch of a player's aim because it's server-held information (meaning it's in the server, so other players can see how a player is aiming) and you can use trigonometry to determine the angle between 2 points (players) plus you offset the Z coordinates.


Re: Calculating if a text draw is colliding with a object. - paytas - 30.07.2009

Well, maybe you're right, maybe it is possible, but how to retrieve this value from the server then? How comes no one released plugins with new players functions?


Re: Calculating if a text draw is colliding with a object. - Joe Staff - 30.07.2009

****** did with YSF, but he focused on other things like fixes and a few functions (SetPlayerGravity, SetPlayerSkinForPlayer), if I knew C++ I'd be all over this. All you'd need to know is the pointer address of the first player's pitch, then offset for each other player, which would probably take some time to get, but can be done using a Memory Editor like cheat engine.


Re: Calculating if a text draw is colliding with a object. - yezizhu - 30.07.2009

I don't know how to deal with textdraw.

Here's the function for aiming check, but it doesn't check z, because there's no such a 'z' angle.
pawn Код:
//Author:yezizhu
#define DisBetweenPoints(%1,%2,%3,%4,%5,%6) floatsqroot(((%1-%4)*(%1-%4))+((%2-%5)+(%2-%5))+((%3-%6)*(%3-%6)))

//Author:too many guys
 stock Float:getInfrontXY(&Float:x,&Float:y,Float:a,Float:distance){
  new
    Float:tmpx=x,
    Float:tmpy=y;
  x = tmpx+(distance*floatsin(-a, degrees));
  y = tmpy+(distance*floatcos(-a, degrees));
}

//Author:***** - Alex
#define PointToPoint(%0,%1,%2,%3,%4,%5,%6) (((%0 - %3) * (%0 - %3)) + ((%1 - %4) * (%1 - %4)) + ((%2 - %5) * (%2 - %5)) <= %6 * %6)
stock isPlayerAimingArea(playerid, Float,Float:y,Float:centre){
new
Floatx,Floaty,Floatz,Floata;
GetPlayerPos(playerid,px,py,pz);
GetPlayerFacingAngle(playerid,pa);
Float:getInfrontXY(px,py,pa,DisBetweenPoints(px,py ,0,x,y,0));
return PointToPoint(px,py,0,x,y,0,centre);
}[/pawn]
Note:More detail, DIY


Re: Calculating if a text draw is colliding with a object. - [TG]Chase - 30.07.2009

Thanks yezizhu, but could you tell me what exactly "Float:centre" refers to?


Re: Calculating if a text draw is colliding with a object. - yezizhu - 30.07.2009

Quote:
Originally Posted by Chaser98
Thanks yezizhu, but could you tell me what exactly "Float:centre" refers to?
The centre of the area
I don't know how to explain : O