Raised This Month: $ Target: $400
 0% 

Solved in_view_cone of entity


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 


Thread Tools
Display Modes

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 17:12.


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