AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Get origin in player's viewcone? (https://forums.alliedmods.net/showthread.php?t=319890)

redivcram 11-25-2019 10:33

Get origin in player's viewcone?
 
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.

JocAnis 11-25-2019 12:27

Re: Get origin in player's viewcone?
 
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)

redivcram 11-25-2019 13:36

Re: Get origin in player's viewcone?
 
Quote:

Originally Posted by JocAnis (Post 2674441)
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...

Bugsy 11-25-2019 18:13

Re: Get origin in player's viewcone?
 
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");



redivcram 11-25-2019 19:01

Re: Get origin in player's viewcone?
 
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.

Bugsy 11-25-2019 19:13

Re: Get origin in player's viewcone?
 
Do a server print of the entity's origin after this...classic debugging.

pev(TestSprite, pev_origin, fTestOrigin);

redivcram 11-25-2019 20:18

Re: Get origin in player's viewcone?
 
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 11-26-2019 11:52

Re: Get origin in player's viewcone?
 
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.


All times are GMT -4. The time now is 02:57.

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