Raised This Month: $51 Target: $400
 12% 

Solved in_view_cone of entity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 07-03-2020 , 03:32   in_view_cone of entity
Reply With Quote #1

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.
__________________
My plugin:

Last edited by Celena Luna; 07-03-2020 at 14:02. Reason: solved
Celena Luna is offline
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 07-03-2020 , 03:41   Re: in_view_cone of entity
Reply With Quote #2

How about using fm_is_visible?
__________________
GitHub
SteamWishlist

六四天安門事件
+ARUKARI- is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 07-03-2020 , 04:13   Re: in_view_cone of entity
Reply With Quote #3

Quote:
Originally Posted by +ARUKARI- View Post
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)
__________________
My plugin:

Last edited by Celena Luna; 07-03-2020 at 04:14.
Celena Luna is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-03-2020 , 11:45   Re: in_view_cone of entity
Reply With Quote #4

in_view_cone() + visible check should be enough.

Have you confirmed the correct 2 player variables are used to get the origins?
__________________
Bugsy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 07-03-2020 , 11:58   Re: in_view_cone of entity
Reply With Quote #5

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.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 07-03-2020 at 11:59.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 07-03-2020 , 12:23   Re: in_view_cone of entity
Reply With Quote #6

Quote:
Originally Posted by Bugsy View Post
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 View Post
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)
__________________
My plugin:

Last edited by Celena Luna; 07-03-2020 at 12:28.
Celena Luna is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-03-2020 , 12:27   Re: in_view_cone of entity
Reply With Quote #7

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?
__________________

Last edited by Bugsy; 07-03-2020 at 12:27.
Bugsy is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 07-03-2020 , 12:33   Re: in_view_cone of entity
Reply With Quote #8

Quote:
Originally Posted by Bugsy View Post
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
__________________
My plugin:

Last edited by Celena Luna; 07-03-2020 at 12:35.
Celena Luna is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-03-2020 , 12:42   Re: in_view_cone of entity
Reply With Quote #9

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")     }     ...    }
__________________

Last edited by Bugsy; 07-03-2020 at 12:43.
Bugsy is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 07-03-2020 , 12:52   Re: in_view_cone of entity
Reply With Quote #10



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

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

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


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:

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
__________________
My plugin:

Last edited by Celena Luna; 07-03-2020 at 12:55.
Celena Luna 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 06:48.


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