AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved [HELP] Player Aim At Entity (https://forums.alliedmods.net/showthread.php?t=294841)

DarthMan 03-09-2017 09:00

[HELP] Player Aim At Entity
 
Hello. This is the current code to display the map name on the panels when the player gets closer to them. Can someone modify the code to display them if player is aiming at the entity named target_name ? Thanks!

Code:

public display_map_name(task_id)
{
new ent
new entcount, entlist[32]
new panel
while ((ent = find_ent_by_tname(ent, "target_map")) !=0)
{
        entcount = find_sphere_class(ent, "player", 50.0, entlist, sizeof(entlist))
        //if (entcount > 0) client_print(0, print_chat, "Found %d players at panel %d.", entcount, panel + 1)
        for(new player_index; player_index < entcount; player_index++)
        {
                set_hudmessage(g_hud_colour[0], g_hud_colour[1], g_hud_colour[2], -1.0, -1.0, 0, 0.0, 2.0, 0.0, 0.0, 2)
                show_hudmessage(entlist[player_index], g_mapnames[g_mapselection[panel]])
        }       
        panel++
}
}


OciXCrom 03-09-2017 10:23

Re: [HELP] Player Aim At Entity
 
PHP Code:

new iEntiBody
get_user_aiming
(idiEntiBody50.0)

if(
pev_valid(iEnt))
{
    new 
szClass[32]
    
pev(iEntpev_classnameszClasscharsmax(szClass))
    
    if(
equal(szClass"target_map"))
    {
        
// display HUD message for player "id"
    
}



DarthMan 03-09-2017 11:49

Re: [HELP] Player Aim At Entity
 
Quote:

Originally Posted by OciXCrom (Post 2502112)
PHP Code:

new iEntiBody
get_user_aiming
(idiEntiBody50.0)

if(
pev_valid(iEnt))
{
    new 
szClass[32]
    
pev(iEntpev_classnameszClasscharsmax(szClass))
    
    if(
equal(szClass"target_map"))
    {
        
// display HUD message for player "id"
    
}



Ty, I didnt know that iEnt can be declared inside the script. Thanks!

DarthMan 03-09-2017 12:13

Re: [HELP] Player Aim At Entity
 
Quote:

Originally Posted by OciXCrom (Post 2502112)
PHP Code:

new iEntiBody
get_user_aiming
(idiEntiBody50.0)

if(
pev_valid(iEnt))
{
    new 
szClass[32]
    
pev(iEntpev_classnameszClasscharsmax(szClass))
    
    if(
equal(szClass"target_map"))
    {
        
// display HUD message for player "id"
    
}



I get a run time error 10 now, saying native error (native "get user aiming") , line 158.

Kotoamatsukami 03-09-2017 12:35

Re: [HELP] Player Aim At Entity
 
Quote:

Originally Posted by DarthMan (Post 2502138)
I get a run time error 10 now, saying native error (native "get user aiming") , line 158.

Hello.
I recently used the native too and I do believe the distance should be in integer, you can refer to the native information.

PHP Code:

native Float:get_user_aiming(index,&id,&bodydist=9999); 


DarthMan 03-09-2017 12:42

Re: [HELP] Player Aim At Entity
 
Quote:

Originally Posted by Kotoamatsukami (Post 2502142)
Hello.
I recently used the native too and I do believe the distance should be in integer, you can refer to the native information.

Code:

native Float:get_user_aiming(index,&id,&body,dist=9999);

I did change it to 50.

I did that for now, but it doesn't display the message on the panels, even if I put test on the emssage.

Code:

public display_map_name(id)
{
new ent, body
new entlist[32]
new panel
while ((ent = find_ent_by_tname(ent, "target_map")) !=0)
{
        //entcount = find_sphere_class(ent, "player", 50.0, entlist, sizeof(entlist))
        //if (entcount > 0) client_print(0, print_chat, "Found %d players at panel %d.", entcount, panel + 1)
        if ( is_user_connected(id) || is_user_alive(id) )
        {
                for(new player_index; player_index < get_user_aiming(id, ent, body, 50) ; player_index++)
                {
                set_hudmessage(g_hud_colour[0], g_hud_colour[1], g_hud_colour[2], -1.0, -1.0, 0, 0.0, 2.0, 0.0, 0.0, 2)
                show_hudmessage(entlist[player_index], g_mapnames[g_mapselection[panel]])
                }
        }       
        panel++
}
}


Kotoamatsukami 03-09-2017 13:16

Re: [HELP] Player Aim At Entity
 
First of all, I am just trying to help here and if this still doesn't help, I am sorry.

I will explain here what I am trying to do. Firstly, catch what the 'id' is aiming, and save the aimed target into 'iEnt'. Then, I check in the while loop if the aimed index( iEnt ) is equal to the entity that the user wanted to aim( ent ). So, I check it( ent == iEnt ). If it's equal then show the HUD message that you wanted to show to the user.

I might be wrong but any improvement or rectification towards my code is greatly welcomed.
Thank you..
PHP Code:

public display_map_nameid )
{
    new 
iEntbodyentlist32 ], panel
    
    get_user_aiming
idiEntbody50 )
    
    while( ( 
ent find_ent_by_tnameent"target_map" ) ) !=)
    {
        if ( 
is_user_connectedid ) && ent == iEnt )
        {
            
set_hudmessageg_hud_colour], g_hud_colour], g_hud_colour], -1.0, -1.000.02.00.00.0)
            
show_hudmessageentlistent ], g_mapnamesg_mapselectionpanel ] ] )
        }
        
    
panel++
    }    



DarthMan 03-09-2017 13:23

Re: [HELP] Player Aim At Entity
 
Quote:

Originally Posted by Kotoamatsukami (Post 2502153)
First of all, I am just trying to help here and if this still doesn't help, I am sorry.

I will explain here what I am trying to do. Firstly, catch what the 'id' is aiming, and save the aimed target into 'iEnt'. Then, I check in the while loop if the aimed index( iEnt ) is equal to the entity that the user wanted to aim( ent ). So, I check it( ent == iEnt ). If it's equal then show the HUD message that you wanted to show to the user.

I might be wrong but any improvement or rectification towards my code is greatly welcomed.
Thank you..
PHP Code:

public display_map_nameid )
{
    new 
iEntbodyentlist32 ], panel
    
    get_user_aiming
idiEntbody50 )
    
    while( ( 
ent find_ent_by_tnameent"target_map" ) ) !=)
    {
        if ( 
is_user_connectedid ) && ent == iEnt )
        {
            
set_hudmessageg_hud_colour], g_hud_colour], g_hud_colour], -1.0, -1.000.02.00.00.0)
            
show_hudmessageentlistent ], g_mapnamesg_mapselectionpanel ] ] )
        }
        
    
panel++
    }    



Sadly, it doesn't display anything :(

DarthMan 03-09-2017 13:27

Re: [HELP] Player Aim At Entity
 
Quote:

Originally Posted by Kotoamatsukami (Post 2502153)
First of all, I am just trying to help here and if this still doesn't help, I am sorry.

I will explain here what I am trying to do. Firstly, catch what the 'id' is aiming, and save the aimed target into 'iEnt'. Then, I check in the while loop if the aimed index( iEnt ) is equal to the entity that the user wanted to aim( ent ). So, I check it( ent == iEnt ). If it's equal then show the HUD message that you wanted to show to the user.

I might be wrong but any improvement or rectification towards my code is greatly welcomed.
Thank you..
PHP Code:

public display_map_nameid )
{
    new 
iEntbodyentlist32 ], panel
    
    get_user_aiming
idiEntbody50 )
    
    while( ( 
ent find_ent_by_tnameent"target_map" ) ) !=)
    {
        if ( 
is_user_connectedid ) && ent == iEnt )
        {
            
set_hudmessageg_hud_colour], g_hud_colour], g_hud_colour], -1.0, -1.000.02.00.00.0)
            
show_hudmessageentlistent ], g_mapnamesg_mapselectionpanel ] ] )
        }
        
    
panel++
    }    



I fixed the warning, but it sitll doesn't work.

Code:

public display_map_name( id )
{
    new iEnt, body, entlist[ 32 ], panel
   
    while( ( ent = find_ent_by_tname( ent, "target_map" ) ) !=0 )
    {
        if ( is_user_connected( id ) && ent == iEnt && get_user_aiming( id, iEnt, body, 50 ) )
        {
            set_hudmessage( g_hud_colour[ 0 ], g_hud_colour[ 1 ], g_hud_colour[ 2 ], -1.0, -1.0, 0, 0.0, 2.0, 0.0, 0.0, 2 )
            show_hudmessage( entlist[ id ], g_mapnames[ g_mapselection[ panel ] ] )
        }
       
        panel++
    }   
}


DarthMan 03-09-2017 14:08

Re: [HELP] Player Aim At Entity
 
Code:

public display_map_name( i_Client )
{
        if ( ! is_user_connected( i_Client )  ||  ! is_user_alive( i_Client ))
        return;
        new i_Body, i_Target;       
        get_user_aiming( i_Client, i_Target, i_Body, 100 )

        if( pev_valid( i_Target ) != 2 )
        return;
       
        static sz_tname[ 32 ];
        pev( i_Target, pev_targetname, sz_tname, 31 )
       
        if ( !( equal( sz_tname, "target_map" ) ) )
                return;
       
        set_hudmessage( g_hud_colour[ 0 ], g_hud_colour[ 1 ], g_hud_colour[ 2 ], -1.0, -1.0, 0, 0.0, 2.0, 0.0, 0.0, 2 )
        show_hudmessage( i_Client, "Test" )
}

Still doesn't work :(


All times are GMT -4. The time now is 17:46.

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