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

is_user_visible


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 03-23-2014 , 06:20   is_user_visible
Reply With Quote #1

Code:
stock bool:is_user_visible ( const host, const who )
{
        static tr, Float:fFraction, Float:fPosHost[3], Float:fOfsHost[3],
        Float:fPosWho[3], Float:fOfsWho[3]
        
        pev ( host, pev_origin, fPosHost )
        pev ( host, pev_view_ofs, fOfsHost )
        fPosHost[0] += fOfsHost[0]
        fPosHost[1] += fOfsHost[1]
        fPosHost[2] += fOfsHost[2]
        
        pev ( who, pev_origin, fPosWho )
        pev ( who, pev_view_ofs, fOfsWho )
        fOfsWho[0] += fPosWho[0]
        fOfsWho[1] += fPosWho[1]
        fOfsWho[2] += fPosWho[2] + 12
        
        engfunc ( EngFunc_TraceLine, fPosHost, fOfsWho, IGNORE_GLASS | IGNORE_MONSTERS, host, tr )
        get_tr2 ( tr, TR_flFraction, fFraction )
        
        if ( fFraction == 1.0 )
                return true

        static Float:fVecRightHost[3], Float:fVecRightSrcHost[3]
        global_get ( glb_v_right, fVecRightHost ) // Правее!
        fVecRightHost[0] *= 18
        fVecRightHost[1] *= 18
        fVecRightHost[2] *= 18
        
        fVecRightSrcHost[0] = fPosWho[0] + fVecRightHost[0]
        fVecRightSrcHost[1] = fPosWho[1] + fVecRightHost[1]
        fVecRightSrcHost[2] = fPosWho[2] + fVecRightHost[2]
        
        //DrawLaser ( fPosHost, fVecRightSrcHost, { 0, 255, 0 } )
        
        engfunc ( EngFunc_TraceLine, fPosHost, fVecRightSrcHost, IGNORE_GLASS | IGNORE_MONSTERS, host, tr )
        get_tr2 ( tr, TR_flFraction, fFraction )
        
        if ( fFraction == 1.0 ) // Нет преград между игроками
                return true
        //---------------------------------------
        static Float:fVecLeftSrcHost[3]
        fVecLeftSrcHost[0] = fPosWho[0] - fVecRightHost[0]
        fVecLeftSrcHost[1] = fPosWho[1] - fVecRightHost[1]
        fVecLeftSrcHost[2] = fPosWho[2] - fVecRightHost[2]
        

        engfunc ( EngFunc_TraceLine, fPosHost, fVecLeftSrcHost, IGNORE_GLASS | IGNORE_MONSTERS, host, tr )
        get_tr2 ( tr, TR_flFraction, fFraction )
        
        if ( fFraction == 1.0 ) 
                return true

        return false
}
Does anyone has this stock for module? Or can any one me give some details how to create this in module? I don't know what i have to include. I want to use it in AddToFullPack, to check if one player sees the other player.

Last edited by OvidiuS; 03-23-2014 at 06:21.
OvidiuS is offline
Send a message via Skype™ to OvidiuS
Rirre
Veteran Member
Join Date: Nov 2006
Old 03-23-2014 , 10:05   Re: is_user_visible
Reply With Quote #2

Code:
bool FVisible(edict_t *pEdict, edict_t *pLooker);
PHP Code:
//=========================================================
// FVisible - returns true if a line can be traced from
// the caller's eyes to the target
//=========================================================
bool FVisible edict_t *pEntityedict_t *pLooker )
{
    
TraceResult tr;
    
Vector        vecLookerOrigin;
    
Vector        vecTargetOrigin;
    
    if (
FBitSetpEntity->pev->flagsFL_NOTARGET ))
        return 
FALSE;

    
// don't look through water
    
if ((pLooker->pev->waterlevel != && pEntity->pev->waterlevel == 3
        || (
pLooker->pev->waterlevel == && pEntity->pev->waterlevel == 0))
        return 
FALSE;

    
vecLookerOrigin pLooker->pev->origin pLooker->pev->view_ofs;//look through the caller's 'eyes'
    
vecTargetOrigin pEntity->pev->origin pEntity->pev->view_ofs;

    
UTIL_TraceLine(vecLookerOriginvecTargetOriginignore_monstersignore_glasspLooker, &tr);
    
    if (
tr.flFraction != 1.0)
    {
        return 
FALSE;// Line of sight is not established
    
}
    else
    {
        return 
TRUE;// line of sight is valid.
    
}


Last edited by Rirre; 03-23-2014 at 10:08.
Rirre is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 03-23-2014 , 13:15   Re: is_user_visible
Reply With Quote #3

I suggest using functions from virtual table.
It means like below.

PHP Code:
    /**
     * Description:        Unsure, I assume it is whether or not the other entity is visible to this entity.
     * Forward params:    function(this, idOther);
     * Return type:        Integer (boolean).
     * Execute params:    ExecuteHam(Ham_FVisible, this, idOther);
     */
    
Ham_FVisible 
Here's your pawn coded function converted for C++.

PHP Code:
char is_user_visible edict_t hostedict_t  who )
{
        static 
TraceResult tr; static float fFraction 0.0f; static Vector fPosHostfOfsHost,
        
fPosWhofOfsWho;
        
        
//pev ( host, pev_origin, fPosHost )
        //pev ( host, pev_view_ofs, fOfsHost )
        //fPosHost[0] += fOfsHost[0]
        //fPosHost[1] += fOfsHost[1]
        //fPosHost[2] += fOfsHost[2]
        
fPosHost=host->v.originfOfsHost=host->v.view_ofsfPosHost+=fOfsHost;

        
//pev ( who, pev_origin, fPosWho )
        //pev ( who, pev_view_ofs, fOfsWho )
        //fOfsWho[0] += fPosWho[0]
        //fOfsWho[1] += fPosWho[1]
        //fOfsWho[2] += fPosWho[2] + 12
        
fPosWho=who->v.origin,fOfsWho=who->v.view_ofs,fOfsWho+=fPosWho,fOfsWho.z+=12.0f;

        
//engfunc ( EngFunc_TraceLine, fPosHost, fOfsWho, IGNORE_GLASS | IGNORE_MONSTERS, host, tr )
        //get_tr2 ( tr, TR_flFraction, fFraction )
        
TRACE_LINE(fPosHost,fOfsWho,ignore_glass|ignore_monsters,host,&tr);fFraction=tr.flFraction;

        if ( 
fFraction == 1.0f )
                return (
char)1;

        static 
Vector fVecRightHostfVecRightSrcHost;
 
//       global_get ( glb_v_right, fVecRightHost ) // Правее!
  //      fVecRightHost[0] *= 18
  //      fVecRightHost[1] *= 18
   //     fVecRightHost[2] *= 18
        
    //    fVecRightSrcHost[0] = fPosWho[0] + fVecRightHost[0]
  //      fVecRightSrcHost[1] = fPosWho[1] + fVecRightHost[1]
  //      fVecRightSrcHost[2] = fPosWho[2] + fVecRightHost[2]
        

fVecRightHost=gpGlobals->v_right;   fVecRightHost*=18.0ffVecRightSrcHost=fPosWho+fVecRightHost;


        
//DrawLaser ( fPosHost, fVecRightSrcHost, { 0, 255, 0 } )
        
//        engfunc ( EngFunc_TraceLine, fPosHost, fVecRightSrcHost, IGNORE_GLASS | IGNORE_MONSTERS, host, tr )
//        get_tr2 ( tr, TR_flFraction, fFraction )
        

TRACE_LINE(fPosHost,fVecRightSrcHost,ignore_glass|ignore_monsters,host,&tr);
fFraction=tr.flFraction;



        if ( 
fFraction == 1.0f // Нет преград между игроками
                
return (char)1;
        
//---------------------------------------
        
static Vector fVecLeftSrcHost;
///        fVecLeftSrcHost[0] = fPosWho[0] - fVecRightHost[0]
 ///       fVecLeftSrcHost[1] = fPosWho[1] - fVecRightHost[1]
 ///       fVecLeftSrcHost[2] = fPosWho[2] - fVecRightHost[2]
        
fVecLeftSrcHost fPosWho fVecRightHost;
   
///     engfunc ( EngFunc_TraceLine, fPosHost, fVecLeftSrcHost, IGNORE_GLASS | IGNORE_MONSTERS, host, tr )
   ///     get_tr2 ( tr, TR_flFraction, fFraction )
        
TRACE_LINE(fPosHost,fVecLeftSrcHost,ignore_glass|ignore_monsters,host,&tr);
fFraction=tr.flFraction;


        if ( 
fFraction == 1.0f 
                return (
char)1;

        return 
char(0);

__________________

Last edited by claudiuhks; 03-23-2014 at 14:00.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 03-23-2014 , 13:21   Re: is_user_visible
Reply With Quote #4


Maybe
Code:
 vecLookerOrigin = = pLooker->v.origin + Looker->v.view_ofs;
Anyway thank you for function

EDIT:
@claudiuhks thanks for help. I'm still new to this, is there any tutorial how to use functions from virtual table?

Last edited by OvidiuS; 03-24-2014 at 03:09.
OvidiuS is offline
Send a message via Skype™ to OvidiuS
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 03:09.


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