AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   Player between a Rectangle (https://forums.alliedmods.net/showthread.php?t=142126)

dordnung 11-01-2010 16:43

Player between a Rectangle
 
1 Attachment(s)
This Snippet checks if a player is between a rectangular area specified by two opposite corners

Picture (;

http://forums.alliedmods.net/attachm...1&d=1288698870

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 (;

FaTony 11-02-2010 06:31

Re: Player between a Rectangle
 
Define: between a rectangle.

M1NDFREAK 11-02-2010 07:29

Re: Player between a Rectangle
 
Which rectancle?

dordnung 11-02-2010 07:47

Re: Player between a Rectangle
 
Oh sry, i updated my first post

"Checks if a player is between a rectangular area specified by two opposite corners"

And also add a Picture ^^

Sammy-ROCK! 11-02-2010 20:58

Re: Player between a Rectangle
 
Why not make it Vector instead of client?

dordnung 11-03-2010 03:10

Re: Player between a Rectangle
 
Ok, i updated the first post, where both is possible (;

SuperShadow 11-03-2010 14:33

Re: Player between a Rectangle
 
Shouldn't that be check if a client is within a box (cube)? A rectangle is 2 dimensional shape.

dordnung 11-03-2010 18:06

Re: Player between a Rectangle
 
"rectangular area" means "cuboid"

SuperShadow 11-03-2010 18:20

Re: Player between a Rectangle
 
Not in English, a rectangle is the surface of one side of a cube.

dordnung 11-03-2010 18:54

Re: Player between a Rectangle
 
Mh, ok ;D

DarkEnergy 11-03-2010 20:07

Re: Player between a Rectangle
 
it should note it uses abs-origin, not eye-pos

nice job, if only it can be used to detect player stuck *cough check hull doesnt capture everything*?

FaTony 11-04-2010 08:59

Re: Player between a Rectangle
 
PHP Code:

stock bool:IsPlayerInside(const client, const Float:mins[3], const Float:maxs[3])
{
    
//Check if client is connected, in game, has origin
    
decl Float:pos[3];
    
GetClientAbsOrigin(clientpos);
    return 
IsPositionInside(posminsmaxs);
}

stock bool:IsPositionInside(const Float:pos[3], const Float:mins[3], const Float:maxs[3])
{
    if ((
pos[0] > mins[0]) && (pos[0] < maxs[0]) && (pos[1] > mins[1]) && (pos[1] < maxs[1]) && (pos[2] > mins[2]) && (pos[2] < maxs[2]))
    {
        return 
true;
    }
    return 
false;



Monkeys 11-10-2010 09:48

Re: Player between a Rectangle
 
This uses too big assumptions to be useful.
It assumes that the cube is parallel with the axis in every direction.
2 points is not enough to define a cube without those assumptions, though.

FaTony 11-10-2010 23:59

Re: Player between a Rectangle
 
Quote:

Originally Posted by Monkeys (Post 1346591)
This uses too big assumptions to be useful.
It assumes that the cube is parallel with the axis in every direction.
2 points is not enough to define a cube without those assumptions, though.

That is an optimization of the initial code.

NatalyaAF 11-16-2010 18:28

Re: Player between a Rectangle
 
This is awesome. Lets modders set up special areas in a map without trigger_multiple.

FaTony 11-17-2010 03:01

Re: Player between a Rectangle
 
...but trigger_multiple will save many CPU cycles.


All times are GMT -4. The time now is 18:09.

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