Raised This Month: $ Target: $400
 0% 

How to determine whether the player is looking for an entity?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 06-18-2011 , 16:03   How to determine whether the player is looking for an entity?
Reply With Quote #1

How to determine whether the player is looking for an entity?
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
bibu
Veteran Member
Join Date: Sep 2010
Old 06-18-2011 , 16:14   Re: How to determine whether the player is looking for an entity?
Reply With Quote #2

PHP Code:
stock bool:is_aiming_at_player(id)
{
    new 
targettempclassname[32]
    
    
get_user_aiming(idtargettemp)
    
    
pev(targetpev_classnameclassname31)
    
    if(
equal(classname"player")) 
        return 
true
       
    
return false

This would be to check if a player is aiming at another player. For all the other entities I would use an array where all the solid entities are in there.
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-18-2011 , 17:13   Re: How to determine whether the player is looking for an entity?
Reply With Quote #3

If searching a player, checking classname is pointless. From the index, checking if between 1 and maxclients is enough.
__________________
Arkshine is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 06-18-2011 , 17:48   Re: How to determine whether the player is looking for an entity?
Reply With Quote #4

It was just an example.
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-18-2011 , 18:13   Re: How to determine whether the player is looking for an entity?
Reply With Quote #5

So, give him the RIGHT code.
__________________
Arkshine is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 06-18-2011 , 18:52   Re: How to determine whether the player is looking for an entity?
Reply With Quote #6

Quote:
Originally Posted by PRoSToTeM@ View Post
How to determine whether the player is looking for an entity?
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-18-2011 , 19:34   Re: How to determine whether the player is looking for an entity?
Reply With Quote #7

Still, your example itself is bad. People who will see that are going to use unnecessary native by following your beautiful "example". It's a bad method and you lead people to a wrong usage of classname check. So, don't be approximative, change your "example", make a special for player and another for non-player entities. It would make more sense and would be helpful.
__________________

Last edited by Arkshine; 06-18-2011 at 19:36.
Arkshine is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 06-18-2011 , 19:53   Re: How to determine whether the player is looking for an entity?
Reply With Quote #8

Quote:
Originally Posted by Arkshine View Post
Still, your example itself is bad.
Do it better.

Quote:
Originally Posted by Arkshine View Post
It's a bad method and you lead people to a wrong usage of classname check.
Bad method of checking for players maybe, yes. You were just talking about checking players, and I said it can be used for other entities too (what the OP wants).

Quote:
Originally Posted by Arkshine View Post
So, don't be approximative, change your "example", make a special for player and another for non-player entities. It would make more sense and would be helpful.
Do it yourself then.

@lucas:

Can you read the topic?

Quote:
Re: How to determine whether the player is looking for an entity?
do you want to check if the player is looking an entity ?
......
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-18-2011 , 20:33   Re: How to determine whether the player is looking for an entity?
Reply With Quote #9

Quote:
Originally Posted by bibu View Post
Do it better.



Bad method of checking for players maybe, yes. You were just talking about checking players, and I said it can be used for other entities too (what the OP wants).



Do it yourself then.
Your stock function is named is_aiming_at_player().
Therefore, it should be for checking players only.
You could write another stock that check if player is aiming at an entity with a given classname.
Here are those 2 stocks:
Code:
#include < amxmodx > #include < engine > new g_iMaxPlayers; public plugin_init( ) {     g_iMaxPlayers = get_maxplayers( ); } stock bool:is_aiming_at_player(id) {     new iEntity, iBody;     get_user_aiming( id, iEntity, iBody );         return ( 1 <= iEntity <= g_iMaxPlayers ); } stock bool:is_aiming_at_classname(id, const classname[]) {     new iEntity, iBody;     get_user_aiming( id, iEntity, iBody );         new szEntityClassname[ 32 ];     entity_get_string( iEntity, EV_SZ_classname, szEntityClassname, charsmax( szEntityClassname ) );         return equal( classname, szEntityClassname ); }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-19-2011 , 02:57   Re: How to determine whether the player is looking for an entity?
Reply With Quote #10

Quote:
Originally Posted by bibu View Post
Do it better...Do it yourself then.
Don't post examples if you don't know what you're doing nor the knowledge to provide correct code then.
__________________
Arkshine is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 23:25.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode