SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 23/06/2018, 10:42 PM   #1
Marmeladova
Little Clucker
 
Marmeladova's Avatar
 
Join Date: Dec 2016
Location: Somewhere
Posts: 15
Reputation: 0
Default s_aimobject - is the player aimed to an object

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 Code:
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 Code:
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;

__________________
CLR or Ngen, here's the question.
Marmeladova is online now   Reply With Quote
Old 23/06/2018, 11:14 PM   #2
KinderClans
Little Clucker
 
Join Date: May 2018
Posts: 17
Reputation: 0
Default Re: s_aimobject - is the player aimed to an object

Emh....no.

Code:
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.
KinderClans is offline   Reply With Quote
Old 23/06/2018, 11:17 PM   #3
KashCherry
Little Clucker
 
KashCherry's Avatar
 
Join Date: Feb 2018
Location: Estonia
Posts: 30
Reputation: 19
Default Re: s_aimobject - is the player aimed to an object

It was better if instead of
PHP Code:
OnPlayerAimAtDynamicObject(playeridobjectid
OnPlayerAimAtObject(playeridobjectid
there would be
PHP Code:
OnPlayerStartAimingAtObject(playeridobjectid)
OnPlayerEndAimingAtObject(playeridobjectid)
OnPlayerStartAimingAtDynamicObject(playeridobjectid)
OnPlayerEndAimingAtDynamicObject 
KashCherry is offline   Reply With Quote
Old 23/06/2018, 11:24 PM   #4
Marmeladova
Little Clucker
 
Marmeladova's Avatar
 
Join Date: Dec 2016
Location: Somewhere
Posts: 15
Reputation: 0
Default Re: s_aimobject - is the player aimed to an object

Quote:
Originally Posted by KinderClans View Post
Emh....no.

Code:
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
__________________
CLR or Ngen, here's the question.
Marmeladova is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Include] GetObjectOffset - Get an object's offset to: player, vehicle or object Abagail Includes 15 06/08/2016 11:29 PM
[Tutorial] Idle NPC's reacting to being aimed at and shot. miokie Tutorials 9 26/12/2014 05:03 AM
Object destroys when other player spawns the object Admigo Scripting Help 1 29/03/2013 08:22 AM
Destroy Object when player surfing in object kurta999 Bug Reports 0 06/01/2011 03:08 PM
[Request] Set(Player)ObjectSize / Size parameters in Create(Player)Object [03]Garsino Help Archive 3 28/11/2010 05:12 PM


All times are GMT. The time now is 03:32 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.