Raised This Month: $51 Target: $400
 12% 

Plugin Request


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Obada
Senior Member
Join Date: Dec 2014
Location: Abu Dhabi
Old 01-06-2015 , 13:54   Plugin Request
Reply With Quote #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] View Post
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_aPlayerUsageMAX_PLAYERS ];

new 
g_szSteamIDMAX_PLAYERS ][ 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 ArrayCreateCommandData );
    
g_tCommandToIndex TrieCreate( );
    
    new 
iMaxPlayers get_maxplayers( );
    
    for( new 
iPlayer 1iPlayer <= iMaxPlayersiPlayer++ )
    {
        
g_aPlayerUsageiPlayer ] = ArrayCreate( );
    }
    
    
g_hVault sqlv_open_local"command_limiter"false );
    
    if( !
sqlv_init_exg_hVault ) )
    {
        
set_fail_state"Error opening SQLVault" );
    }
    
    
sqlv_connectg_hVault );
    
    
LoadCommandsiMaxPlayers );
}

public 
plugin_end( )
{
    
sqlv_closeg_hVault );
}

public 
client_authorizediPlayer )
{
    
get_user_authidiPlayerg_szSteamIDiPlayer ], charsmaxg_szSteamID[ ] ) );
    
    
LoadPlayerUsageiPlayer );
}

public 
client_disconnectiPlayer )
{
    for( new 
iCommandIndex 0iCommandIndex g_iNumCommandsiCommandIndex++ )
    {
        
ArrayClearArrayGetCellg_aPlayerUsageiPlayer ], iCommandIndex ) );
    }
}

public 
client_commandiPlayer )
{
    if( 
accessiPlayerGetFlag( ) ) )
    {
        static 
szCommandMAX_COMMAND_SIZE ];
        
read_argv0szCommandcharsmaxszCommand ) );
        
strtolowerszCommand );
        
        new 
iCommandIndex;
        
        if( 
TrieGetCellg_tCommandToIndexszCommandiCommandIndex ) )
        {
            static 
eCommandDataCommandData ];
            
ArrayGetArrayg_aCommandsiCommandIndexeCommandData );
            
            new Array:
aUsageTimes ArrayGetCellg_aPlayerUsageiPlayer ], iCommandIndex );
            
            new 
iTotalUsage ArraySizeaUsageTimes );
            
            new 
iUnixTime get_systime( );
            
            new 
bool:bUpdate;
            
            while( 
iTotalUsage && ( iUnixTime eCommandDataCommand_iMaxTime ] ) >= ArrayGetCellaUsageTimes) )
            {
                
ArrayDeleteItemaUsageTimes);
                
                
iTotalUsage--;
                
                
bUpdate true;
            }
            
            if( 
iTotalUsage eCommandDataCommand_iMaxUses ] )
            {
                
ArrayPushCellaUsageTimesiUnixTime );
                
                
SavePlayerUsageiPlayerszCommandaUsageTimes );
            }
            else
            {
                if( 
bUpdate )
                {
                    
SavePlayerUsageiPlayerszCommandaUsageTimes );
                }
                
                return 
PLUGIN_HANDLED;
            }
        }
    }
    
    return 
PLUGIN_CONTINUE;
}

LoadCommandsiMaxPlayers )
{
    new 
szFile64 ];
    
get_configsdirszFilecharsmaxszFile ) );
    
addszFilecharsmaxszFile ), "/command_limiter.ini" );
    
    new 
pFile fopenszFile"rt" );
    
    if( 
pFile )
    {
        new 
szLine128 ];
        
        new 
szCommandMAX_COMMAND_SIZE ];
        new 
szMaxUses12 ];
        new 
szMaxTime12 ];
        
        new 
eCommandDataCommandData ];
        
        new 
iPlayer;
        
        while( !
feofpFile ) )
        {
            
fgetspFileszLinecharsmaxszLine ) );
            
trimszLine );
            
            if( !
szLine] || szLine] == ';' || szLine] == '/' && szLine] == '/' )
            {
                continue;
            }
            
            
parseszLineszCommandcharsmaxszCommand ), szMaxUsescharsmaxszMaxUses ), szMaxTimecharsmaxszMaxTime ) );
            
            
strtolowerszCommand );
            
            if( 
TrieKeyExistsg_tCommandToIndexszCommand ) )
            {
                continue;
            }
            
            
eCommandDataCommand_iMaxUses ] = str_to_numszMaxUses );
            
eCommandDataCommand_iMaxTime ] = str_to_numszMaxTime );
            
            
ArrayPushArrayg_aCommandseCommandData );
            
            
TrieSetCellg_tCommandToIndexszCommandg_iNumCommands );
            
            for( 
iPlayer 1iPlayer <= iMaxPlayersiPlayer++ )
            {
                
ArrayPushCellg_aPlayerUsageiPlayer ], ArrayCreate( ) );
            }
            
            
g_iNumCommands++;
        }
        
        
fclosepFile );
    }
}

GetFlag( )
{
    new 
szFlags];
    
get_pcvar_stringg_pCvarFlagszFlagscharsmaxszFlags ) );
    
    return 
read_flagsszFlags );
}

LoadPlayerUsageiPlayer )
{
    new 
szWhere64 ];
    
formatexszWherecharsmaxszWhere ), "`key1` = '%s'"g_szSteamIDiPlayer ] );
    
    new Array:
aVaultData;
    new 
iNumEntries sqlv_read_all_exg_hVaultaVaultDataszWhere"`key2` ASC" );
    
    new 
eVaultDataSQLVaultEntryEx ];
    
    new 
iCommandIndex;
    new 
eCommandDataCommandData ];
    
    new Array:
aUsageTimes;
    new 
iNumTimes;
    
    new 
iStartiPos;
    new 
szTime12 ], iTime;
    
    new 
iUnixTime get_systime( );
    
    for( new 
0iNumEntriesi++ )
    {
        
ArrayGetArrayaVaultDataieVaultData );
        
        if( 
TrieGetCellg_tCommandToIndexeVaultDataSQLVEx_Key2 ], iCommandIndex ) )
        {
            
ArrayGetArrayg_aCommandsiCommandIndexeCommandData );
            
            
aUsageTimes ArrayGetCellg_aPlayerUsageiPlayer ], iCommandIndex );
            
iNumTimes 0;
            
            
iStart 0;
            
            while( 
iNumTimes eCommandDataCommand_iMaxUses ] && ( iPos containeVaultDataSQLVEx_Data ][ iStart ], ";" ) ) > )
            {
                
copyszTimemincharsmaxszTime ), iPos ), eVaultDataSQLVEx_Data ][ iStart ] );
                
                
iTime str_to_numszTime );
                
                if( ( 
iUnixTime eCommandDataCommand_iMaxTime ] ) >= iTime )
                {
                    if( 
iNumTimes++ )
                    {
                        
ArrayInsertCellBeforeaUsageTimes0iTime );
                    }
                    else
                    {
                        
ArrayPushCellaUsageTimesiTime );
                    }
                }
            }
        }
    }
}

SavePlayerUsageiPlayerszCommand[ ], Array:aUsageTimes )
{
    new 
szTimes256 ], iLen;
    
    for( new 
ArraySizeaUsageTimes ) - 1>= 0i-- )
    {
        
iLen += formatexszTimesiLen ], charsmaxszTimes ) - iLen"%d;"ArrayGetCellaUsageTimes) );
    }
    
    
sqlv_set_data_exg_hVaultg_szSteamIDiPlayer ], szCommandszTimes );


Original Link : Here
Obada 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 23:49.


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