AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Detect if player1 and player2 is aiming each other? (https://forums.alliedmods.net/showthread.php?t=294540)

Kotoamatsukami 03-01-2017 12:56

Detect if player1 and player2 is aiming each other?
 
Hello, greetings.

I am working on a plugin, that use the features that I mentioned on the title. Is there any possible way to do this? If so, is it like;

PHP Code:

public Randomid )
{
    if( !
is_user_aliveid ) ) return;
    
    new 
id2body;
    
    
get_user_aimingidid2body )
    
get_user_aimingid2idbody )
    
    if( 
pevidpev_button ) & IN_USE && cs_get_user_teamid ) != cs_get_user_teamid2 ) )
    {
        
//......
    
}


Thank you for your time...

OciXCrom 03-01-2017 13:36

Re: Detect if player1 and player2 is aiming each other?
 
Simply get both players' aiming entity and see if they are equal.

PHP Code:

new iEnt[2], iBody
get_user_aiming
(idiEnt[0], iBody)
get_user_aiming(id2iEnt[1], iBody)

if(
iEnt[0] == id2 && iEnt[1] == id)
{
    
// both players are aiming at each other



PRoSToTeM@ 03-01-2017 14:08

Re: Detect if player1 and player2 is aiming each other?
 
Why not
iEnt[0] == id2 && iEnt[1] == id
?

Kotoamatsukami 03-01-2017 14:41

Re: Detect if player1 and player2 is aiming each other?
 
Quote:

Originally Posted by OciXCrom (Post 2499799)
Simply get both players' aiming entity and see if they are equal.

PHP Code:

new iEnt[2], iBody
get_user_aiming
(idiEnt[0], iBody)
get_user_aiming(id2iEnt[1], iBody)

if(
is_user_connected(iEnt[0]) && is_user_connected(iEnt[1]) && iEnt[0] == iEnt[1])
{
    
// both players are aiming at each other



Pardon me...
But, isn't your code will only operate if both 'id' and 'id2' are aiming at the same entity( not each other )?
For instant, I thought PRoSToTeM@'s lines should work if they are aiming each other?

OciXCrom 03-01-2017 14:56

Re: Detect if player1 and player2 is aiming each other?
 
Yeah, my bad. I fixed my code.

Kotoamatsukami 03-02-2017 02:28

Re: Detect if player1 and player2 is aiming each other?
 
Sorry for driving this out from the main context.
If I want the 'id2' to be an enemy to 'id', should I do
PHP Code:

new id2 read_data

Thank in advance...

Craxor 03-02-2017 02:31

Re: Detect if player1 and player2 is aiming each other?
 
Quote:

Originally Posted by Kotoamatsukami (Post 2499955)
Sorry for driving this out from the main context.
If I want the 'id2' to be an enemy to 'id', should I do
PHP Code:

new id2 read_data

Thank in advance...


if( get_user_team( id1 ) != get_user_team( id2 ) )

Kotoamatsukami 03-02-2017 03:50

Re: Detect if player1 and player2 is aiming each other?
 
Quote:

Originally Posted by Craxor (Post 2499956)
if( get_user_team( id1 ) != get_user_team( id2 ) )

Thank you, sir.
I know how to distinguish the stance by using the cs_get_user_team native.
What I am trying to explain is actually how I can properly/exactly catch the index of the enemy( as I don't have a specific index( id2 ) for the enemy in my function...), is it simply by making the new 'id2'?
PHP Code:

new id2Ent], body
get_user_aiming
id2Ent], body 

Will these lines will automatically store the enemy's index into 'id2' ?
Sorry for any inconvenient...

OciXCrom 03-02-2017 07:21

Re: Detect if player1 and player2 is aiming each other?
 
PHP Code:

new idiEnt[2], iBody
get_user_aiming
(idiEnt[0], iBody)
get_user_aiming(iEnt[0], iEnt[1], iBody)

// iEnt[0] = id's enemy
// iEnt[1] = id enemy's enemy = id 


Kotoamatsukami 03-02-2017 10:01

Re: Detect if player1 and player2 is aiming each other?
 
Like this?
PHP Code:

public Randomid )
{
    if( !
is_user_aliveid ) ) return;
    
    new 
iEnt], body;
    
    
get_user_aimingidiEnt], body )
    
get_user_aimingiEnt], iEnt], body )
    
    if( 
iEnt] == id && cs_get_user_teamid ) != cs_get_user_teamiEnt] ) )
    {
        
// do something ....
    
}


Sorry for being so opposite, I am here to clarify things up. Isn't your code is same as the original code that I posted at the first post?

My enormous apology, I am not being rude or picky. It's just that I'd like to hear your opinion on your code...


All times are GMT -4. The time now is 20:45.

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