Raised This Month: $ Target: $400
 0% 

How to check if entity is in zone?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GasmoN
Member
Join Date: Jul 2014
Old 03-12-2018 , 10:35   How to check if entity is in zone?
Reply With Quote #1

here
PHP Code:
is_user_in_zone(idi)
{
    new 
Float:flOrigin[3]
    
pev(idpev_originflOrigin)

    if(  
g_flZoneMin[i][0] < flOrigin[0] && 
        
g_flZoneMin[i][1] < flOrigin[1] && 
        
g_flZoneMin[i][2] < flOrigin[2] && 
        
g_flZoneMax[i][0] > flOrigin[0] && 
        
g_flZoneMax[i][1] > flOrigin[1] && 
        
g_flZoneMax[i][2] > flOrigin[2] )
        return 
1

    
return 0

Whole plugin:
PHP Code:
/*    Copyright © 2008, ConnorMcLeod

    No Kill Zones is free software;
    you can redistribute it and/or modify it under the terms of the
    GNU General Public License as published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with No Kill Zones; if not, write to the
    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN "No Kill Zones"
#define AUTHOR "ConnorMcLeod"
#define VERSION "0.0.7"

#define DONT_BLEED    -1
#define MAX_ZONES    16
#define MAX_PLAYERS    32
#define KEYS    ((1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<8)|(1<<9))

#define write_coord_f(%1) engfunc(EngFunc_WriteCoord,%1)

new g_iZonesNum
new Float:g_flZoneMin[MAX_ZONES][3], Float:g_flZoneMax[MAX_ZONES][3]

new 
Float:g_flTempMin[3], Float:g_flTempMax[3]

new 
g_szFile[100]

new 
g_iMenuNKZ_MENU
new g_iMenuSettings[MAX_PLAYERS+1][2]

new 
iSprite

public plugin_precache()
{
    
iSprite precache_model("sprites/lgtning.spr")
}

public 
plugin_init() 
{
    
register_plugin(PLUGIN ,VERSION ,AUTHOR)

    
RegisterHam(Ham_TakeDamage"player""Player_TakeDamage")
    
RegisterHam(Ham_TraceAttack"player" "Player_TraceAttack" 

    
NKZ_MENU register_menuid("NKZ")
    
register_menucmdNKZ_MENU KEYS"actionZoneMenu")

    
register_clcmd("nkz_menu""ClientCommand_Menu"ADMIN_CFG)
}

public 
plugin_cfg()
{
    
get_localinfo("amxx_configsdir"g_szFilecharsmax(g_szFile))
    new 
szMapName[32]
    
get_mapname(szMapNamecharsmax(szMapName))
    
format(g_szFilecharsmax(g_szFile), "%s/nkz"g_szFile)

    if( !
dir_exists(g_szFile) )
    {
        
mkdir(g_szFile)
        
format(g_szFilecharsmax(g_szFile), "%s/%s.ini"g_szFileszMapName)
        return
    }

    
format(g_szFilecharsmax(g_szFile), "%s/nkz/%s.ini"g_szFileszMapName)

    new 
iFile fopen(g_szFile"rt")
    if( !
iFile )
        return

    new 
szData[50], szCoords[6][8]
    while(!
feof(iFile) && g_iZonesNum<MAX_ZONES)
    {
        
fgets(iFileszDatacharsmax(szData))
        
trimszData )
        if(!
szData[0] || szData[0] == ';' || (szData[0] == '/' && szData[1] == '/'))
            continue

        
parse(szDataszCoords[0], 7szCoords[1], 7szCoords[2], 7
            
szCoords[3], 7szCoords[4], 7szCoords[5], 7

        for(new 
ii<3i++)
        {
            
g_flZoneMin[g_iZonesNum][i] = str_to_floatszCoords[i] )
            
g_flZoneMax[g_iZonesNum][i] = str_to_floatszCoords[i+3] )
        }
        
g_iZonesNum++
    }
    
fclose(iFile)
}

public 
plugin_end()
{
    
delete_file(g_szFile)

    new 
iFile fopen(g_szFile"a+")
    if( !
iFile )
        return

    new 
szData[50]
    for(new 
ii<g_iZonesNumi++)
    {
        
formatexszData49"%.1f %.1f %.1f %.1f %.1f %.1f^n"
            
g_flZoneMin[i][0], g_flZoneMin[i][1], g_flZoneMin[i][2],
            
g_flZoneMax[i][0], g_flZoneMax[i][1], g_flZoneMax[i][2] )
        
fputs(iFileszData)
    }
    
fclose(iFile)
}

public 
Player_TakeDamage(idiEntidattackerFloat:damagedamagebits)
{
    if( 
iEnt == idattacker )
    {
        return 
HAM_IGNORED
    
}

    for(new 
ii<g_iZonesNumi++)
    {
        if( 
is_user_in_zone(iEnti) )
        {
            return 
HAM_SUPERCEDE
        
}
    }

    return 
HAM_IGNORED
}

public 
Player_TraceAttack(ididattackerFloat:damageFloat:direction[3], tracehandledamagebits)
{
    for(new 
ii<g_iZonesNumi++)
    {
        if( 
is_user_in_zone(idi) || is_user_in_zone(idattackeri) )
        {
            return 
HAM_SUPERCEDE
        
}
    }
    return 
HAM_IGNORED
}

public 
client_putinserver(id)
{
    
reset_setting(id)
}

reset_setting(id)
{
    
g_iMenuSettings[id][0] = -2
    g_iMenuSettings
[id][1] = 0
}

public 
client_disconnect(id)
{
    if( 
g_iMenu == id )
    {
        
g_iMenu 0
    
}
}

public 
ClientCommand_Menu(idlevel)
{
    if( !(
get_user_flags(id) & level) )
        return 
PLUGIN_HANDLED

    
if( g_iMenu )
    {
        new 
iMenuIdLoL
        get_user_menu
(g_iMenuiMenuIdLoL)
        if( 
iMenuId == NKZ_MENU )
        {
            
client_print(idprint_chat"Sorry, someone already uses this menu, try again later...")
            
client_print(idprint_console"Sorry, someone already uses this menu, try again later...")
            return 
PLUGIN_HANDLED
        
}
    }
    
g_iMenu id
    reset_setting
(id)

    
display_menu(id)
    return 
PLUGIN_HANDLED
}

display_menu(id)
{
    new 
szMenu[1024], niZone g_iMenuSettings[id][0]
    static const 
szAxes[][] = { "x (red)" "y (blue)" "z (green)" }

    
formatex(szMenu1023"\rNoKill Zone Menu\y ")
    
    if(
iZone 0)
        
+= formatex(szMenu[n], 1023-n"(New Zone)^n")
    else
        
+= formatex(szMenu[n], 1023-n"(Zone %d/%d)^n"iZone+1g_iZonesNum)

    
+= formatex(szMenu[n], 1023-n"\w1. %s^n^n"g_iZonesNum "Next Zone":"Create Zone")

    
+= formatex(szMenu[n], 1023-n"2. Current Axe %s^n"szAxes[g_iMenuSettings[id][1]])

    
+= formatex(szMenu[n], 1023-n"3. Move ++^n")
    
+= formatex(szMenu[n], 1023-n"4. Move --^n")

    
+= formatex(szMenu[n], 1023-n"5. Increase size^n")
    
+= formatex(szMenu[n], 1023-n"6. Decrease size^n")

    
+= formatex(szMenu[n], 1023-n"7. \yDraw Zone^n^n")

    
+= formatex(szMenu[n], 1023-n"\w9. \rSave Zone & Exit^n")

    
+= formatex(szMenu[n], 1023-n"\w0. Cancel")

    if(
iZone == -2)
    {
        
Create_Temp_Zone(id)
        
g_iMenuSettings[id][0] = -1
    
}

    
show_menu(idKEYSszMenu, -1"NKZ")
}

public 
actionZoneMenu(idkey)
{
    new 
iZone g_iMenuSettings[id][0]
    switch( 
key )
    {
        case 
0:
        {
            if( 
iZone g_iZonesNum-)
            {
                
iZone = ++g_iMenuSettings[id][0]
                
vec_copy(g_flZoneMin[iZone], g_flTempMin)
                
vec_copy(g_flZoneMax[iZone], g_flTempMax)
                
Draw_Ent(id)
            }
            else
            {
                
Create_Temp_Zone(id)
                
g_iMenuSettings[id][0] = -1
            
}
            
display_menu(id)
        }
        case 
1:
        {
            if( ++
g_iMenuSettings[id][1] >= )
                
g_iMenuSettings[id][1] = 0

            display_menu
(id)
        }
        case 
2:
        {
            new 
iAxe g_iMenuSettings[id][1]

            
g_flTempMin[iAxe] += 20
            g_flTempMax
[iAxe] += 20
            Draw_Ent
(id50)

            
display_menu(id)
        }
        case 
3:
        {
            new 
iAxe g_iMenuSettings[id][1]

            
g_flTempMin[iAxe] -= 20
            g_flTempMax
[iAxe] -= 20
            Draw_Ent
(id50)

            
display_menu(id)
        }
        case 
4:
        {
            new 
iAxe g_iMenuSettings[id][1]

            
g_flTempMin[iAxe] -= 15
            g_flTempMax
[iAxe] += 15
            Draw_Ent
(id50)

            
display_menu(id)
        }
        case 
5:
        {
            new 
iAxe g_iMenuSettings[id][1]

            
g_flTempMin[iAxe] += 15
            g_flTempMax
[iAxe] -= 15
            Draw_Ent
(id50)

            
display_menu(id)
        }
        case 
6:
        {
            
Draw_Ent(id)
            
display_menu(id)
        }
        case 
8:
        {
            if( 
iZone == -)
            {
                if( 
g_iZonesNum MAX_ZONES-)
                {
                    
vec_copy(g_flTempMing_flZoneMin[g_iZonesNum])
                    
vec_copy(g_flTempMaxg_flZoneMax[g_iZonesNum])
                    
g_iZonesNum++
                    
client_print(idprint_chat"[NKZ] Zone #%d saved"g_iZonesNum)
                }
                else
                {
                    
client_print(idprint_chat"Too much zones created")
                }
            }
            else
            {
                
vec_copy(g_flTempMing_flZoneMin[iZone])
                
vec_copy(g_flTempMaxg_flZoneMax[iZone])
                
client_print(idprint_chat"[NKZ] Zone #%d modified"iZone)
            }
            
arrayset_f(g_flTempMin0.03)
            
arrayset_f(g_flTempMax0.03)
            
reset_setting(id)
            
g_iMenu 0
        
}
        case 
9:
        {
            
arrayset_f(g_flTempMin0.03)
            
arrayset_f(g_flTempMax0.03)
            
reset_setting(id)
            
g_iMenu 0
        
}
    }
}

Create_Temp_Zoneid )
{
    new 
Float:flOrigin[3]
    
pev(idpev_originflOrigin)

    
flOrigin[0] -= 100.0
    flOrigin
[1] -= 100.0
    flOrigin
[2] -= 36.0
    vec_copy
(flOriging_flTempMin)

    
flOrigin[0] += 200.0
    flOrigin
[1] += 200.0
    flOrigin
[2] += 100.0
    vec_copy
(flOriging_flTempMax)

    
client_print(idprint_chat"New Zone Created (not saved yet)")
}

Draw_Ent(idlife=100)
{
    new 
Float:flAbsmin[3], Float:flAbsmax[3]
    
vec_copy(g_flTempMinflAbsmin)
    
vec_copy(g_flTempMaxflAbsmax)

/*
                   7----------8
                  /|         /|
                 / |        / | 
                5----------6  |    
                |  |       |  |
                |  3-------|--4
                | /        | /    
                |/         |/
                1----------2
*/
    /*x red*/
    
UTIL_DrawBeam(idflAbsmin[0],flAbsmin[1],flAbsmin[2] , flAbsmax[0],flAbsmin[1],flAbsmin[2] , life20120020202550)
    
UTIL_DrawBeam(idflAbsmin[0],flAbsmin[1],flAbsmax[2] , flAbsmax[0],flAbsmin[1],flAbsmax[2] , life20120020202550)
    
UTIL_DrawBeam(idflAbsmin[0],flAbsmax[1],flAbsmin[2] , flAbsmax[0],flAbsmax[1],flAbsmin[2] , life20120020202550)
    
UTIL_DrawBeam(idflAbsmin[0],flAbsmax[1],flAbsmax[2] , flAbsmax[0],flAbsmax[1],flAbsmax[2] , life20120020202550)

    
/*y blue*/
    
UTIL_DrawBeam(idflAbsmin[0],flAbsmin[1],flAbsmin[2] , flAbsmin[0],flAbsmax[1],flAbsmin[2] , life20120202002550)
    
UTIL_DrawBeam(idflAbsmin[0],flAbsmin[1],flAbsmax[2] , flAbsmin[0],flAbsmax[1],flAbsmax[2] , life20120202002550)
    
UTIL_DrawBeam(idflAbsmax[0],flAbsmin[1],flAbsmin[2] , flAbsmax[0],flAbsmax[1],flAbsmin[2] , life20120202002550)
    
UTIL_DrawBeam(idflAbsmax[0],flAbsmin[1],flAbsmax[2] , flAbsmax[0],flAbsmax[1],flAbsmax[2] , life20120202002550)

    
/*z green*/
    
UTIL_DrawBeam(idflAbsmin[0],flAbsmin[1],flAbsmin[2] , flAbsmin[0],flAbsmin[1],flAbsmax[2] , life20120200202550)
    
UTIL_DrawBeam(idflAbsmax[0],flAbsmax[1],flAbsmin[2] , flAbsmax[0],flAbsmax[1],flAbsmax[2] , life20120200202550)
    
UTIL_DrawBeam(idflAbsmax[0],flAbsmin[1],flAbsmin[2] , flAbsmax[0],flAbsmin[1],flAbsmax[2] , life20120200202550)
    
UTIL_DrawBeam(idflAbsmin[0],flAbsmax[1],flAbsmin[2] , flAbsmin[0],flAbsmax[1],flAbsmax[2] , life20120200202550)
}

// shptools
UTIL_DrawBeam(idFloat:start0Float:start1Float:start2Float:end0Float:end1Float:end2lifewidthnoiseredgreenbluebrightnessspeed)
{
    
message_begin(MSG_ONE_UNRELIABLESVC_TEMPENTITY_id)
    
write_byte(TE_BEAMPOINTS)
    
write_coord_f(start0)
    
write_coord_f(start1)
    
write_coord_f(start2)
    
write_coord_f(end0)
    
write_coord_f(end1)
    
write_coord_f(end2)
    
write_short(iSprite)
    
write_byte(1// framestart
    
write_byte(10// framerate
    
write_byte(life// life in 0.1's
    
write_byte(width// width
    
write_byte(noise// noise
    
write_byte(red// r, g, b
    
write_byte(green// r, g, b
    
write_byte(blue// r, g, b
    
write_byte(brightness// brightness
    
write_byte(speed// speed
    
message_end()
}

vec_copy(const Float:vecIn[], Float:vecOut[])
{
    
vecOut[0] = vecIn[0]
    
vecOut[1] = vecIn[1]
    
vecOut[2] = vecIn[2]
}

is_user_in_zone(idi)
{
    new 
Float:flOrigin[3]
    
pev(idpev_originflOrigin)

    if(  
g_flZoneMin[i][0] < flOrigin[0] && 
        
g_flZoneMin[i][1] < flOrigin[1] && 
        
g_flZoneMin[i][2] < flOrigin[2] && 
        
g_flZoneMax[i][0] > flOrigin[0] && 
        
g_flZoneMax[i][1] > flOrigin[1] && 
        
g_flZoneMax[i][2] > flOrigin[2] )
        return 
1

    
return 0
}

arrayset_f(Float:flArray[], Float:flValueiSize)
{
    for(--
iSizeiSize>=0iSize--)
    {
        
flArray[iSize] = flValue
    
}

GasmoN is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 03-12-2018 , 10:41   Re: How to check if entity is in zone?
Reply With Quote #2

https://forums.alliedmods.net/showpo...26&postcount=5

https://forums.alliedmods.net/showpo...34&postcount=9
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 03-12-2018 at 10:43.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
GasmoN
Member
Join Date: Jul 2014
Old 03-12-2018 , 10:47   Re: How to check if entity is in zone?
Reply With Quote #3

I need for entityfor my basebuilder mod.

PHP Code:
public bb_core_user_drop_block_post(identity
Can you give me example?

Last edited by GasmoN; 03-12-2018 at 10:48.
GasmoN is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 03-12-2018 , 10:51   Re: How to check if entity is in zone?
Reply With Quote #4

I just did.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
GasmoN
Member
Join Date: Jul 2014
Old 03-12-2018 , 11:12   Re: How to check if entity is in zone?
Reply With Quote #5

I'll try and post here results. Thanks
GasmoN is offline
GasmoN
Member
Join Date: Jul 2014
Old 03-12-2018 , 13:03   Re: How to check if entity is in zone?
Reply With Quote #6

I have no idea how to do this.

EDIT: This is what i tried.

PHP Code:
is_user_in_zone(idi)
{
    new 
Float:fOrigin[3];
    
pev(idpev_originfOrigin)

    for(new 
iiMAXENTSi++)
    {
        
pev(g_iOwnedEnt[i], pev_originfOrigin);
        
        if(
g_flZoneMin[i][0] <= fOrigin[0] <= g_flZoneMax[i][0] && g_flZoneMin[i][1] <= fOrigin[1] <= g_flZoneMax[i][1] && g_flZoneMin[i][2] <= fOrigin[2] <= g_flZoneMax[i][2]) 
        {
            
engfuncEngFunc_SetOriginiFloat:{ 0.00.00.0 } );
            
CheckEnt true
        
}
        else
        {
            
CheckEnt false
        
}
    }

    return 
CheckEnt;


Last edited by GasmoN; 03-12-2018 at 13:06.
GasmoN is offline
GasmoN
Member
Join Date: Jul 2014
Old 03-12-2018 , 13:05   Re: How to check if entity is in zone?
Reply With Quote #7

- mistake -

Last edited by GasmoN; 03-12-2018 at 13:06.
GasmoN 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 20:26.


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