AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] No Kill Zones [By ConnorMcLeod] (https://forums.alliedmods.net/showthread.php?t=196385)

Erdener 09-20-2012 04:47

[HELP] No Kill Zones [By ConnorMcLeod]
 
PHP Code:

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

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

#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)

    
RegisterHamHam_TakeDamage"player""TakeDamage_player")

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

    
register_clcmd("nkz_menu""ClientCommand_Menu"ADMIN_CFG)
}

public 
plugin_cfg()
{
    
load_setting()
}

load_setting()
{
    
get_configsdir(g_szFile99)
    new 
szMapName[32]
    
get_mapname(szMapName31)
    
format(g_szFile99"%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(iFileszData49)
        
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 
TakeDamage_player(idiEntidattackerFloat:damagedamagebits)
{
    for(new 
ii<g_iZonesNumi++)
    {
        if( 
is_user_in_zone(idi) || is_user_in_zone(idattackeri) )
        {
            
SetHamParamFloat(40.0)
            return 
HAM_HANDLED
        
}
    }
    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(idlevelcid)
{
    if( !
cmd_access(idlevelcid1) )
        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
    
}



I build the coordinates of the in game.But, players is killing me :cry:

Erdener 10-11-2012 08:04

Re: [HELP] No Kill Zones [By ConnorMcLeod]
 
Up.

Erdener 01-30-2013 13:38

Re: [HELP] No Kill Zones [By ConnorMcLeod]
 
Hey! for this topic can you help me?


All times are GMT -4. The time now is 08:11.

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