AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to determine whether the player is looking for an entity? (https://forums.alliedmods.net/showthread.php?t=159543)

PRoSToTeM@ 06-18-2011 16:03

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

bibu 06-18-2011 16:14

Re: How to determine whether the player is looking for an entity?
 
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.

Arkshine 06-18-2011 17:13

Re: How to determine whether the player is looking for an entity?
 
If searching a player, checking classname is pointless. From the index, checking if between 1 and maxclients is enough.

bibu 06-18-2011 17:48

Re: How to determine whether the player is looking for an entity?
 
It was just an example. :)

Arkshine 06-18-2011 18:13

Re: How to determine whether the player is looking for an entity?
 
So, give him the RIGHT code.

bibu 06-18-2011 18:52

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

Originally Posted by PRoSToTeM@ (Post 1490936)
How to determine whether the player is looking for an entity?


Arkshine 06-18-2011 19:34

Re: How to determine whether the player is looking for an entity?
 
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.

lucas_7_94 06-18-2011 19:45

Re: How to determine whether the player is looking for an entity?
 
do you want to check if the player is looking an entity ?

bibu 06-18-2011 19:53

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

Originally Posted by Arkshine (Post 1491045)
Still, your example itself is bad.

Do it better.

Quote:

Originally Posted by Arkshine (Post 1491045)
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 (Post 1491045)
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 ?
......

Exolent[jNr] 06-18-2011 20:33

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

Originally Posted by bibu (Post 1491051)
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 ); }


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

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