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

Check if player can see respawn / buying zone


Post New Thread Reply   
 
Thread Tools Display Modes
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-04-2023 , 16:46   Re: Check if player can see respawn / buying zone
Reply With Quote #11

I can give you a more proper way just give me a bit time.


Here's the First Part of creating the zone.

PHP Code:
function(id)
{
    new 
Float:flMaxBS[3], Float:flMinBS[3], Float:fOrigin[3];
    
pev(idpev_originfOrigin);
    
CreateBoundingBoxAroundEntities("info_player_start"flMaxBSflMinBS);
    
SCAN_Zone_Visuality(fOriginflMaxBSflMinBS);
}

CreateBoundingBoxAroundEntities(const szEntClassName[32], Float:flMaxBS[3], Float:flMinBS[3])
{
    new 
ent = -1Float:fEntMaxBS[3], Float:fEntMinBS[3];
    
// find the max/mins coords of the zone.
    
while( (ent find_ent_by_class(entszEntClassName)) > 0)
    {
        
pev(entpev_absmaxfEntMaxBS);
        
pev(entpev_absminfEntMinBS);

        
flMaxBS[0] = floatmax(fEntMaxBS[0], flMaxBS[0]);
        
flMaxBS[1] = floatmax(fEntMaxBS[1], flMaxBS[1]);
        
flMaxBS[2] = floatmax(fEntMaxBS[2], flMaxBS[2]);

        
flMinBS[0] = floatmin(fEntMinBS[0], flMinBS[0]);
        
flMinBS[1] = floatmin(fEntMinBS[1], flMinBS[1]);
        
flMinBS[2] = floatmin(fEntMinBS[2], flMinBS[2]);
    }

    return 
0;


Here's the second part...

PHP Code:
SCAN_Zone_Visuality(const Float:fvPOVOrigin[3], const Float:fMaxBS[3], const Float:fMinBS[3])
{
    new 
Float:fvPOVAngle[3], Float:fAngle[3], Float:fVector[3], Float:fMidPoint[3], Float:fLenFloat:flFractioniTr2 create_tr2();
    
xs_vec_sub(fMaxBSfMinBSfMidPoint);
    
xs_vec_mul_scalar(fMidPoint0.5fMidPoint);
    
xs_vec_sub(fMidPointfvPOVOriginfVector);
    
xs_vec_normalize(fVectorfVector);
    
vector_to_angle(fVectorfvPOVAngle);

    new 
Float:fDistance get_distance_f(fvPOVOriginfMidPoint);

    for(new 
Float:fXShift 60.0Float:fYShiftfXShift >= -60.0fXShift += -1.0)
    {
        
xs_vec_copy(fvPOVAnglefAngle);
        
fAngle[0] += fXShift;

        for(
fYShift 60.0fYShift >= -60.0fYShift += -1.0)
        {
            
fAngle[1] += fYShift;

            
angle_vector(fAngleANGLEVECTOR_FORWARDfVector);
            
fLen fDistance floatmaxfloatcosxs_vec_angle(fMidPointfVector), degrees ), 1.0 );
            
xs_vec_mul_scalar(fVectorfLenfVector);
            
xs_vec_add(fvPOVOriginfVectorfVector);

            
engfunc(EngFunc_TraceLinefvPOVOriginfVectorIGNORE_MONSTERS|IGNORE_GLASS|IGNORE_GLASS0iTr2);

            
get_tr2(iTr2TR_FractionflFraction);

            if(
flFraction >= 0.90)
            {
                
free_tr2(iTr2);
                return 
1;
            }
        }
    }

    
free_tr2(iTr2);
    return 
0;

Here the function do a scan unit by unit and the function will return 1 when there's a potential view of the zone!
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 01-04-2023 at 19:19.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
sebxx4
Senior Member
Join Date: Feb 2013
Old 01-05-2023 , 01:50   Re: Check if player can see respawn / buying zone
Reply With Quote #12

Thank you, I'll try both.
Btw, will it check both buying zones?

Last edited by sebxx4; 01-05-2023 at 02:06.
sebxx4 is offline
artist
Member
Join Date: Nov 2013
Old 01-05-2023 , 03:00   Re: Check if player can see respawn / buying zone
Reply With Quote #13

To begin with, it is worth understanding that a traceline can only be drawn to a certain point.

You can get the coordinates of all points at the start and draw lines to them in a cycle.

Here is a plugin that displays all points.

PHP Code:
#include <amxmodx>
#include <fakemeta>
 
new hook_ent_spawn
new Float:ct_origin[32][3], ct_num
new Float:t_origin[32][3], t_num
new sprite
 
public plugin_init()
{
        
register_clcmd("say /""create")
        
unregister_forward(FM_Spawnhook_ent_spawn)
}
public 
plugin_precache()
{
        
hook_ent_spawn register_forward(FM_Spawn"ent_spawn")
        
sprite precache_model("sprites/laserbeam.spr")
}
public 
ent_spawn(ent)
{
        if(!
pev_valid(ent)) return FMRES_IGNORED
        
        
static classname[33]; pev(entpev_classnameclassnamecharsmax(classname))
        
        if(
equal(classname"info_player_start") && ct_num sizeof(ct_origin))
        {
                
pev(entpev_originct_origin[ct_num++])
                
server_print("entid %i %s %i"entclassnamect_num)
        }
        else if(
equal(classname"info_player_deathmatch") && t_num sizeof(t_origin))
        {
                
pev(entpev_origint_origin[t_num++])
                
server_print("entid %i %s %i"entclassnamet_num)
        }
        return 
FMRES_IGNORED
}
public 
create(id)
{
        for(new 
0ct_numa++) create_line(ct_origin[a], 1)
        for(new 
0t_numb++) create_line(t_origin[b], 0)
        
client_print(idprint_chat"spawn t = %i"t_num)
        
client_print(idprint_chat"spawn ct = %i"ct_num)
}
public 
create_line(Float:orign[3], color)
{
        
message_begin(MSG_BROADCASTSVC_TEMPENTITY)
        
write_byte(TE_BEAMPOINTS)
        
engfunc(EngFunc_WriteCoordorign[0])   //Стартовая точка x
        
engfunc(EngFunc_WriteCoordorign[1])   //Стартовая точка y
        
engfunc(EngFunc_WriteCoordorign[2]+20)//Стартовая точка z
        
engfunc(EngFunc_WriteCoordorign[0])   //Конечная точка x
        
engfunc(EngFunc_WriteCoordorign[1])   //Конечная точка y
        
engfunc(EngFunc_WriteCoordorign[2]-40)//Конечная точка z
        
write_short(sprite)                     //Индекс спрайта
        
write_byte(0)                           //Стартовый кадр
        
write_byte(1)                           //Скорость анимации
        
write_byte(0)                           //Время существования
        
write_byte(10)                          //Толщина луча
        
write_byte(0)                           //Искажение
        
if(color)
        {
                
write_byte(0)                   //Цвет красный
                
write_byte(0)                   //Цвет зелёный
                
write_byte(255)                 //Цвет синий
        
}
        else
        {
                
write_byte(255)                 //Цвет красный
                
write_byte(0)                   //Цвет зелёный
                
write_byte(0)                   //Цвет синий
        
}
        
write_byte(255)                         //Яркость
        
write_byte(0)                           //Флаг
        
message_end()

artist is offline
sebxx4
Senior Member
Join Date: Feb 2013
Old 01-05-2023 , 05:22   Re: Check if player can see respawn / buying zone
Reply With Quote #14

For now I tried Natsheh's plugin, but it seems to work wierd :/

https://www.youtube.com/watch?v=tK3_nPU4se0

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <engine>
#include <xs>

#define PLUGIN "test"
#define VERSION "1.0"
#define AUTHOR "sebxx"

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
register_clcmd("say /test""check_bzs");
}

public 
check_bzs(id)
{
    new 
Float:flMaxBS[3], Float:flMinBS[3], Float:fOrigin[3];
    
pev(idpev_originfOrigin);
    
CreateBoundingBoxAroundEntities("info_player_start"flMaxBSflMinBS);

    if ( 
SCAN_Zone_Visuality(fOriginflMaxBSflMinBS) )
        
client_print(idprint_center"I see buying zone!");
    else
        
client_print(idprint_center"I don't see buying zone!");
}

public 
CreateBoundingBoxAroundEntities(const szEntClassName[32], Float:flMaxBS[3], Float:flMinBS[3])
{
    new 
ent = -1Float:fEntMaxBS[3], Float:fEntMinBS[3];
    
// find the max/mins coords of the zone.
    
while( (ent find_ent_by_class(entszEntClassName)) > 0)
    {
        
pev(entpev_absmaxfEntMaxBS);
        
pev(entpev_absminfEntMinBS);

        
flMaxBS[0] = floatmax(fEntMaxBS[0], flMaxBS[0]);
        
flMaxBS[1] = floatmax(fEntMaxBS[1], flMaxBS[1]);
        
flMaxBS[2] = floatmax(fEntMaxBS[2], flMaxBS[2]);

        
flMinBS[0] = floatmin(fEntMinBS[0], flMinBS[0]);
        
flMinBS[1] = floatmin(fEntMinBS[1], flMinBS[1]);
        
flMinBS[2] = floatmin(fEntMinBS[2], flMinBS[2]);
    }

    return 
0;


public 
SCAN_Zone_Visuality(const Float:fvPOVOrigin[3], const Float:fMaxBS[3], const Float:fMinBS[3])
{
    new 
Float:fvPOVAngle[3], Float:fAngle[3], Float:fVector[3], Float:fMidPoint[3], Float:fLenFloat:flFractioniTr2 create_tr2();
    
xs_vec_sub(fMaxBSfMinBSfMidPoint);
    
xs_vec_mul_scalar(fMidPoint0.5fMidPoint);
    
xs_vec_sub(fMidPointfvPOVOriginfVector);
    
xs_vec_normalize(fVectorfVector);
    
vector_to_angle(fVectorfvPOVAngle);

    new 
Float:fDistance get_distance_f(fvPOVOriginfMidPoint);

    for(new 
Float:fXShift 60.0Float:fYShiftfXShift >= -60.0fXShift += -1.0)
    {
        
xs_vec_copy(fvPOVAnglefAngle);
        
fAngle[0] += fXShift;

        for(
fYShift 60.0fYShift >= -60.0fYShift += -1.0)
        {
            
fAngle[1] += fYShift;

            
angle_vector(fAngleANGLEVECTOR_FORWARDfVector);
            
fLen fDistance floatmaxfloatcosxs_vec_angle(fMidPointfVector), degrees ), 1.0 );
            
xs_vec_mul_scalar(fVectorfLenfVector);
            
xs_vec_add(fvPOVOriginfVectorfVector);

            
engfunc(EngFunc_TraceLinefvPOVOriginfVectorIGNORE_MONSTERS|IGNORE_GLASS|IGNORE_GLASS0iTr2);

            
get_tr2(iTr2TR_FractionflFraction);

            if(
flFraction >= 0.90)
            {
                
free_tr2(iTr2);
                return 
1;
            }
        }
    }

    
free_tr2(iTr2);

    return 
0;

sebxx4 is offline
sebxx4
Senior Member
Join Date: Feb 2013
Old 01-05-2023 , 06:05   Re: Check if player can see respawn / buying zone
Reply With Quote #15

I also tried to merge artist's and Bugsy's code. The first one looks for spawn spots, and the second one check trace. But it shows all the time like there are no obstacles on the way from player to any spawn spot (displays "I see respawn!").

PHP Code:
#include <amxmodx>
#include <fakemeta>
 
new hook_ent_spawn;
new 
Float:ct_origin[32][3], ct_num;
new 
Float:t_origin[32][3], t_num;
 
public 
plugin_init()
{
    
register_clcmd("say /test""check_respzone");
    
unregister_forward(FM_Spawnhook_ent_spawn);
}

public 
plugin_precache()
    
hook_ent_spawn register_forward(FM_Spawn"ent_spawn");

public 
ent_spawn(ent)
{
    if( !
pev_valid(ent) ) 
        return 
FMRES_IGNORED;
        
    static 
classname[33];

    
pev(entpev_classnameclassnamecharsmax(classname));
        
    if ( 
equal(classname"info_player_start") && ct_num sizeof(ct_origin) )
        
pev(entpev_originct_origin[ct_num++]);
    else if ( 
equal(classname"info_player_deathmatch") && t_num sizeof(t_origin) )
        
pev(entpev_origint_origin[t_num++]);

    return 
FMRES_IGNORED;
}

public 
check_respzone(id)
{
    new 
bool:block false;
    new 
Float:player_origin[3];

    
pev(idpev_originplayer_origin);

    for ( new 
0ct_numa++ )
    {
        new 
tlTraceFloat:fFraction;

        
engfunc(EngFunc_TraceLineplayer_originct_origin[a], IGNORE_MONSTERS0tlTrace);
        
get_tr2(tlTraceTR_flFractionfFraction);
        
        if ( 
fFraction != 1.0 )
        {
            
block true;
            break;
        }
    }

    if ( !
block )
    {
        for ( new 
0t_numb++ ) 
        {
            new 
tlTraceFloat:fFraction;
            
            
engfunc(EngFunc_TraceLineplayer_origint_origin[b], IGNORE_MONSTERS0tlTrace);
            
get_tr2(tlTraceTR_flFractionfFraction);
            
            if ( 
fFraction != 1.0 )
            {
                
block true;
                break;
            }
        }
    }

    if ( 
block )
        
client_print(idprint_center"I see respawn!");
    else
        
client_print(idprint_center"I dont see respawn!");


Last edited by sebxx4; 01-05-2023 at 06:05.
sebxx4 is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-05-2023 , 06:14   Re: Check if player can see respawn / buying zone
Reply With Quote #16

You need to add the player view ofs to the origin, the code itself needs a bit testing, also you need to change the check where checking if the fraction greater than 90% to check if the point Vector is between the Zone boundaries.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-05-2023 , 06:22   Re: Check if player can see respawn / buying zone
Reply With Quote #17

Quote:
Originally Posted by sebxx4 View Post
Thank you, I'll try both.
Btw, will it check both buying zones?
No it will check only CT spawn AKA ( info_player_start )


T Spawn is info_player_deathmatch
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
sebxx4
Senior Member
Join Date: Feb 2013
Old 01-05-2023 , 06:58   Re: Check if player can see respawn / buying zone
Reply With Quote #18

Quote:
Originally Posted by Natsheh View Post
you need to change the check where checking if the fraction greater than 90%
Thanks, now it seems to work fine

Last edited by sebxx4; 01-05-2023 at 07:01.
sebxx4 is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-05-2023 , 08:21   Re: Check if player can see respawn / buying zone
Reply With Quote #19

Quote:
Originally Posted by sebxx4 View Post
Thanks, now it seems to work fine
There it should work better here...

Spoiler
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 01-05-2023 at 08:56.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
sebxx4
Senior Member
Join Date: Feb 2013
Old 01-05-2023 , 09:44   Re: Check if player can see respawn / buying zone
Reply With Quote #20

Thanks, I'll give it a try
sebxx4 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 12:05.


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