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

Get origin in player's viewcone?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 11-25-2019 , 10:33   Get origin in player's viewcone?
Reply With Quote #1

I've made a test map, added one env_sprite entity and named it "sprite_test". This plugin is supposed to spam a chat message to each player only if the entity('s origin) is inside the players' 3D viewcone. However, it does not.

PHP Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <hamsandwich>

new Float:fTestOrigin[3];

public 
plugin_init()
{
    
register_plugin("Viewcone Test""1.0""ridavcrum");

    
RegisterHam(Ham_Think"player""HamPlayerThink");
    
    new 
TestSprite find_ent_by_target(-1"sprite_test");
    
pev(TestSpritepev_originfTestOrigin);
}

public 
HamPlayerThink(id)
{
    if(
is_in_viewcone(idfTestOrigin1))
        
client_print(idprint_chat"IN VIEWCONE");

What am I doing wrong here?

I've also tried replacing find_ent_by_target with find_ent_by_class with "env_sprite" as the second parameter, without any luck.
redivcram is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 11-25-2019 , 12:27   Re: Get origin in player's viewcone?
Reply With Quote #2

can you try:
Code:
is_visible( playerID, entityID )
while my testing i got correct results in 90% of the time (was bugged while in Spec)
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)

Last edited by JocAnis; 11-25-2019 at 12:28.
JocAnis is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 11-25-2019 , 13:36   Re: Get origin in player's viewcone?
Reply With Quote #3

Quote:
Originally Posted by JocAnis View Post
can you try:
Code:
is_visible( playerID, entityID )
while my testing i got correct results in 90% of the time (was bugged while in Spec)
Nothing, nothing at all. I've even swapped the ID's between the player and the env_sprite. No error logs, no nothing. Strange...
redivcram is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-25-2019 , 18:13   Re: Get origin in player's viewcone?
Reply With Quote #4

Did you confirm the entity is spawned in a place that can be in your player viewcone? Are you really searching for the entity in plugin_init()? Maybe it doesn't exist yet.

The function works, aim at a player and say "test"
PHP Code:

#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <hamsandwich>

new Float:fTestOrigin[3];

public 
plugin_init()
{
    
register_plugin("Viewcone Test""1.0""ridavcrum");

    
register_clcmd"say test" "Test" );
}

public 
Testid )
{
    new 
pID;
    
    
set_task0.1 "ViewconeTest" id , .flags="b");
    
get_user_aimingid pID );
    
pev(pIDpev_originfTestOrigin);
    
    
client_printid print_chat "Found ent at {%f, %f, %f}" fTestOrigin[0],fTestOrigin[1],fTestOrigin[2])
}

public 
ViewconeTestid )
{
    if ( 
is_in_viewconeid fTestOrigin ) )
        
client_print(idprint_chat"IN VIEWCONE");

__________________
Bugsy is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 11-25-2019 , 19:01   Re: Get origin in player's viewcone?
Reply With Quote #5

Actually, I've been playing around my code a bit and tried different methods. The entity is there. I'm getting the logs I want. For example, in my testmap, the sprite entity has an id of 38, as seen in logs.

PHP Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <hamsandwich>

new TestSprite = -1;
new 
Float:fTestOrigin[3];

public 
plugin_precache()
{
    
register_forward(FM_Spawn"FwdSpawn");
}

public 
plugin_init()
{
    
register_plugin("Viewcone Test""1.0""ridavcrum");

    
RegisterHam(Ham_Think"player""HamPlayerThink");
}

public 
FwdSpawn(ent)
{
    
log_amx("ENTITY: %d, START"ent);
    
    if(!
pev_valid(ent))
    {
        
log_amx("ENTITY: %d, INVALID"ent);
        return 
FMRES_IGNORED;
    }
    
    
log_amx("ENTITY: %d, VALID"ent);
        
    new 
ClassName[32];
    
pev(entpev_classnameClassNamecharsmax(ClassName));
    
    
log_amx("ENTITY: %d, CLASSNAME: %s"entClassName);
    
    if(
equali(ClassName"env_sprite"))
    {
        new 
TargetName[32];
        
pev(entpev_targetnameTargetNamecharsmax(TargetName));
        
        
log_amx("ENTITY: %d, TARGETNAME: %s"entTargetName);
        
        if(
equali(TargetName"sprite_test"))
        {
            
TestSprite ent;
            
            
log_amx("ENTITY: %d, END !!"ent);
            return 
FMRES_HANDLED;
        }
    }
    
    
log_amx("ENTITY: %d, END"ent);
    return 
FMRES_IGNORED;
}

public 
HamPlayerThink(id)
{
    if(
is_in_viewcone(idfTestOrigin1) || is_visible(idTestSprite))
        
client_print(idprint_chat"%s%s"is_in_viewcone(idfTestOrigin1) ? "IN_VIEWCONE" ""is_visible(idSprite) ? " | IS_VISIBLE" "");

None return true. Bleh!

Yes, I can definitely see the entity. It's in the middle of the room, basically.

Last edited by redivcram; 11-25-2019 at 19:02.
redivcram is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-25-2019 , 19:13   Re: Get origin in player's viewcone?
Reply With Quote #6

Do a server print of the entity's origin after this...classic debugging.

pev(TestSprite, pev_origin, fTestOrigin);
__________________

Last edited by Bugsy; 11-25-2019 at 19:13.
Bugsy is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 11-25-2019 , 20:18   Re: Get origin in player's viewcone?
Reply With Quote #7

Huh. Weird. The origin is kinda wrong. The entity is clearly placed at one origin while the method with the entity's origin returns an origin a bit further from the entity.
redivcram is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 11-26-2019 , 11:52   Re: Get origin in player's viewcone?
Reply With Quote #8

Blefk!

Turns out, the PlayerThink function did not work. Chose a different method of checking instead to show the output. Both is_visible and is_in_viewcone work.

Last edited by redivcram; 11-26-2019 at 11:54.
redivcram 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 16:05.


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