AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to check entity side? (https://forums.alliedmods.net/showthread.php?t=221850)

kulers2010 07-27-2013 05:31

How to check entity side?
 
I search and found only this but i dont know how to use thats on entity.

#define TOUCH_NONE 1<<0
#define TOUCH_ALL 1<<1
#define TOUCH_BOTH 1<<2
#define TOUCH_HEAD 1<<3
#define TOUCH_FOOT 1<<4
#define TOUCH_OTHER 1<<5

Edit: I mean when player touch thats entity.

Black Rose 07-27-2013 09:50

Re: How to check entity side?
 
Do you want to determine which side of the entity that was touched?
I believe you have to compare origins and check which dimension is the closest to determine that.

kulers2010 07-27-2013 11:55

Re: How to check entity side?
 
I need if player stands on the block ,or touch side or hit his head to the block bottom

Black Rose 07-27-2013 12:39

Re: How to check entity side?
 
Quote:

Originally Posted by kulers2010 (Post 1999926)
I need if player stands on the block ,or touch side or hit his head to the block bottom

Yes, but do you need to determine which side of the block that is touched or just that is was touched?

kulers2010 07-27-2013 12:50

Re: How to check entity side?
 
How i said i need know whitch side bottom, top or sides

Black Rose 07-27-2013 15:30

Re: How to check entity side?
 
Ok, then you just compare the differences from the entity origin and the player origin to the size of the entity and the one that is the lowest contains your answer.

EDIT: I found the subject interesting so I decided to try it out. This is the best I could create:
There may be some math errors but I don't think so. If there is, it would be because it's 4AM here and I need to sleep.
Code:
#include <amxmodx> #include <hamsandwich> #include <fakemeta> new const g_TouchedSide[][] = {     "east",     "north",     "top",     "west",     "south",     "bottom" } public plugin_init() {     register_plugin("Test Plugin 9", "", "");         RegisterHam(Ham_Touch, "player", "HamTouch"); } public HamTouch(id, ent) {         if ( 0 >= id > 32 || ! ent )     return;         new iSide, Float:plOrigin[3], Float:entOrigin[3], Float:entSize[3], Float:entMins[3], Float:entMaxs[3];         pev(id, pev_origin, plOrigin);     pev(ent, pev_origin, entOrigin);     pev(ent, pev_size, entSize);     pev(ent, pev_mins, entMins);     pev(ent, pev_maxs, entMaxs);         new Float:fDifference[4] = {0.0,0.0,0.0,9999.9};         fDifference[0] = floatabs(floatabs(floatabs(plOrigin[0]) - floatabs(entOrigin[0] + entMins[0] + ( ( floatabs(entMins[0]) + floatabs(entMaxs[0]) ) / 2 ) ) ) - entSize[0] / 2 - 16); // Touched East/West     fDifference[1] = floatabs(floatabs(floatabs(plOrigin[1]) - floatabs(entOrigin[1] + entMins[1] + ( ( floatabs(entMins[1]) + floatabs(entMaxs[1]) ) / 2 ) ) ) - entSize[1] / 2 - 16); // Touched North/South     fDifference[2] = floatabs(floatabs(floatabs(plOrigin[2]) - floatabs(entOrigin[2] + entMins[2] + ( ( floatabs(entMins[2]) + floatabs(entMaxs[2]) ) / 2 ) ) ) - entSize[2] / 2 - ( pev(id, pev_flags) & FL_DUCKING ? 18 : 36 ) ); // Touched Top/Bottom         for ( new i = 0; i < 3 ; i++ ) {         if ( fDifference[i] < fDifference[3] ) {             iSide = i;             fDifference[3] = fDifference[i]         }     }         if ( plOrigin[iSide] < entOrigin[iSide] )     iSide += 3;         client_print(id, print_chat, "%d touched %d on the %s side", id, ent, g_TouchedSide[iSide]); } /* Player offsets: * X *   +16 * Y *   +16 * Z *   Standing:  +36 *   Ducking:   +18 */


All times are GMT -4. The time now is 06:28.

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