Here is an example of specific weapon spawn protection for cs.
but I cant get it to work for hldm/AG to create spawn mine protection.
Код:
/*
- Plugin: Weapon-Specific Spawn Protection
- Version: 1.0
- Author: H3avY Ra1n
-
- Description
- -----------
- This plugin allows you to protect a player from a certain
- weapon for the first X seconds after he spawns.
-
- A .ini file is created where you can place the weapon names that you want
- to be blocked.
-
- CVARs
- -----
- wssp_protect_time <seconds>
- + How long after a player spawns he is no longer protected
- from the specified weapons
- + Default: 5
-
-
- Changelog
- ---------
- October 12, 2011
- - v1.0 -
- + Initial Release
- - v1.0.1 -
- + Turn off plugin if no weapons registered
- + Don't try to read from file if plugin's first run
- + Changed from boolean and tasks to get_gametime()
- October 14, 2011
- - v1.1 -
- + Optimized Ham_TakeDamage call and Ham_TraceAttack call_think + Credits to ConnorMcLeod for the optimisation.
- Credits
- -------
- Vamppa
- + Original Idea
- + Thread: http://forums.alliedmods.net/showthread.php?p=1573613
- ConnorMcLeod
- + Plugin Optimisations
-
*/
/* Includes */
#include < amxmodx >
#include < amxmisc >
#include < hamsandwich >
/* Defines */
#define MAX_PLAYERS 32
#define DMG_HEGRENADE (1<<24)
/* Constants */
new const g_szVersion[ ] = "1.1";
/* Integers */
new g_iProtectWeapons;
new g_iMaxPlayers;
/* PCVARs */
new g_pProtectionTime;
/* Floats */
new Float:g_flSpawnTime[ MAX_PLAYERS + 1 ];
///////////////////
//* Plugin Init *//
///////////////////
public plugin_init()
{
register_plugin( "Weapon-Specific Spawn Protection", g_szVersion, "H3avY Ra1n" );
LoadWeapons();
if( g_iProtectWeapons == 0 )
return;
RegisterHam( Ham_Spawn, "player", "Ham_PlayerSpawn_Post", 1 );
RegisterHam( Ham_TraceAttack, "player", "Ham_PlayerTraceAttack_Pre", 0 );
RegisterHam( Ham_TakeDamage, "player", "Ham_PlayerTakeDamage_Pre", 0 );
g_pProtectionTime = register_cvar( "wssp_protect_time", "5" );
g_iMaxPlayers = get_maxplayers();
}
/////////////////////
//* Ham Functions *//
//* ------------- *//
//* Player Spawn *//
//* Trace Attack *//
//* Take Damage *//
/////////////////////
public Ham_PlayerSpawn_Post( id )
{
g_flSpawnTime[ id ] = get_gametime();
}
public Ham_PlayerTraceAttack_Pre( iVictim, iAttacker, Float:flDamage, Float:flDirection[ 3 ], iTraceHandle, iBits )
{
if( !( 1 <= iAttacker <= g_iMaxPlayers ) || get_gametime() - g_flSpawnTime[ iVictim ] < get_pcvar_float( g_pProtectionTime ) )
return HAM_IGNORED;
new iWeapon = get_user_weapon( iAttacker );
if( g_iProtectWeapons & ( 1<<iWeapon ) )
return HAM_SUPERCEDE;
return HAM_IGNORED;
}
public Ham_PlayerTakeDamage_Pre( iVictim, iInflictor, iAttacker, Float:flDamage, iBits )
{
if( 1 <= iAttacker <= g_iMaxPlayers
&& iBits & DMG_HEGRENADE
&& g_iProtectWeapons & ( 1<<CSW_HEGRENADE )
&& get_gametime() - g_flSpawnTime[ iVictim ] > get_pcvar_float( g_pProtectionTime ) )
{
return HAM_SUPERCEDE;
}
return HAM_IGNORED;
}
////////////////////////////////
//* Read File + Load Weapons *//
////////////////////////////////
LoadWeapons()
{
new szDirectory[ 128 ];
get_configsdir( szDirectory, charsmax( szDirectory ) );
add( szDirectory, charsmax( szDirectory ), "/spawn_protect_weapons.ini" );
if( !file_exists( szDirectory ) )
{
write_file( szDirectory, ";Use this file to configure which weapons players are protected from on spawn." );
return;
}
new iFile = fopen( szDirectory, "rt" );
if( !iFile )
{
set_fail_state( "Unable to open file spawn_protect_weapons.ini" );
return;
}
new szBuffer[ 32 ], iWeapon;
while( !feof( iFile ) )
{
fgets( iFile, szBuffer, charsmax( szBuffer ) );
trim( szBuffer );
if( !szBuffer[ 0 ] || szBuffer[ 0 ] == ';' || ( szBuffer[ 0 ] == '/' && szBuffer[ 1 ] == '/' ) )
continue;
iWeapon = get_weaponid( szBuffer );
if( !iWeapon )
continue;
g_iProtectWeapons |= ( 1 << iWeapon );
server_print( "Loaded Weapon: %s", szBuffer );
}
}