SA-MP Forums Archive
[Include] s_aimobject - is the player aimed to an 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: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] s_aimobject - is the player aimed to an object (/showthread.php?tid=655550)



s_aimobject - is the player aimed to an object - Marmeladova - 23.06.2018

Include, which implements the ability to check in the callbacks, whether the player aimed at the object or removed the sight from it.

Author: #Samurai aka un[x]pected aka Marmeladova (only at forum.sa-mp.com)
Download: GitHub

Callbacks:
PHP код:
OnPlayerAimAtObject(playeridobjectid)
// playerid - ID of the player who aimed at the object
// objectid - ID of the object the player aimed at (INVALID_OBJECT_ID if the player stops aiming at any objects)
OnPlayerAimAtDynamicObject(playeridobjectid)
// playerid - ID of the player who aimed at the dynamic object
// objectid - ID of the dynamic object the player aimed at (0 if the player stops aiming at any dynamic objects) 
Example of using:
PHP код:
public OnPlayerAimAtObject(playeridobjectid)
{
    if(
objectid == 65535) return SendClientMessage(playerid, -1"You stopped aiming at the object");
    new 
chatStr[30];
    
format(chatStrsizeof(chatStr), "You aimed at the object %i"objectid);
    
SendClientMessage(playerid, -1chatStr);
    return 
1;
}
public 
OnPlayerAimAtDynamicObject(playeridobjectid)
{
    if(
objectid == 0) return SendClientMessage(playerid, -1"You stopped aiming at the dynamic object");
    new 
chatStr[38];
    
format(chatStrsizeof(chatStr), "You aimed at the dynamic object %i"objectid);
    
SendClientMessage(playerid, -1chatStr);
    return 
1;




Re: s_aimobject - is the player aimed to an object - KinderClans - 23.06.2018

Emh....no.

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PRESSED(KEY_AIM))
    {
            targetTimer[playerid] return SetTimerEx("TargetObjectTimer", TARGET_TIMER_INTERVAL, true, "i", playerid);
            else ( EnablePlayerCameraTarget(playerid, true));
    }
    else if(RELEASED(KEY_AIM))
    {
        if(lastTargetObj[playerid] != INVALID_OBJECT_ID) return lastTargetObj[playerid] = INVALID_OBJECT_ID or OnPlayerAimAtObject(playerid, INVALID_OBJECT_ID);
        {
        }
        KillTimer(targetTimer[playerid]); EnablePlayerCameraTarget(playerid, false);
    }
    #if defined ExOnPlayerKeyStateChange   
        return ExOnPlayerKeyStateChange(playerid, newkeys, oldkeys);
    #else
        return 1;
    #endif
}
Better.


Re: s_aimobject - is the player aimed to an object - KashCherry - 23.06.2018

It was better if instead of
PHP код:
OnPlayerAimAtDynamicObject(playeridobjectid
OnPlayerAimAtObject(playeridobjectid
there would be
PHP код:
OnPlayerStartAimingAtObject(playeridobjectid)
OnPlayerEndAimingAtObject(playeridobjectid)
OnPlayerStartAimingAtDynamicObject(playeridobjectid)
OnPlayerEndAimingAtDynamicObject 



Re: s_aimobject - is the player aimed to an object - Marmeladova - 23.06.2018

Quote:
Originally Posted by KinderClans
Посмотреть сообщение
Emh....no.

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PRESSED(KEY_AIM))
    {
            targetTimer[playerid] return SetTimerEx("TargetObjectTimer", TARGET_TIMER_INTERVAL, true, "i", playerid);
            else ( EnablePlayerCameraTarget(playerid, true));
    }
    else if(RELEASED(KEY_AIM))
    {
        if(lastTargetObj[playerid] != INVALID_OBJECT_ID) return lastTargetObj[playerid] = INVALID_OBJECT_ID or OnPlayerAimAtObject(playerid, INVALID_OBJECT_ID);
        {
        }
        KillTimer(targetTimer[playerid]); EnablePlayerCameraTarget(playerid, false);
    }
    #if defined ExOnPlayerKeyStateChange   
        return ExOnPlayerKeyStateChange(playerid, newkeys, oldkeys);
    #else
        return 1;
    #endif
}
Better.
Lmao dude