The first one blocks duck only during freezetime
PHP Code:
#include < amxmodx >
#include < fakemeta >
#include < hamsandwich >
new const g_szPlugin[ ] = "Block Duck On Freezetime";
new const g_szVersion[ ] = "0.0.1";
new const g_szAuthor[ ] = "wizard";
new HamHook:g_hDuck;
public plugin_init( )
{
register_plugin( g_szPlugin, g_szVersion, g_szAuthor );
register_event( "HLTV", "OnFreezetimeStart", "a", "1=0", "2=0" );
register_logevent( "OnRoundStart", 2, "1=Round_Start" );
DisableHamForward( g_hDuck = RegisterHam( Ham_Player_Duck, "player", "OnPlayerDuckPre", 0 ) );
}
public OnFreezetimeStart( )
{
EnableHamForward( g_hDuck );
}
public OnRoundStart( )
{
DisableHamForward( g_hDuck );
}
public OnPlayerDuckPre( iClient )
{
if( !is_user_alive( iClient ) )
return HAM_IGNORED;
static biOldButtons; biOldButtons = pev( iClient, pev_oldbuttons );
biOldButtons |= IN_DUCK;
set_pev( iClient, pev_oldbuttons, biOldButtons );
return HAM_SUPERCEDE;
}
The second one i was trying to do without blocking duck, instead it would set your spawn position if you moved. The problem is that you can't jump nor duck because PreThink is a function executed every frame. I'm posting this anyway if anyone wants to modify and test. It also works but can be really anoying.
PHP Code:
#include < amxmodx >
#include < fakemeta >
#include < hamsandwich >
new const g_szPlugin[ ] = "Block Duck On Freezetime";
new const g_szVersion[ ] = "0.0.1";
new const g_szAuthor[ ] = "wizard";
new HamHook:g_hPreThink;
new Float:g_fPlayerPos[ 33 ][ 3 ];
public plugin_init( )
{
register_plugin( g_szPlugin, g_szVersion, g_szAuthor );
register_event( "HLTV", "OnFreezetimeStart", "a", "1=0", "2=0" );
register_logevent( "OnRoundStart", 2, "1=Round_Start" );
DisableHamForward( g_hPreThink = RegisterHam( Ham_Player_PreThink, "player", "OnPlayerPreThink", 0 ) );
RegisterHam( Ham_Spawn, "player", "OnPlayerSpawn", 1 );
}
public OnFreezetimeStart( )
{
if( get_cvar_num( "mp_freezetime" ) > 0 ) // Security check, if there is no freezetime then we shouldn't enable ham
set_task( 1.0, "LetPlayerSpawn" ); // Cooldown so players can spawn and 'OnPlayerSpawn' can save their positions
}
public LetPlayerSpawn( )
{
EnableHamForward( g_hPreThink );
}
public OnRoundStart( )
{
DisableHamForward( g_hPreThink );
}
public OnPlayerSpawn( iClient )
{
if( !is_user_alive( iClient ) )
return HAM_IGNORED;
set_task( 0.5, "SavePlayerPos", iClient ); // This was needed, otherwise the plugin would save the player while in the air
pev( iClient, pev_origin, g_fPlayerPos[ iClient ] );
return HAM_IGNORED;
}
public SavePlayerPos( iClient )
{
if( !is_user_alive( iClient ) )
return;
pev( iClient, pev_origin, g_fPlayerPos[ iClient ] );
}
public OnPlayerPreThink( iClient )
{
if( !is_user_alive( iClient ) )
return HAM_IGNORED;
static Float:fPos[ 3 ]; pev( iClient, pev_origin, fPos );
if( xs_vec_equal( fPos, g_fPlayerPos[ iClient ] ) )
return HAM_IGNORED;
engfunc( EngFunc_SetOrigin, iClient, g_fPlayerPos[ iClient ] );
return HAM_IGNORED;
}
bool:xs_vec_equal(const Float:vec1[], const Float:vec2[]) // Stolen from XS library
{
return (vec1[0] == vec2[0]) && (vec1[1] == vec2[1]) && (vec1[2] == vec2[2]);
}
You're probably going to use this plugin in dust2 so if you want you can add this in plugin_init()
PHP Code:
new szMapName[ 32 ];
if( !equal( szMapName, "de_dust2" ) )
set_fail_state( "Plugin only for dust2" );
There is also an orpheu version, but it always block duck -->
https://forums.alliedmods.net/showthread.php?t=118476
Cheers!
__________________