|
Senior Member
Join Date: Oct 2013
Location: India
|

05-31-2015
, 11:53
Re: [REQ] Need someone to create this small easy plugin regarding knife
|
#3
|
Knife Kills Plugin v0.1 [ UNTESTED ] - ( 31/05/2015 )
PHP Code:
/*
* Declaration :
* ZOF 'X Plugins Comply With GNU General Public License.
* Knife Kills is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Under no circumstances are you allowed to redistribute and/or modify
* it claming that you are the original author of such plugin/modification.
*
* Knife Kills is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* =========================================================================
* Contact : '[email protected]' | 'facebook.com/RP.ROHIT07'
* =========================================================================
*
* Description :
* AMXX Knife Kills Plugin v0.1 By ZOF 'X ( Rohit Panchal ).
*
*
* Change Log :
* v0.1 ( 31/05/2015 ) - Initial Release ( UNTESTED ).
*
*/
#include < amxmodx >
#include < amxmisc >
#pragma semicolon 1
#define MAX_PLAYERS 32
#define MAX_BUFFER 2047
#define IsPlayer(%1) ( 1 <= %1 <= iMaxPlayers )
new const PLUGIN[ ] = "Knife Kills";
new const VERSION[ ]= "0.1";
new const AUTHOR[ ] = "ZOF 'X";
new const PREFIX[ ] = "[AMXX]";
enum _:_mPlayerData {
szAuth[ 35 ],
szName[ 32 ],
szKills,
szDeaths
};
new Array:pAuth;
new gSaveFile[ 128 ], iMaxPlayers;
new szBuffer[ MAX_BUFFER + 1 ] = 0;
new Trie:pName, Trie:pKills, Trie:pDeaths;
new gPlayerInfo[ MAX_PLAYERS + 1 ][ _mPlayerData ];
public plugin_init( ) {
register_plugin( PLUGIN, VERSION, AUTHOR );
register_cvar( "amxx_knife_kills_version", VERSION, FCVAR_SERVER );
get_datadir( gSaveFile, sizeof( gSaveFile ) - 1 );
add( gSaveFile, sizeof( gSaveFile ) - 1, "/knife_kills.ini" );
pAuth = ArrayCreate( MAX_PLAYERS, 1 );
pName = TrieCreate( );
pKills = TrieCreate( );
pDeaths = TrieCreate( );
LoadDataFile( );
ArraySort( pAuth, "SortArray" );
MakeTOP15( );
register_clcmd( "say /kniferank", "cmdShowRank" );
register_clcmd( "say /knifetop", "cmdShowTop" );
register_event( "DeathMsg", "EventDead", "a", "1>0", "4&knife" );
register_logevent( "EventRoundStart", 2, "1=Round_Start" );
}
public plugin_end( ) {
ArraySort( pAuth, "SortArray" );
SaveDataFile( );
ArrayDestroy( pAuth );
}
public client_putinserver( index ) {
get_user_name( index, gPlayerInfo[ index ][ szName ], sizeof( gPlayerInfo[ ][ szName ] ) - 1 );
get_user_authid( index, gPlayerInfo[ index ][ szAuth ], sizeof( gPlayerInfo[ ][ szAuth ] ) - 1 );
if( TrieKeyExists( pName, gPlayerInfo[ index ][ szAuth ] ) ) {
LoadData( index );
} else {
CreateData( index );
}
UpdateData( index, true );
}
public client_infochanged( index ) {
if( is_user_connected( index ) ) {
static tNewName[ MAX_PLAYERS + 1 ];
get_user_info( index, "name", tNewName, sizeof( tNewName ) - 1 );
if( equal( tNewName, gPlayerInfo[ index ][ szName ] ) ) {
return PLUGIN_HANDLED;
} else {
copy( gPlayerInfo[ index ][ szName ], sizeof( gPlayerInfo[ ][ szName ] ) - 1, tNewName );
UpdateData( index, true );
}
}
return PLUGIN_CONTINUE;
}
public cmdShowRank( index ) {
static iRank, iSize;
iRank = GetRank( index );
iSize = ArraySize( pAuth );
if( !iRank ) {
client_print( index, print_chat, "%s You are not ranked", PREFIX );
} else {
client_print( index, print_chat, "%s You're rank is %d of %d with %d kills and %d deaths", PREFIX, iRank, iSize, gPlayerInfo[ index ][ szKills ], gPlayerInfo[ index ][ szDeaths ] );
}
return PLUGIN_CONTINUE;
}
public cmdShowTop( index ) {
show_motd( index, szBuffer, "TOP 15" );
return PLUGIN_CONTINUE;
}
public EventDead( ) {
static iKiller, iVictim;
iKiller = read_data( 1 );
iVictim = read_data( 2 );
if( iKiller && IsPlayer( iKiller ) && iKiller != iVictim ) {
gPlayerInfo[ iKiller ][ szKills ]++;
UpdateData( iKiller, false );
}
if( iVictim && IsPlayer( iVictim ) ) {
gPlayerInfo[ iVictim ][ szDeaths ]++;
UpdateData( iVictim, false );
}
}
public EventRoundStart( ) {
static Players[ MAX_PLAYERS ], iNum, id;
get_players( Players, iNum );
while( --iNum >= 0 ) {
id = Players[ iNum ];
UpdateData( id, false );
}
ArraySort( pAuth, "SortArray" );
SaveDataFile( );
MakeTOP15( );
}
public SortArray( Array:aArray, iPos1, iPos2, iData[ ], iDataSize ) {
static tData1[ MAX_PLAYERS ], tData2[ MAX_PLAYERS ];
ArrayGetString( aArray, iPos1, tData1, sizeof( tData1 ) - 1 );
ArrayGetString( aArray, iPos2, tData2, sizeof( tData2 ) - 1 );
static tKills1, tKills2;
TrieGetCell( pKills, tData1, tKills1 );
TrieGetCell( pKills, tData2, tKills2 );
static tDeaths1, tDeaths2;
TrieGetCell( pDeaths, tData1, tDeaths1 );
TrieGetCell( pDeaths, tData2, tDeaths2 );
return( tKills1 - tDeaths1 > tKills2 - tDeaths2 ) ? -1 : ( ( tKills1 - tDeaths1 < tKills2 - tDeaths2 ) ? 1 : 0 );
}
LoadDataFile( ) {
static WriteFile;
WriteFile = fopen( gSaveFile, "r" );
if( !WriteFile ) return PLUGIN_HANDLED;
static tData[ 128 ], tAuth[ MAX_PLAYERS ], tName[ MAX_PLAYERS ], tKills[ 7 ], tDeaths[ 7 ];
while( !feof( WriteFile ) ) {
fgets( WriteFile, tData, sizeof( tData ) - 1 );
if( !strlen( tData ) ) {
continue;
} else {
parse( tData, tAuth, sizeof( tAuth ) - 1, tName, sizeof( tName ) - 1, tKills, sizeof( tKills ) - 1, tDeaths, sizeof( tDeaths ) - 1 );
ArrayPushString( pAuth, tAuth );
TrieSetString( pName, tAuth, tName );
TrieSetCell( pKills, tAuth, str_to_num( tKills ) );
TrieSetCell( pDeaths, tAuth, str_to_num( tDeaths ) );
}
}
fclose( WriteFile );
return PLUGIN_CONTINUE;
}
SaveDataFile( ) {
static WriteFile;
WriteFile = fopen( gSaveFile, "w+" );
if( !WriteFile ) return PLUGIN_HANDLED;
static iPosition, iSize, tAuth[ MAX_PLAYERS ], tName[ MAX_PLAYERS ], tKills, tDeaths;
iSize = ArraySize( pAuth );
for( iPosition = 0; iPosition < iSize; iPosition++ ) {
ArrayGetString( pAuth, iPosition, tAuth, sizeof( tAuth ) - 1 );
TrieGetString( pName, tAuth, tName, sizeof( tName ) - 1 );
TrieGetCell( pKills, tAuth, tKills );
TrieGetCell( pDeaths, tAuth, tDeaths );
fprintf( WriteFile, "%s ^"%s^" %d %d^n", tAuth, tName, tKills, tDeaths );
}
fclose( WriteFile );
return PLUGIN_CONTINUE;
}
CreateData( index ) {
gPlayerInfo[ index ][ szKills ] = 0;
gPlayerInfo[ index ][ szDeaths ] = 0;
ArrayPushString( pAuth, gPlayerInfo[ index ][ szAuth ] );
TrieSetString( pName, gPlayerInfo[ index ][ szAuth ], gPlayerInfo[ index ][ szName ] );
}
LoadData( index ) {
TrieGetCell( pKills, gPlayerInfo[ index ][ szAuth ], gPlayerInfo[ index ][ szKills ] );
TrieGetCell( pDeaths, gPlayerInfo[ index ][ szAuth ], gPlayerInfo[ index ][ szDeaths ] );
}
UpdateData( index, bool:tName ) {
if( tName ) {
TrieSetString( pName, gPlayerInfo[ index ][ szAuth ], gPlayerInfo[ index ][ szName ] );
} else {
TrieSetCell( pKills, gPlayerInfo[ index ][ szAuth ], gPlayerInfo[ index ][ szKills ] );
TrieSetCell( pDeaths, gPlayerInfo[ index ][ szAuth ], gPlayerInfo[ index ][ szDeaths ] );
}
}
GetRank( index ) {
static iPosition, iSize, tAuth[ MAX_PLAYERS ];
iSize = ArraySize( pAuth );
for( iPosition = 0; iPosition < iSize; iPosition++ ) {
ArrayGetString( pAuth, iPosition, tAuth, sizeof( tAuth ) );
if( equal( tAuth, gPlayerInfo[ index ][ szAuth ] ) ) {
return iPosition + 1;
}
}
return 0;
}
MakeTOP15( ) {
static iLen;
iLen = formatex( szBuffer, sizeof( szBuffer ) - 1,
"<STYLE>\
body{background:#FFFFFF;color:#4f6b72;font-family:sans-serif;font: normal 11px auto;}\
table{border-style:solid;border-width:1px;border-color:#FFFFFF;font-size:11px;font-family:sans-serif}\
th{border-right:1px solid #C1DAD7;border-bottom: 1px solid #C1DAD7;border-top:1px solid #C1DAD7;padding:8px 8px 8px;}\
td{border-right:1px solid #C1DAD7;border-bottom:1px solid #C1DAD7;padding:6px 8px 6px;}\
</STYLE>\
<table align=center width=100%% cellpadding=2 cellspacing=0 border=0>" );
iLen += formatex( szBuffer[ iLen ], sizeof( szBuffer ) - 1 - iLen,
"<tr align=left bgcolor=#CAE8EA>\
<th width=5%% align=left> # \
<th width=65%% align=left> Nick \
<th width=15%%> Kills \
<th width=15%%> Deaths" );
static iPosition, iArraySize, iSize, tAuth[ MAX_PLAYERS ], tName[ MAX_PLAYERS ], tKills, tDeaths;
iArraySize = ArraySize( pAuth );
iSize = clamp( iArraySize, 0, 15 );
for( iPosition = 0; iPosition < iSize; iPosition++ ) {
ArrayGetString( pAuth, iPosition, tAuth, sizeof( tAuth ) - 1 );
TrieGetString( pName, tAuth, tName, sizeof( tName ) - 1 );
TrieGetCell( pKills, tAuth, tKills );
TrieGetCell( pDeaths, tAuth, tDeaths );
iLen += formatex( szBuffer[ iLen ], sizeof( szBuffer ) - 1 - iLen, "<tr align=left bgcolor=#FFFFFF>" );
iLen += formatex( szBuffer[ iLen ], sizeof( szBuffer ) - 1 - iLen, "<td>%d", iPosition + 1 );
iLen += formatex( szBuffer[ iLen ], sizeof( szBuffer ) - 1 - iLen, "<td align=left>%s", tName );
iLen += formatex( szBuffer[ iLen ], sizeof( szBuffer ) - 1 - iLen, "<td>%d", tKills );
iLen += formatex( szBuffer[ iLen ], sizeof( szBuffer ) - 1 - iLen, "<td>%d", tDeaths );
}
iLen += formatex( szBuffer[ iLen ], sizeof( szBuffer ) - 1 - iLen, "</table></body>" );
}
__________________
|
|