Senior Member
Join Date: Dec 2014
Location: Abu Dhabi
|
01-06-2015
, 13:54
Plugin Request
|
#1
|
Hello there,
I was using a plugin that was made by Exolent, which is command limiter.
So basically what this plugin does is just limit a specific command for admin.
Quote:
Originally Posted by Exolent[jNr]
Cvars:
command_limiter_flag <flag>
- Flag required for admins/players to have this command limited
- Only 1 flag is allowed
File:
File should be located at: addons/amxmodx/configs/command_limiter.ini
Format for this file is:
Code:
; Lines starting with ; are comments
// Lines starting with // are also comments
; Empty lines are ignored
; To limit a command for a certain amount of attempts within a certain amount of time, use this format:
; "command" "uses" "seconds"
;
; That will limit "command" to a maximum of "uses" within "seconds"
;
; Be sure player has access for this command or it won't work.
;
; Example:
; "amx_map" "3" "86400"
Requirements:
AMX Mod X 1.8.1 or higher
SQLVault
SQLVault: Extended
- Compile locally with both of those includes
Installation:
1. Compile the .sma locally with sqlvault.inc and sqlvault_ex.inc
2. Put the .amxx in the plugins folder
3. Put command_limiter_flags.amxx at the TOP of the plugins.ini file, above admin.amxx and all other plugins.
4. Configure the .ini file accordingly
Compiled, not tested.
|
I tried the plugin, but the problem is that it does not limit the command, and after I reconnect to the server, the server crashes without any logs.
So what I want is 1 of 2, either
1- Fixing the code.
2- a plugin for limiting a specific command.
Thank you very much
Here is the plugin:
PHP Code:
#include < amxmodx >
#include < amxmisc >
#include < sqlvault_ex >
#define MAX_COMMAND_SIZE 64
#define MAX_PLAYERS 32
enum _:CommandData
{
Command_iMaxUses,
Command_iMaxTime
};
new Array:g_aCommands;
new g_iNumCommands;
new Trie:g_tCommandToIndex;
// g_aPlayerUsage[ iPlayer ] = Array( iCommandIndex => aCommandUsage )
// aCommandUsage = Array( time, time, ... )
new Array:g_aPlayerUsage[ MAX_PLAYERS + 1 ];
new g_szSteamID[ MAX_PLAYERS + 1 ][ 35 ];
new g_pCvarFlag;
new SQLVault:g_hVault;
public plugin_init( )
{
register_plugin( "Command Limiter by Flag", "0.0.1", "Exolent" );
g_pCvarFlag = register_cvar( "command_limiter_flag", "n" );
g_aCommands = ArrayCreate( CommandData );
g_tCommandToIndex = TrieCreate( );
new iMaxPlayers = get_maxplayers( );
for( new iPlayer = 1; iPlayer <= iMaxPlayers; iPlayer++ )
{
g_aPlayerUsage[ iPlayer ] = ArrayCreate( );
}
g_hVault = sqlv_open_local( "command_limiter", false );
if( !sqlv_init_ex( g_hVault ) )
{
set_fail_state( "Error opening SQLVault" );
}
sqlv_connect( g_hVault );
LoadCommands( iMaxPlayers );
}
public plugin_end( )
{
sqlv_close( g_hVault );
}
public client_authorized( iPlayer )
{
get_user_authid( iPlayer, g_szSteamID[ iPlayer ], charsmax( g_szSteamID[ ] ) );
LoadPlayerUsage( iPlayer );
}
public client_disconnect( iPlayer )
{
for( new iCommandIndex = 0; iCommandIndex < g_iNumCommands; iCommandIndex++ )
{
ArrayClear( ArrayGetCell( g_aPlayerUsage[ iPlayer ], iCommandIndex ) );
}
}
public client_command( iPlayer )
{
if( access( iPlayer, GetFlag( ) ) )
{
static szCommand[ MAX_COMMAND_SIZE ];
read_argv( 0, szCommand, charsmax( szCommand ) );
strtolower( szCommand );
new iCommandIndex;
if( TrieGetCell( g_tCommandToIndex, szCommand, iCommandIndex ) )
{
static eCommandData[ CommandData ];
ArrayGetArray( g_aCommands, iCommandIndex, eCommandData );
new Array:aUsageTimes = ArrayGetCell( g_aPlayerUsage[ iPlayer ], iCommandIndex );
new iTotalUsage = ArraySize( aUsageTimes );
new iUnixTime = get_systime( );
new bool:bUpdate;
while( iTotalUsage > 0 && ( iUnixTime - eCommandData[ Command_iMaxTime ] ) >= ArrayGetCell( aUsageTimes, 0 ) )
{
ArrayDeleteItem( aUsageTimes, 0 );
iTotalUsage--;
bUpdate = true;
}
if( iTotalUsage < eCommandData[ Command_iMaxUses ] )
{
ArrayPushCell( aUsageTimes, iUnixTime );
SavePlayerUsage( iPlayer, szCommand, aUsageTimes );
}
else
{
if( bUpdate )
{
SavePlayerUsage( iPlayer, szCommand, aUsageTimes );
}
return PLUGIN_HANDLED;
}
}
}
return PLUGIN_CONTINUE;
}
LoadCommands( iMaxPlayers )
{
new szFile[ 64 ];
get_configsdir( szFile, charsmax( szFile ) );
add( szFile, charsmax( szFile ), "/command_limiter.ini" );
new pFile = fopen( szFile, "rt" );
if( pFile )
{
new szLine[ 128 ];
new szCommand[ MAX_COMMAND_SIZE ];
new szMaxUses[ 12 ];
new szMaxTime[ 12 ];
new eCommandData[ CommandData ];
new iPlayer;
while( !feof( pFile ) )
{
fgets( pFile, szLine, charsmax( szLine ) );
trim( szLine );
if( !szLine[ 0 ] || szLine[ 0 ] == ';' || szLine[ 0 ] == '/' && szLine[ 1 ] == '/' )
{
continue;
}
parse( szLine, szCommand, charsmax( szCommand ), szMaxUses, charsmax( szMaxUses ), szMaxTime, charsmax( szMaxTime ) );
strtolower( szCommand );
if( TrieKeyExists( g_tCommandToIndex, szCommand ) )
{
continue;
}
eCommandData[ Command_iMaxUses ] = str_to_num( szMaxUses );
eCommandData[ Command_iMaxTime ] = str_to_num( szMaxTime );
ArrayPushArray( g_aCommands, eCommandData );
TrieSetCell( g_tCommandToIndex, szCommand, g_iNumCommands );
for( iPlayer = 1; iPlayer <= iMaxPlayers; iPlayer++ )
{
ArrayPushCell( g_aPlayerUsage[ iPlayer ], ArrayCreate( ) );
}
g_iNumCommands++;
}
fclose( pFile );
}
}
GetFlag( )
{
new szFlags[ 2 ];
get_pcvar_string( g_pCvarFlag, szFlags, charsmax( szFlags ) );
return read_flags( szFlags );
}
LoadPlayerUsage( iPlayer )
{
new szWhere[ 64 ];
formatex( szWhere, charsmax( szWhere ), "`key1` = '%s'", g_szSteamID[ iPlayer ] );
new Array:aVaultData;
new iNumEntries = sqlv_read_all_ex( g_hVault, aVaultData, szWhere, "`key2` ASC" );
new eVaultData[ SQLVaultEntryEx ];
new iCommandIndex;
new eCommandData[ CommandData ];
new Array:aUsageTimes;
new iNumTimes;
new iStart, iPos;
new szTime[ 12 ], iTime;
new iUnixTime = get_systime( );
for( new i = 0; i < iNumEntries; i++ )
{
ArrayGetArray( aVaultData, i, eVaultData );
if( TrieGetCell( g_tCommandToIndex, eVaultData[ SQLVEx_Key2 ], iCommandIndex ) )
{
ArrayGetArray( g_aCommands, iCommandIndex, eCommandData );
aUsageTimes = ArrayGetCell( g_aPlayerUsage[ iPlayer ], iCommandIndex );
iNumTimes = 0;
iStart = 0;
while( iNumTimes < eCommandData[ Command_iMaxUses ] && ( iPos = contain( eVaultData[ SQLVEx_Data ][ iStart ], ";" ) ) > 0 )
{
copy( szTime, min( charsmax( szTime ), iPos ), eVaultData[ SQLVEx_Data ][ iStart ] );
iTime = str_to_num( szTime );
if( ( iUnixTime - eCommandData[ Command_iMaxTime ] ) >= iTime )
{
if( iNumTimes++ )
{
ArrayInsertCellBefore( aUsageTimes, 0, iTime );
}
else
{
ArrayPushCell( aUsageTimes, iTime );
}
}
}
}
}
}
SavePlayerUsage( iPlayer, szCommand[ ], Array:aUsageTimes )
{
new szTimes[ 256 ], iLen;
for( new i = ArraySize( aUsageTimes ) - 1; i >= 0; i-- )
{
iLen += formatex( szTimes[ iLen ], charsmax( szTimes ) - iLen, "%d;", ArrayGetCell( aUsageTimes, i ) );
}
sqlv_set_data_ex( g_hVault, g_szSteamID[ iPlayer ], szCommand, szTimes );
}
Original Link : Here
|
|