AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved in_view_cone of entity (https://forums.alliedmods.net/showthread.php?t=325699)

Celena Luna 07-03-2020 03:32

in_view_cone of entity
 
I tried to detect if player is in front of the entity.
I used in_view_cone & distance to check. The distance was fine but in_view_cone didn't detect player.

PHP Code:

public Spawn_NPC(id)
{
    new 
szModelPath[64], team
    formatex
(szModelPathsizeof(szModelPath) - 1"models/Z_Files/Zombies/%s.mdl"g_Zombie_Model[0])

    static 
entidentid engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target"))
    if(!
pev_valid(entid)) return
    new 
Float:VEC_HULL_MIN[3] = {-15.0, -9.0, -36.0}
    new 
Float:VEC_HULL_MAX[3] = {15.09.028.0}

    
set_pev(entidpev_classnameNPC_ZOMBIE)
    
engfunc(EngFunc_SetModelentidszModelPath)
    
set_pev(entidpev_modelindexZombieModelIndex[Class])

    
engfunc(EngFunc_SetSizeentidVEC_HULL_MINVEC_HULL_MAX)
    
    
set_pev(entidpev_iuser1STATE_IDLE)
    
set_pev(entidpev_anglesNPC_Angle[0])
    
set_pev(entidpev_v_angleNPC_VAngle[0])

    
set_pev(entidpev_movetypeMOVETYPE_PUSHSTEP)

    
set_pev(entidpev_solidSOLID_BBOX)

    
set_pev(entidpev_originNPC_Origin[0])
    
//set_pev(entid, pev_angles, g_Item_Angle[item_type])

    
set_pev(entidpev_animtimeget_gametime())
    
set_pev(entidpev_framerate1.0)
    
set_pev(entidpev_sequence0)
    
set_pev(entidpev_nextthinkget_gametime() + 0.01)
}

public 
Zombie_Think(ent)
{
    if(!
pev_valid(ent))
        return 
FMRES_IGNORED

    
new Float:fOrigin[3], Float:fVicOrigin[3], Float:distance
    pev
(g_PlayerIDpev_originfVicOrigin//it is single player so g_PlayerID = id on spawn
    
pev(entpev_originfOrigin)

    
distance get_distance_f(fOriginfVicOrigin)    
    new 
bRunning get_xvar_num(g_pRunning)

    if(
distance 270.0 && !is_wall_between_points(fOriginfVicOrigin0))
    {
        if(
bRunning)
        {
            
client_print(g_PlayerIDprint_center"Detected")
            
set_pev(entpev_iuser1STATE_ATTACK)
        }
        else 
        {
            if(
fm_is_in_viewcone(entfVicOrigin))
            {
                
client_print(g_PlayerIDprint_center"Detected")
                
set_pev(entpev_iuser1STATE_ATTACK)
            }
            else 
            {
                
client_print(g_PlayerIDprint_center"Stand by...")    
            }
        }
    }    
    
//else
    //    client_print(g_PlayerID, print_center, "Stand by...")        
        
set_pev(entpev_nextthinkget_gametime()+1.0)
    }
}

stock is_wall_between_points(Float:start[3], Float:end[3], ignore_ent)
{
    static 
ptr
    ptr 
create_tr2()

    
engfunc(EngFunc_TraceLinestartendIGNORE_MONSTERSignore_entptr)
    
    static 
Float:EndPos[3]
    
get_tr2(ptrTR_vecEndPosEndPos)

    
free_tr2(ptr)
    return 
floatround(get_distance_f(endEndPos))


I want to make it only detect when player go in eye sight of it or running close to it.

+ARUKARI- 07-03-2020 03:41

Re: in_view_cone of entity
 
How about using fm_is_visible?

Celena Luna 07-03-2020 04:13

Re: in_view_cone of entity
 
Quote:

Originally Posted by +ARUKARI- (Post 2708353)
How about using fm_is_visible?

Also didn't work
I did change V_Angle => ViewOffset to test it. (I get my ViewOffset data to set for NPC, not just change V_Angle to ViewOffset)

Bugsy 07-03-2020 11:45

Re: in_view_cone of entity
 
in_view_cone() + visible check should be enough.

Have you confirmed the correct 2 player variables are used to get the origins?

Natsheh 07-03-2020 11:58

Re: in_view_cone of entity
 
TIP : when you're using is_wall_between_points in zombie think set the third Param the zombie entity index to ignore the zombie otherwise it might give you always false results. Since also when you're creating the zombie you dont give him the monster flag.

Celena Luna 07-03-2020 12:23

Re: in_view_cone of entity
 
Quote:

Originally Posted by Bugsy (Post 2708413)
in_view_cone() + visible check should be enough.

Have you confirmed the correct 2 player variables are used to get the origins?

i used this to get data
PHP Code:

public clcmd_origin(id)
{
    static 
Float:fOrigin[3], Float:fAngle[3], iEyeOrigin[3]
    
get_user_origin(idiEyeOriginOrigin_Eyes)
    
pev(idpev_originfOrigin)
    
pev(idpev_anglesfAngle)
    
server_print("Eye Origin: %i.0, %i.0, %i.0"iEyeOrigin[0], iEyeOrigin[1], iEyeOrigin[2])
    
server_print("Origin: %0.1f, %0.1f, %0.1f"fOrigin[0], fOrigin[1], fOrigin[2])
    
server_print("Angle: %0.1f, %0.1f, %0.1f"fAngle[0], fAngle[1], fAngle[2])

    
pev(idpev_view_ofsfAngle)    
    
server_print("View Offset: %0.1f, %0.1f, %0.1f"fAngle[0], fAngle[1], fAngle[2])

    
pev(idpev_v_anglefAngle)    
    
server_print("View Angle: %0.1f, %0.1f, %0.1f"fAngle[0], fAngle[1], fAngle[2])

    
client_print(idprint_chat"[Console] Origin Saved. Check Console")


and get this result
Code:

Eye Origin: 1698.0, 2137.0, -1907.0
Origin: 1698.7, 2137.0, -1924.9
Angle: -0.5, -92.8, 0.0
View Offset: 0.0, 0.0, 17.0
View Offset: 1.6, -92.8, 0.00

and the data I got at that position that I want to use is
PHP Code:

new const Float:NPC_Origin[][3] = 
{
    {
1707.02154.0, -1924.9}

}

new const 
Float:NPC_Angle[][3] =
{
    {-
2.3, -89.00.0}
}

new const 
Float:NPC_VAngle[][3] =
{
    {
1.6, -92.80.0}
}

new const 
Float:NPC_ViewOfs[][3] =
{
    {
0.00.017.0}


PHP Code:

public Spawn_NPC(id)
{
    ...

    
set_pev(entpev_anglesNPC_Angle[0])
    
set_pev(entpev_view_ofsNPC_VAngle[0])
    
set_pev(entpev_v_angleNPC_ViewOfs[0])

    ...
}

public 
Zombie_Think(ent)
{
    ....

    
pev(g_PlayerIDpev_originfVicOrigin)
    
pev(entpev_originfOrigin)
    
    if(
bRunning)
    {
        if(
distance 270.0)
            
set_pev(entpev_iuser1STATE_ATTACK)
    }
    else 
    {
        if(
fm_is_visible(entfVicOrigin) && fm_is_in_viewcone(entfVicOrigin) && !is_wall_between_points(fOriginfVicOrigin0))
            
client_print(0print_center"Detected")
    }

    ...    


I tried but it still didn't work didn't work. I walk in front of it, nothing happened
is_wall_between_points work normally because of my previous code, it did not dectect when I behind object.

Quote:

Originally Posted by Natsheh (Post 2708417)
TIP : when you're using is_wall_between_points in zombie think set the third Param the zombie entity index to ignore the zombie otherwise it might give you always false results. Since also when you're creating the zombie you dont give him the monster flag.

The zombie I used have flags FL_MONSTER and FL_MONSTERCLIP so I think I should put it as 0 (I updated it later on, adding those flags)

Bugsy 07-03-2020 12:27

Re: in_view_cone of entity
 
Is bRunning definitely false?
g_PlayerID and ent are the correct player ID's?

Did you identify which of fm_is_visible(), fm_is_in_viewcone, and is_wall_between_points() is not working as expected?

Celena Luna 07-03-2020 12:33

Re: in_view_cone of entity
 
Quote:

Originally Posted by Bugsy (Post 2708423)
Is bRunning definitely false?
g_PlayerID and ent are the correct player ID's?

Did you identify which of fm_is_visible(), fm_is_in_viewcone, and is_wall_between_points() is not working as expected?

because it is like single player mode so I just store it in g_PlayerID so it easier to use. I get the id from ham spawn post and tried at other part, it work normally so I don't think it is the reason

bRunning was false at that time, when I run, the zombie did change state and chase. So it is nothing wrong with bRunning

is_wall_between_points work normally because of my previous code, it did not dectect when I behind object.

both fm_is_visble and fm_is_in_viewcone didn't work when I tested it previously. Either separated and together

Bugsy 07-03-2020 12:42

Re: in_view_cone of entity
 
Try something like this to identify specifically what is not returning as expected
Code:
public Zombie_Think(ent) {     ....     pev(g_PlayerID, pev_origin, fVicOrigin)     pev(ent, pev_origin, fOrigin)         new szName[ 32 ]     get_user_name( g_PlayerID , szName , charsmax( szName ) );     server_print( "Is running? %d" , bRunning )     server_print( "Is %s visible to ent %d? %d" , szName , ent , fm_is_visible(ent, fVicOrigin) )     server_print( "Is %s in ent %d's viewcone? %d" , szName , ent , fm_is_in_viewcone(ent, fVicOrigin) )     server_print( "Is wall between ent %d origin and %s? %d" , ent , szName , is_wall_between_points(fOrigin, fVicOrigin, 0) )     server_print( "" )         if(bRunning)     {         if(distance < 270.0)             set_pev(ent, pev_iuser1, STATE_ATTACK)     }     else     {         if(fm_is_visible(ent, fVicOrigin) && fm_is_in_viewcone(ent, fVicOrigin) && !is_wall_between_points(fOrigin, fVicOrigin, 0))             client_print(0, print_center, "Detected")     }     ...     }

Celena Luna 07-03-2020 12:52

Re: in_view_cone of entity
 
https://i.imgur.com/vRiNccs.png

Code:

Is running? 0
Is Celena Luna visible to ent 563? 0
Is Celena Luna in ent 563's viewcone? 0
Is wall between ent 563 origin and Celena Luna? 0

https://i.imgur.com/lYtRkqX.png
Code:

Is running? 0
Is Celena Luna visible to ent 563? 0
Is Celena Luna in ent 563's viewcone? 0
Is wall between ent 563 origin and Celena Luna? 0

https://i.imgur.com/Epub2mo.png
Code:

Is running? 0
Is Celena Luna visible to ent 563? 0
Is Celena Luna in ent 563's viewcone? 0
Is wall between ent 563 origin and Celena Luna? 119

The last one I just try for fun but it is work... so weird

https://i.imgur.com/P7EBFkh.png
Code:

Is running? 0
Is Celena Luna visible to ent 563? 1
Is Celena Luna in ent 563's viewcone? 0
Is wall between ent 563 origin and Celena Luna? 0

Sorry if the image is too dark

Edit:
For running function testing:
https://i.imgur.com/jw7rzew.png
Code:

Is running? 1
Is Celena Luna visible to ent 563? 0
Is Celena Luna in ent 563's viewcone? 0
Is wall between ent 563 origin and Celena Luna? 0



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

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