SA-MP Forums Archive
Object Question - 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: Object Question (/showthread.php?tid=265389)



Object Question - Tommy_Mandaz - 30.06.2011

Hello,

Is there a way to detect if the player is aiming at an object? I've seen things like onplayeraimatplayer or onplayershootplayer but is there a onplayeraimatobject or shootatobject? Thanks


Re: Object Question - GangsTa_ - 30.06.2011

I don't think it's possible, maybe there is - search & ****** is your friend.


Re: Object Question - Revolutionary Roleplay - 30.06.2011

It wouldn't be difficult to make, depending on how you would like to do it. Just think about it logically.

Here is the basic IsPlayerAimingAtPlayer function.

Код:
stock IsPlayerAimingAtPlayer(playerid, targetid)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(targetid, x, y, z);
    if (IsPlayerAimingAt(playerid, x, y, z-0.75, 0.25)) return true;
    if (IsPlayerAimingAt(playerid, x, y, z-0.25, 0.25)) return true;
    if (IsPlayerAimingAt(playerid, x, y, z+0.25, 0.25)) return true;
    if (IsPlayerAimingAt(playerid, x, y, z+0.75, 0.25)) return true;
    return false;
}
As you can see, all you would need to change is the position (the GetPlayerPos). You would need some kind of dynamic object system if you wanted to detect if a player is aiming at any object or multiple different objects of the same ID, but if it's just one scenario just set the x, y, and z to the appropriate coordinates.

Of course you would need to do some more editing then JUST that, but for the most part it's as simple as that. It really depends on the scenario you are talking about.


Re: Object Question - Tommy_Mandaz - 30.06.2011

Yeah I understand what you mean im thinking of a fire system aspect where the fire object would automatically start a timer once the player begins aiming at it and removes it self after a couple of seconds... Would need to work on it a bit.