Raised This Month: $ Target: $400
 0% 

Is Inside


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
madeitout
Member
Join Date: Jun 2008
Old 08-18-2009 , 18:33   Is Inside
Reply With Quote #1

I am trying to get a stock that will return 1 if an ent is inside a 3d insemetrical box. I tried a few different ways including the is_inside function in the chr_engine but it doesnt seem to allow z origins. The 3d box isn't a set origin and moves around the map and has various sizes.

here is my test code I made to try and make the stock

thank you
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>

new spriteFloat:origin1[3], Float:origin2[3], Float:origin3[3], Float:origin4[3], Float:origin5[3], Float:origin6[3], Float:origin7[3], Float:origin8[3];

public 
plugin_init()
{
    
register_forward(FM_PlayerPreThink"ee")
    
register_event("ResetHUD""ff""b");
    
set_task(4.0"dd"___"b"_);
    
set_task(3.9"gg"___"b"_);
    
set_task(3.8"hh"___"b"_);
}
public 
plugin_precache()
    
sprite precache_model("sprites/lgtning.spr");
public 
ee(id)
    
client_print(idprint_center"%d"is_inside(id));

stock is_inside(id)
{
    static 
Float:origin[3];
    
pev(idpev_originorigin);
    
    if (
origin[0] == 1.0
        return 
1;

    return 
0;
}


public 
ff(id)
    
set_task(0.1"ll"id);
public 
ll(id)
{
    new 
Float:origin[3];
    
pev(idpev_originorigin);

    
origin1[0] = origin[0] - 100.0origin1[1] = origin[1] - 50.0origin1[2] = origin[2];
    
origin2[0] = origin[0] + 100.0origin2[1] = origin[1] - 50.0origin2[2] = origin[2] + 50.0;
    
origin3[0] = origin[0] - 100.0origin3[1] = origin[1] - 50.0origin3[2] = origin[2] + 100.0;
    
origin4[0] = origin[0] + 100.0origin4[1] = origin[1] - 50.0origin4[2] = origin[2] + 150.0;
    
origin5[0] = origin[0] - 050.0origin5[1] = origin[1] + 50.0origin5[2] = origin[2];
    
origin6[0] = origin[0] + 150.0origin6[1] = origin[1] + 50.0origin6[2] = origin[2] + 50.0;
    
origin7[0] = origin[0] - 050.0origin7[1] = origin[1] + 50.0origin7[2] = origin[2] + 100.0;
    
origin8[0] = origin[0] + 150.0origin8[1] = origin[1] + 50.0origin8[2] = origin[2] + 150.0;
}
public 
dd()
{
    new 
Float:temp[3], Float:temp2[3];
    for (new 
04i++)
    {
        if (
i==0temp origin1temp2 origin2;
        else if (
i==1temp origin2temp2 origin4;
        else if (
i==2temp origin3temp2 origin4;
        else 
temp origin3temp2 origin1;
        
message_begin(MSG_BROADCASTSVC_TEMPENTITY
        
write_byte(0)
        
write_coord(floatround(temp[0]))
        
write_coord(floatround(temp[1]))
        
write_coord(floatround(temp[2]))
        
write_coord(floatround(temp2[0]))
        
write_coord(floatround(temp2[1]))
        
write_coord(floatround(temp2[2]))
        
write_short(sprite)
        
write_byte(1)
        
write_byte(1)
        
write_byte(50)
        
write_byte(15)
        
write_byte(0)
        
write_byte((== 1) ? 255 0)
        
write_byte(255)
        
write_byte((== 2) ? 255 0)
        
write_byte(210)
        
write_byte(0)
        
message_end()
    }
}
public 
gg()
{
    new 
Float:temp[3], Float:temp2[3];
    for (new 
04i++)
    {
        if (
i==0temp origin5temp2 origin6;
        else if (
i==1temp origin6temp2 origin8;
        else if (
i==2temp origin7temp2 origin8;
        else 
temp origin7temp2 origin5;
        
message_begin(MSG_BROADCASTSVC_TEMPENTITY
        
write_byte(0)
        
write_coord(floatround(temp[0]))
        
write_coord(floatround(temp[1]))
        
write_coord(floatround(temp[2]))
        
write_coord(floatround(temp2[0]))
        
write_coord(floatround(temp2[1]))
        
write_coord(floatround(temp2[2]))
        
write_short(sprite)
        
write_byte(1)
        
write_byte(1)
        
write_byte(50)
        
write_byte(15)
        
write_byte(0)
        
write_byte((== 1) ? 255 0)
        
write_byte(255)
        
write_byte((== 2) ? 255 0)
        
write_byte(210)
        
write_byte(0)
        
message_end()
    }
}
public 
hh()
{
    new 
Float:temp[3], Float:temp2[3];
    for (new 
04i++)
    {
        if (
i==0temp origin1temp2 origin5;
        else if (
i==1temp origin2temp2 origin6;
        else if (
i==2temp origin3temp2 origin7;
        else 
temp origin4temp2 origin8;
        
message_begin(MSG_BROADCASTSVC_TEMPENTITY
        
write_byte(0)
        
write_coord(floatround(temp[0]))
        
write_coord(floatround(temp[1]))
        
write_coord(floatround(temp[2]))
        
write_coord(floatround(temp2[0]))
        
write_coord(floatround(temp2[1]))
        
write_coord(floatround(temp2[2]))
        
write_short(sprite)
        
write_byte(1)
        
write_byte(1)
        
write_byte(50)
        
write_byte(15)
        
write_byte(0)
        
write_byte((== 1) ? 255 0)
        
write_byte(255)
        
write_byte((== 2) ? 255 0)
        
write_byte(210)
        
write_byte(0)
        
message_end()
    }

madeitout is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-18-2009 , 18:55   Re: Is Inside
Reply With Quote #2

Code:
bool:IsEntityInsideBox( const iEntity, const Float:vBoxCenter[ 3 ], const Float:vBoxMins[ 3 ], const Float:vBoxMaxs[ 3 ] ) {     static Float:vOrigin[ 3 ];     entity_get_vector( iEntity, EV_VEC_origin, vOrigin );         static Float:vMins[ 3 ], Float:vMaxs[ 3 ];     entity_get_vector( iEntity, EV_VEC_mins, vMins );     entity_get_vector( iEntity, EV_VEC_maxs, vMaxs );         static Float:vBoxMinCorner[ 3 ], Float:vBoxMaxCorner[ 3 ];     xs_vec_add( vBoxCenter, vBoxMins, vBoxMinCorner );     xs_vec_add( vBoxCenter, vBoxMaxs, vBoxMaxCorner );         static Float:vEntityCorner[ 3 ];     for( new i = 0; i < 8; i++ )     {         xs_vec_copy( vOrigin, vEntityCorner );                 switch( i )         {             case 0:             {                 // top -- left -- front                 vEntityCorner[ 0 ] += vMins[ 0 ];                 vEntityCorner[ 1 ] += vMaxs[ 1 ];                 vEntityCorner[ 2 ] += vMaxs[ 2 ];             }             case 1:             {                 // top -- right -- front                 vEntityCorner[ 0 ] += vMaxs[ 0 ];                 vEntityCorner[ 1 ] += vMaxs[ 1 ];                 vEntityCorner[ 2 ] += vMaxs[ 2 ];             }             case 2:             {                 // top -- left -- back                 vEntityCorner[ 0 ] += vMins[ 0 ];                 vEntityCorner[ 1 ] += vMins[ 1 ];                 vEntityCorner[ 2 ] += vMaxs[ 2 ];             }             case 3:             {                 // top -- right -- front                 vEntityCorner[ 0 ] += vMaxs[ 0 ];                 vEntityCorner[ 1 ] += vMaxs[ 1 ];                 vEntityCorner[ 2 ] += vMaxs[ 2 ];             }             case 4:             {                 // bottom -- left -- front                 vEntityCorner[ 0 ] += vMins[ 0 ];                 vEntityCorner[ 1 ] += vMaxs[ 1 ];                 vEntityCorner[ 2 ] += vMins[ 2 ];             }             case 5:             {                 // bottom -- right -- front                 vEntityCorner[ 0 ] += vMaxs[ 0 ];                 vEntityCorner[ 1 ] += vMaxs[ 1 ];                 vEntityCorner[ 2 ] += vMins[ 2 ];             }             case 6:             {                 // bottom -- left -- back                 vEntityCorner[ 0 ] += vMins[ 0 ];                 vEntityCorner[ 1 ] += vMins[ 1 ];                 vEntityCorner[ 2 ] += vMins[ 2 ];             }             case 7:             {                 // bottom -- right -- front                 vEntityCorner[ 0 ] += vMaxs[ 0 ];                 vEntityCorner[ 1 ] += vMaxs[ 1 ];                 vEntityCorner[ 2 ] += vMins[ 2 ];             }         }                 if( vBoxMinCorner[ 0 ] <= vEntityCorner[ 0 ] <= vBoxMaxCorner[ 0 ]         && vBoxMinCorner[ 1 ] <= vEntityCorner[ 1 ] <= vBoxMaxCorner[ 1 ]         && vBoxMinCorner[ 2 ] <= vEntityCorner[ 2 ] <= vBoxMaxCorner[ 2 ] )         {             return true;         }     }         return false; }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Reply


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 15:15.


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