/* Plugin generated by AMXX-Studio
Changelog
v1.0.0 - Alap ötlet megvalósítása, macerás használat, kisebb hibák.
v2.0.0 - Egész plugin újraírva, gondolva: jobb kelezhetőség, új mentés, bővíthető mellékpluginokkal.
v2.0.1 - Kisebb optimalizálások.
v2.1.0 - Pár dolog újra gondolva, fakemeta / fun modul feleslegessé vált, kivéve.
*/
#include < amxmisc >
#include < amxmodx >
#include < engine >
#include < hamsandwich >
#define IS_PLAYER(%0) ( 0 < ( %0 ) < MaxClients )
//#define SQL
#if defined SQL
#include < sqlx >
new const g_sSQL_INFOS[ ][ ] =
{
"127.0.0.1",
"USERNAME",
"PASSWORD",
"DATABASE"
}
new Handle:g_iSqlTuple;
#else
#include < nvault >
new const g_sNVAULTNAME[ ] = "PlayerDatas";
new g_iNvaultId;
#endif
enum _:ePlayerInfos
{
iPlayerLvl,
iPlayerXp,
iPlayerPoints,
iPlayerSelected
};
new const g_sPLUGIN[ ] = "KnifeSystem";
new const g_sVERSION[ ] = "2.1.0";
new const g_sAUTHOR[ ] = "Akosch:.";
new const g_sPREFIX[ ] = "[A:.]";
const g_iADD_FLAG = ADMIN_CVAR;
new Array:g_daKnives[ 10 ], Array:g_daLevels, Array:g_daItemName, Array:g_daItemAccess;
new Array:g_daItemCallback, Array:g_daItemFuncId, Array:g_daItemPluginId, Array:g_daItemCost;
new g_iPlayerInfos[ MAX_PLAYERS + 1 ][ ePlayerInfos ], g_iTarget[ MAX_PLAYERS + 1 ];
new g_sPlayerName[ MAX_PLAYERS + 1 ][ MAX_NAME_LENGTH ], g_iForwards[ 3 ];
new g_iCvarKillMsgs, g_iCvarKillPts, g_iCvarKillXp, g_iCvarHsPts, g_iCvarHsXp;
new g_iPlayerConnected, Float:g_fMap = 100.00;
public plugin_natives( )
{
register_native( "ks_register_item", "@naRegItem" );
register_native( "ks_register_item_callback", "@naRegItemCallback" );
register_native( "ks_set_player_info", "@naSetPlayerInfo" );
register_native( "ks_get_player_info", "@naGetPlayerInfo" );
register_native( "ks_get_knife_info", "@naGetKnifeInfo" );
register_native( "ks_get_max_level", "@naGetMaxLvl" );
}
public plugin_init( )
{
RegisterHam( Ham_CS_Player_ResetMaxSpeed, "player", "@fwResetMaxSpeedPost", 1, true );
RegisterHam( Ham_TakeDamage, "player", "@fwTakeDamage", 0, true );
RegisterHam( Ham_Item_Deploy, "weapon_knife", "@fwWeaponKnifePost", 1, true );
RegisterHam( Ham_Spawn, "player", "@fwPlayerSpawnPost", 1, true );
register_message( get_user_msgid( "Health" ), "@evHealthPre" );
register_event( "DeathMsg", "@evDeathPost", "a" );
register_clcmd( "drop", "@fnShowMenu" );
register_clcmd( "say /menu", "@fnShowMenu" );
register_clcmd( "GIFT", "@fnGiftHandler" );
register_clcmd( "ADD", "@fnAddHandler" );
register_concmd( "ks_add_xp", "@fnAddXp", g_iADD_FLAG, "< targetname > < xp to add >" );
g_iForwards[ 0 ] = CreateMultiForward( "ks_level_up", ET_IGNORE, FP_CELL, FP_CELL );
g_iForwards[ 1 ] = CreateMultiForward( "ks_max_lvl_reached", ET_IGNORE, FP_CELL );
g_iForwards[ 2 ] = CreateMultiForward( "ks_knife_selected", ET_IGNORE, FP_CELL, FP_CELL );
bind_pcvar_num( register_cvar( "kill_msgs", "0" ), g_iCvarKillMsgs );
bind_pcvar_num( register_cvar( "kill_xp", "1" ), g_iCvarKillXp );
bind_pcvar_num( register_cvar( "kill_point", "1" ), g_iCvarKillPts );
bind_pcvar_num( register_cvar( "hs_xp", "3" ), g_iCvarHsXp );
bind_pcvar_num( register_cvar( "hs_point", "2" ), g_iCvarHsPts );
new sMapName[ 32 ];
get_mapname( sMapName, charsmax( sMapName ) );
if ( replace( sMapName, charsmax( sMapName ), "hp", "^0" ) )
g_fMap = str_to_float( sMapName );
#if defined SQL
g_iSqlTuple = SQL_MakeDbTuple( g_sSQL_INFOS[ 0 ], g_sSQL_INFOS[ 1 ], g_sSQL_INFOS[ 2 ], g_sSQL_INFOS[ 3 ] );
new sThread[ 256 ];
formatex( sThread, charsmax( sThread ), "CREATE TABLE IF NOT EXISTS `KnifeSystem` (`SteamId` varchar( 32 ) NOT NULL, `Level` INT( 11 ) NOT NULL, `Xp` INT( 11 ) NOT NULL, `Points` INT( 11 ) NOT NULL, `Selected` INT( 11 ) NOT NULL, `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY )" );
SQL_ThreadQuery( g_iSqlTuple, "@fnThreadHandler", sThread );
#else
g_iNvaultId = nvault_open( g_sNVAULTNAME );
if ( g_iNvaultId == INVALID_HANDLE )
set_fail_state( "%L", LANG_SERVER, "INVALIDNVAULTID" )
#endif
}
public plugin_precache( )
{
register_dictionary( "KnifeSystem.txt" );
register_plugin( g_sPLUGIN, g_sVERSION, g_sAUTHOR );
g_daKnives[ 0 ] = ArrayCreate( 32 );
g_daKnives[ 1 ] = ArrayCreate( 32 );
g_daKnives[ 2 ] = ArrayCreate( 32 );
g_daKnives[ 3 ] = ArrayCreate( 1 );
g_daKnives[ 4 ] = ArrayCreate( 1 );
g_daKnives[ 5 ] = ArrayCreate( 1 );
g_daKnives[ 6 ] = ArrayCreate( 1 );
g_daKnives[ 7 ] = ArrayCreate( 1 );
g_daKnives[ 8 ] = ArrayCreate( 1 );
g_daKnives[ 9 ] = ArrayCreate( 1 );
g_daItemName = ArrayCreate( 32 );
g_daItemPluginId = ArrayCreate( 1 );
g_daItemFuncId = ArrayCreate( 1 );
g_daItemCost = ArrayCreate( 1 );
g_daItemAccess = ArrayCreate( 1 );
g_daItemCallback = ArrayCreate( 1 );
g_daLevels = ArrayCreate( 1 );
new sBuffer[ 128 ], sFile[ 64 ], pFile;
get_localinfo( "amxx_configsdir", sFile, charsmax( sFile ) );
add( sFile, charsmax( sFile ), "/knives.txt" );
pFile = fopen( sFile, "rt" );
if ( pFile )
{
new sKey[ 64 ], sValue[ 64 ], sKEYS[ sizeof ( g_daKnives ) ][ 32 ];
new iSize, iSize2, i;
new const sDefValues[ ][ ] =
{
{ "models/v_knife.mdl" }, { "models/p_knife.mdl" }
};
new const Float:fDefValues[ ] = { 250.00, 1.00, 0.00, 0.00, 0.00 };
new const iDefValues[ ] = { 255, 0 };
for ( i = 1; i < sizeof ( sKEYS ); ++i )
{
formatex( sKEYS[ i ], charsmax( sKEYS[ ] ), "KEY%i", i );
formatex( sKEYS[ i ], charsmax( sKEYS[ ] ), "%L", LANG_SERVER, sKEYS[ i ] );
}
while ( !feof( pFile ) )
{
fgets( pFile, sBuffer, charsmax( sBuffer ) );
trim( sBuffer );
if ( sBuffer[ 0 ] == '/' || sBuffer[ 0 ] == ';' || !sBuffer[ 0 ] )
continue;
if ( sBuffer[ 0 ] == '[' )
{
iSize = ArraySize( g_daKnives[ 0 ] );
for ( i = 1; i < sizeof ( g_daKnives ); ++i )
{
iSize2 = ArraySize( g_daKnives[ i ] );
if ( iSize2 < iSize )
if ( 0 < i < 3 )
ArrayPushString( g_daKnives[ i ], sDefValues[ i - 1 ] );
else if ( 2 < i < 8 )
ArrayPushCell( g_daKnives[ i ], fDefValues[ i - 3 ] );
else
ArrayPushCell( g_daKnives[ i ], iDefValues[ i - 8 ] );
else if ( iSize2 > iSize )
ArrayDeleteItem( g_daKnives[ i ], --iSize2 );
}
sBuffer[ strlen( sBuffer ) - 1 ] = EOS;
ArrayPushString( g_daKnives[ 0 ], sBuffer[ 1 ] );
continue;
}
strtok2( sBuffer, sKey, charsmax( sKey ), sValue, charsmax( sValue ), '=', TRIM_FULL );
for ( new i; i < sizeof ( g_daKnives ); ++i )
if ( equali( sKEYS[ i ], sKey ) )
switch ( i )
{
case 1, 2: fnArrayPushModel( sValue, charsmax( sValue ), i );
case 4: ArrayPushCell( g_daKnives[ i ], ( str_to_float( sValue ) / 800.00 ) );
case 8, 9: ArrayPushCell( g_daKnives[ i ], str_to_num( sValue ) );
default: ArrayPushCell( g_daKnives[ i ], str_to_float( sValue ) );
}
}
fclose( pFile );
iSize = ArraySize( g_daKnives[ 0 ] );
for ( i = 1; i < sizeof ( g_daKnives ); ++i )
{
iSize2 = ArraySize( g_daKnives[ i ] );
if ( iSize2 < iSize )
if ( 0 < i < 3 )
ArrayPushString( g_daKnives[ i ], sDefValues[ i - 1 ] );
else if ( 2 < i < 8 )
ArrayPushCell( g_daKnives[ i ], fDefValues[ i - 3 ] );
else
ArrayPushCell( g_daKnives[ i ], iDefValues[ i - 8 ] );
else if ( iSize2 > iSize )
ArrayDeleteItem( g_daKnives[ i ], iSize2 - 1 );
}
}
else
{
format( sFile, charsmax( sFile ), "%L", LANG_SERVER, "MISSINGFILE", sFile );
set_fail_state( sFile );
}
get_localinfo( "amxx_configsdir", sFile, charsmax( sFile ) );
add( sFile, charsmax( sFile ), "/levels.txt" );
pFile = fopen( sFile, "rt" );
if ( pFile )
{
new sData[ 3 ][ 16 ], iNum, iFrom, iTo, iWith, iSize;
while ( !feof( pFile ) )
{
fgets( pFile, sBuffer, charsmax( sBuffer ) );
replace( sBuffer, charsmax( sBuffer ), "^n", "" );
remove_quotes( sBuffer );
if ( is_str_num( sBuffer ) )
ArrayPushCell( g_daLevels, str_to_num( sBuffer ) );
else
{
replace( sBuffer, charsmax( sBuffer ), "...", " " );
replace( sBuffer, charsmax( sBuffer ), ",", " " );
parse( sBuffer, sData[ 0 ], charsmax( sData[ ] ), sData[ 1 ], charsmax( sData[ ] ), sData[ 2 ], charsmax( sData[ ] ) );
iFrom = str_to_num( sData[ 0 ] );
iTo = str_to_num( sData[ 1 ] );
iWith = str_to_num( sData[ 2 ] );
iSize = ArraySize( g_daLevels );
if ( iFrom > iSize )
iFrom = iSize;
iNum = ArrayGetCell( g_daLevels, iFrom - 1 );
for ( new i = iFrom; i <= iTo; ++i )
ArrayPushCell( g_daLevels, iNum += iWith );
}
}
fclose( pFile );
}
else
{
format( sFile, charsmax( sFile ), "%L", LANG_SERVER, "MISSINGFILE", sFile );
set_fail_state( sFile );
}
}
@naRegItem( iPluginId, iParamNum )
{
new sItemName[ 32 ], sItemFunc[ 32 ], iCost;
get_string( 1, sItemName, charsmax( sItemName ) );
get_string( 2, sItemFunc, charsmax( sItemFunc ) );
iCost = get_param( 3 );
if ( iCost < 0 )
iCost = 0;
ArrayPushString( g_daItemName, sItemName );
ArrayPushCell( g_daItemPluginId, iPluginId );
ArrayPushCell( g_daItemFuncId, get_func_id( sItemFunc, iPluginId ) );
ArrayPushCell( g_daItemCost, iCost );
ArrayPushCell( g_daItemAccess, get_param( 4 ) );
ArrayPushCell( g_daItemCallback, -1 );
return ( ArraySize( g_daItemCost ) - 1 );
}
@naRegItemCallback( iPluginId, iParamNum )
{
new iItemId = get_param( 1 );
if ( ArraySize( g_daItemCallback ) > iItemId )
{
ArraySetCell( g_daItemCallback, iItemId, get_param( 2 ) );
return 1;
}
return 0;
}
@naGetKnifeInfo( iPluginId, iParamNum )
if ( 2 < iParamNum < 5 )
{
new sKnifeInfo[ 32 ];
ArrayGetString( g_daKnives[ get_param( 1 ) ], get_param( 2 ), sKnifeInfo, charsmax( sKnifeInfo ) );
set_string( 3, sKnifeInfo, get_param( 4 ) );
return 1;
}
else
return ArrayGetCell( g_daKnives[ get_param( 1 ) ], get_param( 2 ) );
@naGetPlayerInfo( iPluginId, iParamNum )
return g_iPlayerInfos[ get_param( 1 ) ][ get_param( 2 ) ];
@naGetMaxLvl( iPluginId, iParamNum )
return ( ArraySize( g_daLevels ) - 1 );
@naSetPlayerInfo( iPluginId, iParamNum )
g_iPlayerInfos[ get_param( 1 ) ][ get_param( 2 ) ] = get_param( 3 );
@fwTakeDamage( iVictim, iInflictor, iAttacker, Float:fDamage, iDmgBits )
if ( IS_PLAYER( iAttacker ) && iAttacker != iVictim && get_user_weapon( iAttacker ) == CSW_KNIFE )
{
fDamage += Float:ArrayGetCell( g_daKnives[ 5 ], g_iPlayerInfos[ iAttacker ][ iPlayerSelected ] );
SetHamParamFloat( 4, fDamage );
new Float:fKB = Float:ArrayGetCell( g_daKnives[ 6 ], g_iPlayerInfos[ iAttacker ][ iPlayerSelected ] );
if ( fKB )
fnCreateKnockback( iVictim, iAttacker, fKB + fDamage );
}
@fwWeaponKnifePost( iEnt )
{
new iOwner = entity_get_edict( iEnt, EV_ENT_owner );
if ( iOwner )
{
new sModels[ 32 ];
ArrayGetString( g_daKnives[ 1 ], g_iPlayerInfos[ iOwner ][ iPlayerSelected ], sModels, charsmax( sModels ) );
entity_set_string( iOwner, EV_SZ_viewmodel, sModels );
ArrayGetString( g_daKnives[ 2 ], g_iPlayerInfos[ iOwner ][ iPlayerSelected ], sModels, charsmax( sModels ) );
entity_set_string( iOwner, EV_SZ_weaponmodel, sModels );
}
}
@fwPlayerSpawnPost( iPlayerId )
if ( is_user_alive( iPlayerId ) )
switch ( g_fMap )
{
case 1.0: set_task( 2.5, "@fnSpawnSettings", iPlayerId );
case 35.0: set_task( 2.0, "@fnSpawnSettings", iPlayerId );
default: @fnSpawnSettings( iPlayerId );
}
@fwResetMaxSpeedPost( iPlayerId )
if ( is_user_alive( iPlayerId ) && entity_get_float( iPlayerId, EV_FL_maxspeed ) > 1.0 )
entity_set_float( iPlayerId, EV_FL_maxspeed, Float:ArrayGetCell( g_daKnives[ 3 ], g_iPlayerInfos[ iPlayerId ][ iPlayerSelected ] ) );
//Bugfix
@fnSpawnSettings( iPlayerId )
{
entity_set_float( iPlayerId, EV_FL_health, g_fMap + Float:ArrayGetCell( g_daKnives[ 7 ], g_iPlayerInfos[ iPlayerId ][ iPlayerSelected ] ) );
set_rendering( iPlayerId, kRenderFxGlowShell ,0, 0, 0, kRenderTransAlpha, ArrayGetCell( g_daKnives[ 8 ], g_iPlayerInfos[ iPlayerId ][ iPlayerSelected ] ) );
entity_set_float( iPlayerId, EV_FL_gravity, Float:ArrayGetCell( g_daKnives[ 4 ], g_iPlayerInfos[ iPlayerId ][ iPlayerSelected ] ) );
}
// Bugfix
@evHealthPre( iMsgId, iMsgDest, iMsgEnt )
{
new iHp = get_msg_arg_int( 1 );
if ( iHp > 256 )
{
if ( iHp % 256 == 0 )
iHp > 0 ? entity_set_float( iMsgEnt, EV_FL_health, entity_get_float( iMsgEnt, EV_FL_health ) + 1.0 ) : user_kill( iMsgEnt );
set_msg_arg_int( 1, get_msg_argtype( 1 ), 255 );
}
}
@evDeathPost( )
{
new iKiller = read_data( 1 );
if ( IS_PLAYER( iKiller ) && g_iPlayerConnected & ( 1 << ( iKiller & 31 ) ) )
{
new iVictim = read_data( 2 );
new iHs = read_data( 3 );
new iXp, iPoint;
iXp = iHs ? g_iCvarHsXp : g_iCvarKillXp;
iPoint = iHs ? g_iCvarHsPts : g_iCvarKillPts;
g_iPlayerInfos[ iKiller ][ iPlayerXp ] += iXp;
g_iPlayerInfos[ iKiller ][ iPlayerPoints ] += iPoint;
switch ( g_iCvarKillMsgs )
{
case 1: client_print_color( iKiller, iKiller, "%L", LANG_SERVER, "KILLMSGKILLER", g_sPlayerName[ iVictim ], iXp, iPoint );
case 2:
{
client_print_color( iKiller, iKiller, "%L", LANG_SERVER, "KILLMSGKILLER", g_sPlayerName[ iVictim ], iXp, iPoint );
client_print_color( iVictim, iVictim, "%L", LANG_SERVER, "KILLMSGVICTIM", g_sPlayerName[ iKiller ] );
}
}
}
fnCheckLevel( iKiller );
}
@fnShowMenu( iPlayerId )
fnMainMenu( iPlayerId, 0 );
fnMainMenu( iPlayerId, iMenu )
{
new sMenu[ 78 ], sInfo[ 16 ], iMenuId;
switch ( iMenu )
{
case 0:
{
formatex( sMenu, charsmax( sMenu ), "%L", LANG_SERVER, "MENU0", g_iPlayerInfos[ iPlayerId ][ iPlayerLvl ], g_iPlayerInfos[ iPlayerId ][ iPlayerXp ], ArrayGetCell( g_daLevels, g_iPlayerInfos[ iPlayerId ][ iPlayerLvl ] ), g_iPlayerInfos[ iPlayerId ][ iPlayerPoints ] );
iMenuId = menu_create( sMenu, "@fnMenuHandler" );
if ( ArraySize( g_daKnives[ 0 ] ) )
{
formatex( sMenu, charsmax( sMenu ), "%L", LANG_SERVER, "KNIFEMENU" );
menu_additem( iMenuId, sMenu, "1 0" );
}
formatex( sMenu, charsmax( sMenu ), "%L", LANG_SERVER, "GIFTINGMENU" );
menu_additem( iMenuId, sMenu, "2 0" );
if ( ArraySize( g_daItemCost ) )
{
formatex( sMenu, charsmax( sMenu ), "%L", LANG_SERVER, "SHOPMENU" );
menu_additem( iMenuId, sMenu, "3 0" );
}
formatex( sMenu, charsmax( sMenu ), "%L", LANG_SERVER, "PLAYERSMENU" );
menu_additem( iMenuId, sMenu, "4 0" );
formatex( sMenu, charsmax( sMenu ), "%L", LANG_SERVER, "ADDINGMENU" );
menu_additem( iMenuId, sMenu, "5 0", g_iADD_FLAG );
}
case 1:
{
formatex( sMenu, charsmax( sMenu ), "%L", LANG_SERVER, "MENU1", g_iPlayerInfos[ iPlayerId ][ iPlayerLvl ], g_iPlayerInfos[ iPlayerId ][ iPlayerXp ], ArrayGetCell( g_daLevels, g_iPlayerInfos[ iPlayerId ][ iPlayerLvl ] ) );
iMenuId = menu_create( sMenu, "@fnMenuHandler" );
new iSize = ArraySize( g_daKnives[ 0 ] );
for ( new i; i < iSize; ++i )
{
formatex( sMenu, charsmax( sMenu ), "%L", LANG_SERVER, "KNIVES", ArrayGetStringHandle( g_daKnives[ 0 ], i ), ArrayGetCell( g_daKnives[ 9 ], i ) );
formatex( sInfo, charsmax( sInfo ), "%i 1", i );
menu_additem( iMenuId, sMenu, sInfo );
}
}
case 2:
{
formatex( sMenu, charsmax( sMenu ), "%L", LANG_SERVER, "MENU2", g_iPlayerInfos[ iPlayerId ][ iPlayerPoints ] );
iMenuId = menu_create( sMenu, "@fnMenuHandler" );
for ( new i; i < MaxClients; ++i )
if ( g_iPlayerConnected & ( 1 << ( i & 31 ) ) && iPlayerId != i )
{
formatex( sInfo, charsmax( sInfo ), "%i 2", i );
menu_additem( iMenuId, g_sPlayerName[ i ], sInfo );
}
}
case 3:
{
formatex( sMenu, charsmax( sMenu ), "%L", LANG_SERVER, "MENU3", g_iPlayerInfos[ iPlayerId ][ iPlayerPoints ] );
iMenuId = menu_create( sMenu, "@fnMenuHandler" );
new iSize = ArraySize( g_daItemCost );
for ( new i; i < iSize; ++i )
{
ArrayGetString( g_daItemName, i, sMenu, charsmax( sMenu ) );
formatex( sInfo, charsmax( sInfo ), "%i 3", i );
menu_additem( iMenuId, sMenu, sInfo, ArrayGetCell( g_daItemAccess, i ), ArrayGetCell( g_daItemCallback, i ) );
}
}
case 4:
{
formatex( sMenu, charsmax( sMenu ), "%L", LANG_SERVER, "MENU4", g_iPlayerInfos[ iPlayerId ][ iPlayerLvl ], g_iPlayerInfos[ iPlayerId ][ iPlayerXp ], ArrayGetCell( g_daLevels, g_iPlayerInfos[ iPlayerId ][ iPlayerLvl ] ), g_iPlayerInfos[ iPlayerId ][ iPlayerPoints ] );
iMenuId = menu_create( sMenu, "@fnMenuHandler" );
for ( new i; i < MaxClients; ++i )
if ( g_iPlayerConnected & ( 1 << ( i & 31 ) ) && iPlayerId != i )
{
formatex( sMenu, charsmax( sMenu ), "%L", LANG_SERVER, "PLAYERINMENU", g_sPlayerName[ i ], g_iPlayerInfos[ i ][ iPlayerLvl ], g_iPlayerInfos[ i ][ iPlayerXp ], ArrayGetCell( g_daLevels, g_iPlayerInfos[ i ][ iPlayerLvl ] ), g_iPlayerInfos[ i ][ iPlayerPoints ] );
formatex( sInfo, charsmax( sInfo ), "%i 4", i );
menu_additem( iMenuId, sMenu, sInfo );
}
}
case 5:
{
formatex( sMenu, charsmax( sMenu ), "%L", LANG_SERVER, "MENU5" );
iMenuId = menu_create( sMenu, "@fnMenuHandler" );
for ( new i; i < MaxClients; ++i )
if ( g_iPlayerConnected & ( 1 << ( i & 31 ) ) )
{
formatex( sInfo, charsmax( sInfo ), "%i 5", i );
menu_additem( iMenuId, g_sPlayerName[ i ], sInfo );
}
}
}
menu_display( iPlayerId, iMenuId, 0 );
}
@fnMenuHandler( iPlayerId, iMenuId, iItem )
{
if ( iItem != MENU_EXIT )
{
new sMenuName[ 78 ], sInfo[ 32 ], sDatas[ 2 ][ 16 ], iKey, iMenuNum;
menu_item_getinfo( iMenuId, iItem, iKey, sInfo, charsmax( sInfo ), sMenuName, charsmax( sMenuName ), iMenuNum );
parse( sInfo, sDatas[ 0 ], charsmax( sDatas[ ] ), sDatas[ 1 ], charsmax( sDatas[ ] ) );
iKey = str_to_num( sDatas[ 0 ] );
iMenuNum = str_to_num( sDatas[ 1 ] );
switch ( iMenuNum )
{
case 0:
{
fnMainMenu( iPlayerId, iKey );
}
case 1:
{
if ( g_iPlayerInfos[ iPlayerId ][ iPlayerLvl ] >= ArrayGetCell( g_daKnives[ 9 ], iKey ) )
{
new iRet;
g_iPlayerInfos[ iPlayerId ][ iPlayerSelected ] = iKey;
ExecuteForward( g_iForwards[ 2 ], iRet, iPlayerId, g_iPlayerInfos[ iPlayerId ][ iPlayerSelected ] );
if ( get_user_weapon( iPlayerId ) == CSW_KNIFE )
{
ArrayGetString( g_daKnives[ 1 ], g_iPlayerInfos[ iPlayerId ][ iPlayerSelected ], sMenuName, charsmax( sMenuName ) );
entity_set_string( iPlayerId, EV_SZ_viewmodel, sMenuName );
ArrayGetString( g_daKnives[ 2 ], g_iPlayerInfos[ iPlayerId ][ iPlayerSelected ], sMenuName, charsmax( sMenuName ) );
entity_set_string( iPlayerId, EV_SZ_weaponmodel, sMenuName );
}
set_rendering( iPlayerId, kRenderFxGlowShell ,0, 0, 0, kRenderTransAlpha, ArrayGetCell( g_daKnives[ 8 ], g_iPlayerInfos[ iPlayerId ][ iPlayerSelected ] ) );
entity_set_float( iPlayerId, EV_FL_gravity, Float:ArrayGetCell( g_daKnives[ 4 ], g_iPlayerInfos[ iPlayerId ][ iPlayerSelected ] ) );
if ( entity_get_float( iPlayerId, EV_FL_maxspeed ) > 1.0 )
entity_set_float( iPlayerId, EV_FL_maxspeed, Float:ArrayGetCell( g_daKnives[ 3 ], g_iPlayerInfos[ iPlayerId ][ iPlayerSelected ] ) );
}
else
client_print_color( iPlayerId, iPlayerId, "%L", LANG_SERVER, "NOTENOUGHLVL", g_sPREFIX );
}
case 2:
{
if ( g_iPlayerConnected & ( 1 << ( iKey & 31 ) ) )
{
g_iTarget[ iPlayerId ] = iKey;
client_cmd( iPlayerId, "messagemode GIFT" );
}
else
{
client_print_color( iPlayerId, iPlayerId, "%L", LANG_SERVER, "TARGETDISCONNECTED", g_sPREFIX );
fnMainMenu( iPlayerId, 2 );
}
}
case 3:
{
if ( g_iPlayerInfos[ iPlayerId ][ iPlayerPoints ] >= ArrayGetCell( g_daItemCost, iKey ) )
{
g_iPlayerInfos[ iPlayerId ][ iPlayerPoints ] -= ArrayGetCell( g_daItemCost, iKey );
callfunc_begin_i( ArrayGetCell( g_daItemFuncId, iKey ), ArrayGetCell( g_daItemPluginId, iKey ) );
callfunc_push_int( iPlayerId );
callfunc_push_int( iKey );
callfunc_end( );
client_print_color( iPlayerId, iPlayerId, "%L", LANG_SERVER, "SUCCPURCHASE", g_sPREFIX, ArrayGetStringHandle( g_daItemName, iKey ) );
}
else
client_print_color( iPlayerId, iPlayerId, "%L", LANG_SERVER, "UNSUCCPURCHASE", g_sPREFIX );
}
case 4:
{
if ( g_iPlayerConnected & ( 1 << ( iKey & 31 ) ) )
client_print_color( iPlayerId, iPlayerId, "%L", LANG_SERVER, "PLAYERINMENU", g_sPlayerName[ iKey ], g_iPlayerInfos[ iKey ][ iPlayerLvl ], g_iPlayerInfos[ iKey ][ iPlayerXp ], ArrayGetCell( g_daLevels, g_iPlayerInfos[ iKey ][ iPlayerLvl ] ) );
else
{
client_print_color( iPlayerId, iPlayerId, "%L", LANG_SERVER, "TARGETDISCONNECTED", g_sPREFIX );
fnMainMenu( iPlayerId, 4 );
}
}
case 5:
{
if ( g_iPlayerConnected & ( 1 << ( iKey & 31 ) ) )
{
g_iTarget[ iPlayerId ] = iKey;
client_cmd( iPlayerId, "messagemode ADD" );
}
else
{
client_print_color( iPlayerId, iPlayerId, "%L", LANG_SERVER, "TARGETDISCONNECTED", g_sPREFIX );
fnMainMenu( iPlayerId, 5 );
}
}
}
}
menu_destroy( iMenuId );
return PLUGIN_HANDLED;
}
@fnGiftHandler( iPlayerId )
{
new sData[ 191 ], iNum;
read_args( sData, charsmax( sData ) );
remove_quotes( sData );
if ( is_str_num( sData ) )
{
iNum = str_to_num( sData );
if ( g_iPlayerInfos[ iPlayerId ][ iPlayerPoints ] >= iNum )
{
g_iPlayerInfos[ g_iTarget[ iPlayerId ] ][ iPlayerPoints ] += iNum;
g_iPlayerInfos[ iPlayerId ][ iPlayerPoints ] -= iNum;
client_print_color( iPlayerId, iPlayerId, "%L", LANG_SERVER, "SUCCGIFTING", g_sPREFIX, g_sPlayerName[ g_iTarget [ iPlayerId ] ], iNum );
client_print_color( g_iTarget[ iPlayerId ], g_iTarget[ iPlayerId ], "%L", LANG_SERVER, "GETPOINTS", g_sPREFIX, iNum, g_sPlayerName[ iPlayerId ] );
}
else
client_print_color( iPlayerId, iPlayerId, "%L", LANG_SERVER, "NOTENOUGHPOINT", g_sPREFIX );
}
else
{
client_print_color( iPlayerId, iPlayerId, "%L", LANG_SERVER, "INVALIDVALUE", g_sPREFIX );
client_cmd( iPlayerId, "messagemode GIFT" );
}
}
@fnAddHandler( iPlayerId )
{
new sData[ 191 ], iNum;
read_args( sData, charsmax( sData ) );
remove_quotes( sData );
if ( is_str_num( sData ) )
{
iNum = str_to_num( sData );
g_iPlayerInfos[ g_iTarget[ iPlayerId ] ][ iPlayerPoints ] += iNum;
client_print_color( 0, print_team_default, "%L", LANG_SERVER, "ADDTEXT", g_sPREFIX, g_sPlayerName[ iPlayerId ], g_sPlayerName[ g_iTarget[ iPlayerId ] ], iNum );
}
else
{
client_print_color( iPlayerId, iPlayerId, "%L", LANG_SERVER, "INVALIDVALUE", g_sPREFIX );
client_cmd( iPlayerId, "messagemode ADD" );
}
}
@fnAddXp( iPlayerId, iAdminLevel, iCommandId )
if ( cmd_access( iPlayerId, iAdminLevel, iCommandId, 2 ) )
{
new sArg[ 32 ], sXp[ 11 ];
read_argv( 1, sArg, charsmax( sArg ) );
read_argv( 2, sXp, charsmax( sXp ) );
new iTarget = cmd_target( iPlayerId, sArg, CMDTARGET_ALLOW_SELF | CMDTARGET_NO_BOTS );
g_iPlayerInfos[ iTarget ][ iPlayerXp ] += str_to_num( sXp );
fnCheckLevel( iTarget );
}
public client_infochanged( iPlayerId )
{
new sNewName[ 32 ];
get_user_info( iPlayerId, "name", sNewName, charsmax( sNewName ) );
if ( !equal( g_sPlayerName[ iPlayerId ], sNewName ) )
{
g_sPlayerName[ iPlayerId ][ 0 ] = EOS;
copy( g_sPlayerName[ iPlayerId ], charsmax( g_sPlayerName[ ] ), sNewName );
}
}
public client_authorized( iPlayerId, const sSteamId[ ] )
if ( sSteamId[ 0 ] != 'B' ) // If client is a bot, then sSteamId equal with "BOT"
{
g_iPlayerConnected |= ( 1 << ( iPlayerId & 31 ) )
get_user_name( iPlayerId, g_sPlayerName[ iPlayerId ], charsmax( g_sPlayerName[ ] ) );
fnLoadPlayerDatas( iPlayerId, sSteamId );
}
public client_disconnect( iPlayerId )
if ( !is_user_bot( iPlayerId ) )
{
new sSteamId[ 32 ];
get_user_authid( iPlayerId, sSteamId, charsmax( sSteamId ) );
g_iPlayerConnected &= ~( 1 << ( iPlayerId & 31 ) )
#if defined SQL
fnSavePlayerDatas( iPlayerId, sSteamId, 0 );
#else
fnSavePlayerDatas( iPlayerId, sSteamId );
#endif
}
#if defined SQL
fnLoadPlayerDatas( iPlayerId, const sSteamId[ ] )
{
static sText[ 128 ], iArray[ 1 ];
iArray[ 0 ] = iPlayerId;
formatex( sText, charsmax( sText ), "SELECT * FROM `KnifeSystem` WHERE SteamId = ^"%s^"", sSteamId );
SQL_ThreadQuery( g_iSqlTuple, "@fnThreadHandler", sText, iArray, sizeof ( iArray ) );
}
fnSavePlayerDatas( iPlayerId, const sSteamId[ ], iMode )
{
static sText[ 512 ];
if ( iMode )
formatex( sText, charsmax( sText ), "INSERT INTO `KnifeSystem` ( `SteamId`,`Level`,`Xp`,`Points`,`Selected` ) VALUES ( ^"%s^", ^"0^", ^"0^", ^"0^", ^"0^" )", sSteamId );
else
formatex( sText, charsmax( sText ), "UPDATE `KnifeSystem` SET Level = ^"%i^" Xp = ^"%i^" Points = ^"%i^" Selected = ^"%i^" WHERE SteamId = ^"%s^"", g_iPlayerInfos[ iPlayerId ][ iPlayerLvl ], g_iPlayerInfos[ iPlayerId ][ iPlayerXp ], g_iPlayerInfos[ iPlayerId ][ iPlayerPoints ], g_iPlayerInfos[ iPlayerId ][ iPlayerSelected ], sSteamId );
SQL_ThreadQuery( g_iSqlTuple, "@fnThreadHandler", sText );
}
@fnThreadHandler( iFailState, Handle:iQuery, const sErrorMsg[ ], iErrorCode, const iARRAY[ ], iArraySize, Float:fQueueTime )
{
new sText[ 128 ];
if ( iFailState == TQUERY_CONNECT_FAILED )
{
formatex( sText, charsmax( sText ), "%L", LANG_SERVER, "TQUERY_CONNECT_FAILED" );
set_fail_state( sText );
return;
}
else if ( iFailState == TQUERY_QUERY_FAILED )
{
formatex( sText, charsmax( sText ), "%L", LANG_SERVER, "TQUERY_QUERY_FAILED" );
set_fail_state( sText );
return;
}
if ( iErrorCode )
{
log_amx( "%i - %s", iErrorCode, sErrorMsg );
return;
}
if ( iArraySize )
{
new iPlayerId = iARRAY[ 0 ];
if ( iPlayerId )
if ( SQL_NumResults( iQuery ) > 0 )
{
g_iPlayerInfos[ iPlayerId ][ iPlayerSelected ] = SQL_ReadResult( iQuery, SQL_FieldNameToNum( iQuery, "Selected" ) );
g_iPlayerInfos[ iPlayerId ][ iPlayerPoints ] = SQL_ReadResult( iQuery, SQL_FieldNameToNum( iQuery, "Points" ) );
g_iPlayerInfos[ iPlayerId ][ iPlayerLvl ] = SQL_ReadResult( iQuery, SQL_FieldNameToNum( iQuery, "Level" ) );
g_iPlayerInfos[ iPlayerId ][ iPlayerXp ] = SQL_ReadResult( iQuery, SQL_FieldNameToNum( iQuery, "Xp" ) );
}
else
{
new sSteamId[ 32 ];
arrayset( g_iPlayerInfos[ iPlayerId ], 0, sizeof ( g_iPlayerInfos[ ] ) );
get_user_authid( iPlayerId, sSteamId, charsmax( sSteamId ) );
fnSavePlayerDatas( iPlayerId, sSteamId, 1 );
}
}
return;
}
#else
fnLoadPlayerDatas( iPlayerId, const sSteamId[ ] )
{
new sData[ 51 ];
if ( nvault_get( g_iNvaultId, sSteamId, sData, charsmax( sData ) ) )
{
new sLevel[ 11 ], sXp[ 11 ], sPoints[ 11 ], sSelected[ 11 ];
parse( sData, sLevel, charsmax( sLevel ), sXp, charsmax( sXp ), sPoints, charsmax( sPoints ), sSelected, charsmax( sSelected ) );
g_iPlayerInfos[ iPlayerId ][ iPlayerLvl ] = str_to_num( sLevel );
g_iPlayerInfos[ iPlayerId ][ iPlayerXp ] = str_to_num( sXp );
g_iPlayerInfos[ iPlayerId ][ iPlayerPoints ] = str_to_num( sPoints );
g_iPlayerInfos[ iPlayerId ][ iPlayerSelected ] = str_to_num( sSelected );
}
else
arrayset( g_iPlayerInfos[ iPlayerId ], 0, sizeof ( g_iPlayerInfos[ ] ) );
}
fnSavePlayerDatas( iPlayerId, const sSteamId[ ] )
{
new sData[ 51 ];
formatex( sData, charsmax( sData ), " %i %i %i %i ", g_iPlayerInfos[ iPlayerId ][ iPlayerLvl ], g_iPlayerInfos[ iPlayerId ][ iPlayerXp ], g_iPlayerInfos[ iPlayerId ][ iPlayerPoints ], g_iPlayerInfos[ iPlayerId ][ iPlayerSelected ] );
nvault_set( g_iNvaultId, sSteamId, sData );
}
#endif
fnArrayPushModel( sMdl[ ], iMdl, iArrayId )
{
if ( !equal( sMdl, "models/", 7 ) )
format( sMdl, iMdl, "models/%s", sMdl );
if ( !equal( sMdl[ strlen( sMdl ) - 4 ], ".mdl", 4 ) )
add( sMdl, iMdl, ".mdl" );
precache_model( sMdl );
ArrayPushString( g_daKnives[ iArrayId ], sMdl );
}
fnCheckLevel( iPlayerId )
{
new iMax = ArraySize( g_daLevels ) - 1;
if ( g_iPlayerInfos[ iPlayerId ][ iPlayerLvl ] < iMax )
{
new iRet;
while ( g_iPlayerInfos[ iPlayerId ][ iPlayerXp ] >= ArrayGetCell( g_daLevels, g_iPlayerInfos[ iPlayerId ][ iPlayerLvl ] ) )
{
++g_iPlayerInfos[ iPlayerId ][ iPlayerLvl ];
ExecuteForward( g_iForwards[ 0 ], iRet, iPlayerId, g_iPlayerInfos[ iPlayerId ][ iPlayerLvl ] );
if ( g_iPlayerInfos[ iPlayerId ][ iPlayerLvl ] == iMax )
{
ExecuteForward( g_iForwards[ 1 ], iRet, iPlayerId );
break;
}
}
}
}
// Credits to ConnorMcLeod ( conorr )
fnCreateKnockback( iVictim, iAttacker, Float:fKB )
{
new Float:fVictimO[ 3 ], Float:fAttackerO[ 3 ], Float:fVictimV[ 3 ], Float:fValue;
entity_get_vector( iVictim, EV_VEC_origin, fVictimO );
entity_get_vector( iAttacker, EV_VEC_origin, fAttackerO );
fVictimO[ 0 ] -= fAttackerO[ 0 ];
fVictimO[ 1 ] -= fAttackerO[ 1 ];
fVictimO[ 2 ] -= fAttackerO[ 2 ];
fValue = 1.0 / floatsqroot( fVictimO[0] * fVictimO[0] + fVictimO[1] * fVictimO[1] + fVictimO[2] * fVictimO[2] );
fVictimO[ 0 ] *= fValue;
fVictimO[ 1 ] *= fValue;
fVictimO[ 2 ] *= fValue;
entity_get_vector( iVictim, EV_VEC_velocity, fVictimV );
fVictimO[ 0 ] *= fKB
fVictimO[ 1 ] *= fKB
fVictimO[ 2 ] *= fKB
fVictimV[ 0 ] += fVictimO[ 0 ];
fVictimV[ 1 ] += fVictimO[ 1 ];
fVictimV[ 2 ] += fVictimO[ 2 ];
entity_set_vector( iVictim, EV_VEC_velocity, fVictimV );
}
//
public plugin_end( )
{
for ( new i; i < sizeof ( g_daKnives ); ++i )
ArrayDestroy( g_daKnives[ i ] );
ArrayDestroy( g_daItemCost );
ArrayDestroy( g_daItemAccess );
ArrayDestroy( g_daItemCallback );
ArrayDestroy( g_daItemFuncId );
ArrayDestroy( g_daItemName );
ArrayDestroy( g_daItemPluginId );
ArrayDestroy( g_daLevels );
#if defined SQL
SQL_FreeHandle( g_iSqlTuple );
#else
nvault_close( g_iNvaultId );
#endif
}