View Single Post
blaacky
Senior Member
Join Date: Oct 2012
Old 08-05-2013 , 20:59   Re: Check if player is entering a area/zone
Reply With Quote #8

This is a function I use for a plugin I made. The logic is in there and the code is pretty short. It just checks if a player is between two opposite corners of a zone in all 3 axes
PHP Code:
bool:IsInsideZone(clientFloat:point[8][3])
{
    new 
Float:playerPos[3];
    
    
GetEntPropVector(clientProp_Send"m_vecOrigin"playerPos);
    
playerPos[2] += 5.0;
    
    for(new 
i=0i<3i++)
    {
        if(
point[0][i]>=playerPos[i] == point[7][i]>=playerPos[i])
        {
            return 
false;
        }
    }

    return 
true;

Here is a function I use to draw a zone
PHP Code:
/*
* Graphically draws a zone
*    if client == 0, it draws it for all players in the game
*   if client index is between 0 and MaxClients+1, it draws for the specified client
*/
DrawZone(clientFloat:array[8][3], beamspritehalospritecolor[4], Float:life)
{
    for(new 
i=0i2=3i2>=0i+=i2--)
    {
        for(new 
j=1j<=7j+=(j/2)+1)
        {
            if(
!= 7-i)
            {
                
TE_SetupBeamPoints(array[i], array[j], beamspritehalosprite00life5.05.000.0color0);
                if(
client <= MaxClients)
                    
TE_SendToClient(client0.0);
                else
                    
TE_SendToAll(0.0);
            }
        }
    }

And here is one I use to generate all 8 zone points from just 2
PHP Code:
/*
* Generates all 8 points of a zone given just 2 of its points
*/
CreateZonePoints(Float:point[8][3])
{
    for(new 
i=1i<7i++)
    {
        for(new 
j=0j<3j++)
        {
            
point[i][j] = point[((>> (2-j)) & 1) * 7][j];
        }
    }

They are all pretty complicated and took a lot of effort to figure out and are a lot faster and shorter in code then pretty much every other public one that you will find

Last edited by blaacky; 08-06-2013 at 05:45.
blaacky is offline