Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <amxmodx>
- #include <amxmisc>
- #include <fvault>
- #include <engine>
- #include <cstrike>
- #include <fun>
- #define PLUGIN "Knife System"
- #define VERSION "1.0"
- #define AUTHOR "@.Hacker-`"
- #define Prefix "Replay"
- native hnr_set_user_credits( id, amount );
- native hnr_get_user_credits( id );
- new Currect[ 33 ], Knife[ 33 ], UseKnife[ 33 ];
- new bool:uGetCash[ 33 ];
- enum _:info{
- Name[ 33 ],
- Price,
- GetCash
- }
- new const szKnife[ ][ info ] =
- {
- { "Normal Knife", 0, 25 },
- { "Knife #1", 10000, 50 },
- { "Knife #2", 15000, 75 }
- }
- new const v_KnifeModels[ 3 ][ ] =
- {
- "models/v_knife.mdl",
- "models/ReplayHnr/Knivess/v_knife1.mdl",
- "models/ReplayHnr/Knivess/v_knife2.mdl"
- }
- new const p_KnifeModels[ 3 ][ ] =
- {
- "models/p_knife.mdl",
- "models/ReplayHnr/Knivess/p_knife1.mdl",
- "models/ReplayHnr/Knivess/p_knife2.mdl"
- }
- new szVault[ ] = "Knife_VAULT";
- public plugin_init()
- {
- register_plugin(PLUGIN, VERSION, AUTHOR);
- register_clcmd( "say", "CmdSay" );
- register_event( "CurWeapon", "Event_CurWeapon", "be", "1=1" );
- register_logevent( "evRoundStart", 2, "1=Round_Start" );
- }
- public evRoundStart()
- {
- for ( new client = 1; client < get_maxplayers(); client++ )
- {
- if ( !is_user_connected( client ) )
- continue;
- uGetCash[ client ] = false;
- }
- }
- public client_putinserver( id )
- {
- CmdLoad( id );
- uGetCash[ id ] = true;
- UseKnife[ id ] = 0;
- }
- public client_disconnect( id )
- {
- CmdSave( id );
- }
- public plugin_precache()
- {
- for ( new i = 0; i < sizeof v_KnifeModels; i++ )
- precache_model( v_KnifeModels[ i ] );
- for ( new i = 0; i < sizeof p_KnifeModels; i++ )
- precache_model( p_KnifeModels[ i ] );
- }
- public Event_CurWeapon( id )
- {
- new Clip, Ammo, Weapon = get_user_weapon(id, Clip, Ammo)
- if ( Weapon == CSW_KNIFE && Knife[ id ] >= Currect[ id ] && UseKnife[ id ] == Currect[ id ] )
- {
- entity_set_string( id, EV_SZ_viewmodel, v_KnifeModels[ UseKnife[ id ] ] );
- entity_set_string( id, EV_SZ_weaponmodel, p_KnifeModels[ UseKnife[ id ] ] );
- }
- }
- public CmdSay( client )
- {
- new authid[ 50 ];
- get_user_authid( client, authid, charsmax( authid ) );
- new szMsg[ 192 ], szArgs[ 3 ][ 32 ];
- read_argv( 1, szMsg, charsmax( szMsg ) );
- parse( szMsg, szArgs[ 0 ], 31, szArgs[ 1 ], 31, szArgs[ 2 ], 31 );
- if ( equali( szMsg, "/knife" ) || equali( szMsg, "/knifes" ) )
- return CmdKnife( client );
- if ( equali( szMsg, "/getcash" ) || equali( szMsg, "/gc" ) )
- {
- if ( get_playersnum() <= 3 )
- return ColorPrint( client, "^1You need^4 3 ^1Players for ^4getcash" );
- if ( uGetCash[ client ] )
- return ColorPrint( client, "You can only use^4 get cash^1 one time^3 per round^1!" );
- uGetCash[ client ] = true;
- hnr_set_user_credits( client, hnr_get_user_credits( client ) + szKnife[ Knife[ client ] ][ GetCash ] );
- return ColorPrint( client, "You received^4 %i cash^1,^3 good luck^1!", szKnife[ Knife[ client ] ][ GetCash ] );
- }
- if ( equali( szArgs[ 0 ], "/cash" ) || equali( szArgs[ 0 ], "/cash" ) )
- {
- new iPlayer = cmd_target( client, szArgs[ 1 ], 8 );
- if ( equali( szMsg, "/cash" ) || equali( szMsg, "/cash" ) )
- iPlayer = client;
- if( iPlayer == client )
- return ColorPrint( client, "You have^3 %i ^1cash, You using a^4 %s^1.", hnr_get_user_credits( client ), szKnife[ UseKnife[ client ] ][ Name ] );
- if ( !iPlayer )
- return ColorPrint( client, "^3%s^1 was not found!", szArgs[ 1 ] );
- new szNameiPlayer[ 33 ];
- get_user_name( iPlayer, szNameiPlayer, charsmax( szNameiPlayer ) );
- return ColorPrint( client, "^3%s ^1have ^4%i ^1cash, using a^3 %s^1.", szName( iPlayer ), hnr_get_user_credits( iPlayer ), szKnife[ UseKnife[ iPlayer ] ][ Name ] );
- }
- return 0;
- }
- public CmdKnife(id)
- {
- new szMenu[ 300 ];
- formatex( szMenu, charsmax( szMenu ), "\r[\d %s \r] \yShop Knives Menu^n\wYou have \r%i \wcash^n^n\wYou are using: \r%s^n\wYou own: \y%s^n^n\wYou are viewing: \r%s^nPage:", Prefix, hnr_get_user_credits( id ), szKnife[ UseKnife[ id ] ][ Name ], szKnife[ Knife[ id ] ][ Name ], szKnife[ Currect[ id ] ][ Name ] )
- new Menu = menu_create( szMenu, "CmdKnife_sub" );
- for ( new i = 0; i < sizeof szKnife; i++ )
- {
- new iText[ 32 ] = ""
- if( Knife[ id ] >= i )
- iText = "\y[ UNLOCKED ]";
- if( Knife[ id ] < i )
- iText = "\r[ LOCKED ]";
- if( UseKnife[ id ] == i )
- iText = "\d[ USING ]";
- formatex( szMenu, charsmax( szMenu ), "%s%s %s", Knife[ id ]+1 < i ? "\d" : "\w", szKnife[ i ][ Name ], iText);
- menu_additem( Menu, szMenu );
- }
- menu_setprop(Menu, MPROP_EXIT, MEXIT_ALL );
- menu_setprop(Menu, MPROP_EXITNAME, "\wExit" )
- menu_setprop(Menu, MPROP_NUMBER_COLOR, "\r" )
- menu_display(id, Menu, 0);
- return PLUGIN_HANDLED;
- }
- public CmdKnife_sub(id, Menu, item)
- {
- if( item == MENU_EXIT )
- {
- menu_destroy(Menu);
- return PLUGIN_HANDLED;
- }
- new data[6], iName[64];
- new access, callback;
- menu_item_getinfo(Menu, item, access, data, 6, iName, 63, callback)
- Currect[ id ] = item;
- ViewKnife( id );
- menu_destroy(Menu);
- return PLUGIN_HANDLED;
- }
- public ViewKnife(id)
- {
- new mCall1 = menu_makecallback( "MenuCallBackb1" );
- new mCall2 = menu_makecallback( "MenuCallBackb2" );
- new szMenu[ 300 ];
- formatex( szMenu, charsmax( szMenu ), "\r[\d %s \r] \yShop Knives Menu^n\wYou have \r%i \wcash^n^n\wYou are using: \r%s^n\wYou own: \y%s^n^n\wYou are viewing: \r%s", Prefix, hnr_get_user_credits( id ), szKnife[ UseKnife[ id ] ][ Name ], szKnife[ Knife[ id ] ][ Name ], szKnife[ Currect[ id ] ][ Name ] )
- new Menu = menu_create( szMenu, "ViewKnife_sub" );
- formatex( szMenu, charsmax( szMenu ), "\wPurchase Knife");
- menu_additem( Menu, szMenu, "0",_, mCall1 );
- if(UseKnife[ id ] == Currect[ id ])
- {
- formatex( szMenu, charsmax( szMenu ), "\dYou already use this knife." );
- }
- else{
- formatex( szMenu, charsmax( szMenu ), "\wUse Knife" );
- }
- menu_additem( Menu, szMenu, "1",_, mCall2 );
- formatex( szMenu, charsmax( szMenu ), "^n^n\r[KNIFE INFORMATION]^n\wName\r: %s\w.^nPrice\r: %i \wcash.^nGet - Cash\r: +%i \wcash.", szKnife[ Currect[ id ] ][ Name ], szKnife[ Currect[ id ] ][ Price ], szKnife[ Currect[ id ] ][ GetCash ] );
- menu_addtext( Menu, szMenu );
- menu_setprop(Menu, MPROP_EXIT, MEXIT_ALL );
- menu_setprop(Menu, MPROP_EXITNAME, "\wExit" )
- menu_setprop(Menu, MPROP_NUMBER_COLOR, "\r" )
- menu_display(id, Menu, 0);
- return PLUGIN_HANDLED;
- }
- public ViewKnife_sub(id, Menu, item)
- {
- if( item == MENU_EXIT )
- {
- menu_destroy(Menu);
- CmdKnife( id );
- return PLUGIN_HANDLED;
- }
- new data[6], iName[64];
- new access, callback;
- menu_item_getinfo(Menu, item, access, data, 6, iName, 63, callback)
- switch( item )
- {
- case 0:
- {
- if( Knife[ id ] >= Currect[ id ] )
- return ColorPrint( id, "You have already bought ^4%s^1.", szKnife[ Currect[ id ] ][ Name ] );
- if( hnr_get_user_credits( id ) < szKnife[ Currect[ id ] ][ Price ] )
- return ColorPrint( id,"You don't have enough cash Missing: ^4%i^1.", szKnife[ Currect[ id ] ][ Price ] - hnr_get_user_credits( id ) );
- if( hnr_get_user_credits( id ) >= szKnife[ Currect[ id ] ][ Price ] )
- {
- ColorPrint( 0, "^3%s ^1have just bought ^4%s^1.", szName( id ), szKnife[ Currect[ id ] ][ Name ] )
- hnr_set_user_credits( id, hnr_get_user_credits( id ) - szKnife[ Currect[ id ] ][ Price ] )
- Knife[ id ]++
- CmdSave( id )
- }
- }
- case 1:
- {
- if( Knife[ id ] >= Currect[ id ] )
- {
- UseKnife[ id ] = Currect[ id ];
- Event_CurWeapon( id );
- }
- return ViewKnife( id );
- }
- }
- menu_destroy(Menu);
- return PLUGIN_HANDLED;
- }
- public MenuCallBackb1( id )
- {
- if( Knife[ id ] >= Currect[ id ] || Knife[ id ] != Currect[ id ]-1 ) return ITEM_DISABLED
- return ITEM_ENABLED
- }
- public MenuCallBackb2( id )
- {
- if( Knife[ id ] < Currect[ id ] || UseKnife[ id ] == Currect[ id ] ) return ITEM_DISABLED
- return ITEM_ENABLED
- }
- /* Data Storage */
- stock CmdSave( const index )
- {
- new szKey[ 64 ], szData[ 256 ];
- formatex( szKey, charsmax( szKey ), "%s-Save", szAuth( index ) );
- formatex( szData, charsmax( szData ), "%i#", Knife[ index ] );
- fvault_set_data( szVault, szKey, szData );
- }
- stock CmdLoad( const index )
- {
- new szKey[ 64 ], szData[ 256 ];
- formatex( szKey, charsmax( szKey ), "%s-Save", szAuth( index ) );
- formatex( szData, charsmax( szData ), "%i#", Knife[ index ] );
- fvault_get_data( szVault, szKey, szData, 255 );
- replace_all( szData, 255, "#", " " );
- new SetData[ 1 ][ 32 ];
- parse( szData, SetData[ 0 ], 31 );
- Knife[ index ] = str_to_num( SetData[ 0 ] );
- }
- stock szAuth( const index )
- {
- static g_szAuthID[ 35 ];
- get_user_authid( index, g_szAuthID, charsmax( g_szAuthID ) );
- return g_szAuthID;
- }
- stock szName( const index )
- {
- static wName[ 32 ];
- get_user_name( index, wName, charsmax( wName ) );
- return wName;
- }
- stock ColorPrint( const index, const string[], any:... )
- {
- new szMsg[ 191 ], Players[ 32 ], PNum = 1;
- static iLen; iLen = formatex( szMsg, charsmax( szMsg ), "^3[%s]^1 ", Prefix );
- vformat( szMsg[ iLen ], charsmax( szMsg ) - iLen, string, 3 );
- if ( index )
- Players[ 0 ] = index;
- else
- get_players( Players, PNum, "ch" );
- for ( new i; i < PNum; i++ )
- {
- if( is_user_connected( Players[ i ] ) )
- {
- message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ), _, Players[ i ] );
- write_byte( Players[ i ] );
- write_string( szMsg );
- message_end( );
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement