Raised This Month: $ Target: $400
 0% 

Player between a Rectangle


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
dordnung
Veteran Member
Join Date: Apr 2010
Old 11-01-2010 , 16:43   Player between a Rectangle
Reply With Quote #1

This Snippet checks if a player is between a rectangular area specified by two opposite corners

Picture (;



PHP Code:
#include <sourcemod>

bool:IsbetweenRect(Float:Pos[3], Float:Corner1[3], Float:Corner2[3], client=0

    
decl Float:Entity[3]; 
    
decl Float:field1[2]; 
    
decl Float:field2[2]; 
    
decl Float:field3[2]; 
    
    if (!
client)
    {
        
Entity Pos;
    }
    else 
GetClientAbsOrigin(clientEntity); 
     
    
// Sort Floats... 
     
    
if (FloatCompare(Corner1[0], Corner2[0]) == -1)  
    { 
        
field1[0] = Corner1[0]; 
        
field1[1] = Corner2[0]; 
    } 
    else 
    { 
        
field1[0] = Corner2[0]; 
        
field1[1] = Corner1[0]; 
    } 
    if (
FloatCompare(Corner1[1], Corner2[1]) == -1)  
    { 
        
field2[0] = Corner1[1]; 
        
field2[1] = Corner2[1]; 
    } 
    else 
    { 
        
field2[0] = Corner2[1]; 
        
field2[1] = Corner1[1]; 
    } 
    if (
FloatCompare(Corner1[2], Corner2[2]) == -1)  
    { 
        
field3[0] = Corner1[2]; 
        
field3[1] = Corner2[2]; 
    } 
    else 
    { 
        
field3[0] = Corner2[2]; 
        
field3[1] = Corner1[2]; 
    } 
     
    
// Check the Vectors ... 
     
    
if (Entity[0] < field1[0] || Entity[0] > field1[1]) return false
    if (
Entity[1] < field2[0] || Entity[1] > field2[1]) return false
    if (
Entity[2] < field3[0] || Entity[2] > field3[1]) return false
     
    return 
true

Have fun with it (;
Attached Thumbnails
Click image for larger version

Name:	eg.jpg
Views:	870
Size:	30.9 KB
ID:	76562  
__________________

Last edited by dordnung; 11-03-2010 at 03:09.
dordnung is offline
 



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 18:09.


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