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

Above or below entity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Rirre
Veteran Member
Join Date: Nov 2006
Old 06-10-2017 , 19:47   Above or below entity
Reply With Quote #1

Since above, below or under aren't allowed to use in Search (either very common, too long, or too short), and higher wasn't helpful, I start this thread.

What I'm trying to do is to loop through every entity within a box and retrieve the two closest ones, one from the top and one from the bottom and crop the end(s) .Z/[2] of the box depending on the closest ones within the box.
Code:
Think(parm[6]) {     new id = parm[3]; // owner     new ent = parm[5]; // entity id     new origin[3], start[3], end[3];     origin[0] = parm[0];     origin[1] = parm[1];     origin[2] = parm[2];     // Set up the top     start[0] = origin[0];     start[1] = origin[1];     start[2] = origin[2] + 600;     // Set up the bottom     end[0] = origin[0];     end[1] = origin[1];     end[2] = origin[2] - 600;     new pList[32], szClassName[32], Float:flOrigin[3], Float:EntOrigin[3], Float:flCenter[3], szModel[32], Float:flClosestDistance = 4096.0, iClosestTarget = 0;     pev( ent, pev_origin, flOrigin );     // Box size     new Float:flMins[3] = { -85.0, -85.0, 0.0 };     new Float:flMaxs[3] = { 85.0, 85.0, 0.0 };     // Set up the box top and bottom with origin[2]     for( new i = 0; i < 2; i++ )     {         flMins[i] += float( origin[i] );         flMaxs[i] += float( origin[i] );     }     flMins[2] = float( end[2] );     flMaxs[2] = float( start[2] );     // Check for spawnpoints, C4 and hostages below or above and crop the box if they are within the box     new count = UTIL_EntitiesInBox( pList, sizeof(pList), flMins, flMaxs, 0 );     for( new i = 0; i < count; i++ )     {         if ( pList[i] == ent )             continue;         pev( pList[i], pev_model, szModel, charsmax( szModel ) );         pev( pList[i], pev_classname, szClassName, charsmax(szClassName) );         if ( !( equal( szClassName, "info_player_start" ) || equal( szClassName, "info_player_deathmatch" )             || equal( szClassName, "hostage_entity" )             || equal( szClassName, "grenade" ) && equal( szModel, "models/w_c4.mdl" ) ) )             continue;         BodyTarget( pList[i], flCenter );         if ( get_distance_f( flOrigin, flCenter ) < flClosestDistance )         {             iClosestTarget = pList[i];         }     }     if ( iClosestTarget )     {         pev( iClosestTarget, pev_origin, EntOrigin );         BodyTarget( iClosestTarget, flCenter );         // Below, crop the box from the center of iClosestTarget         if ( origin[2] > EntOrigin[2] )         {             end[2] = floatround( flCenter[2] ) + 72; // move up with 72 units             flMins[2] = float( end[2] );         }     }     FX_Box( flMins, flMaxs, {0.0,255.0,0.0}, 15 ); } stock BodyTarget(ent, Float:vecTarget[3]) {     static Float:flOrigin[3], Float:flAbsmin[3], Float:flAbsmax[3];     pev(ent, pev_origin, flOrigin);     pev(ent, pev_absmin, flAbsmin);     pev(ent, pev_absmax, flAbsmax);     vecTarget[0] = (flAbsmin[0] + flAbsmax[0]) * 0.5;     vecTarget[1] = (flAbsmin[1] + flAbsmax[1]) * 0.5;     vecTarget[2] = (flAbsmin[2] + flAbsmax[2]) * 0.5; } stock UTIL_EntitiesInBox( pList[], listMax, Float:mins[3], Float:maxs[3], flagMask ) {     // initialize variables     new count, Float:absmin[3], Float:absmax[3];     count = 0;     // go through all possible entities     for( new i = 1; i < get_global_int( GL_maxEntities ); i++ )     {         // not in use         if( !is_valid_ent(i) )             continue;         if( flagMask && !(pev(i, pev_flags) & flagMask) )             continue;         // get absolutes of entity         entity_get_vector( i, EV_VEC_absmin, absmin );         entity_get_vector( i, EV_VEC_absmax, absmax );         // not in bounds         if( mins[0] > absmax[0] ||             mins[1] > absmax[1] ||             mins[2] > absmax[2] ||             maxs[0] < absmin[0] ||             maxs[1] < absmin[1] ||             maxs[2] < absmin[2] )             continue;         // add to list         pList[count++] = i;         // check for overflow         if( count > listMax )             return count;     }     return count; } public FX_Box(Float:sizemin[3], Float:sizemax[3], color[3], life) {     message_begin( MSG_ALL, SVC_TEMPENTITY );     write_byte( 31 );     write_coord( floatround( sizemin[0] ) ); // x     write_coord( floatround( sizemin[1] ) ); // y     write_coord( floatround( sizemin[2] ) ); // z     write_coord( floatround( sizemax[0] ) ); // x     write_coord( floatround( sizemax[1] ) ); // y     write_coord( floatround( sizemax[2] ) ); // z     write_short( life );    // Life     write_byte( color[0] )// Color R / G / B     write_byte( color[1] );     write_byte( color[2] );     message_end(); }
The blue dot is the origin, yellow line is the default height of the box (600 + 600 = 1200 units), red is the actual box itself, it found entities above and/or below so it has been cropped. This is my goal.


Last edited by Rirre; 06-24-2017 at 08:13.
Rirre is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 06-11-2017 , 14:55   Re: Above or below entity
Reply With Quote #2

Could you explain a bit further and also describe what isn't working. What is supposed to happen? When? What is happening instead?
Without runnable code you really have to give a good description for someone to help you.
__________________
Black Rose is offline
Rirre
Veteran Member
Join Date: Nov 2006
Old 06-22-2017 , 13:45   Re: Above or below entity
Reply With Quote #3

Quote:
Originally Posted by Black Rose View Post
Could you explain a bit further and also describe what isn't working. What is supposed to happen? When? What is happening instead?
Without runnable code you really have to give a good description for someone to help you.
Edited my first post, should be better explained now, as well attached an image to describe it better than just plain text.
Rirre 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 03:33.


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