#include < amxmodx > #include < amxmisc > #include < cstrike > #include < hamsandwich > #include < nvault > #include < colorchat > #include < fun > #include < engine > #include < fakemeta > #define PLUGIN "HidenSeek Shop" #define VERSION "1.0" #define AUTHOR "dinnk" #define MAXPLAYERS 32 #define IsPlayer(%1) (1 <= %1 <= gMaxPlayers) enum _:UPGRADES { Health, Respawn, Damage } enum _:ITEMINFO { Name [ 20 ], Levels, MaxValue, Prefix [ 5 ] } new const ItemInfo [ UPGRADES ] [ ITEMINFO ] = { { "Extra Health", 5, 25, " HP" }, { "Respawn Chance", 5, 15, "%" }, { "Extra Damage", 3, 15, "%" } } new const ItemPrice [ UPGRADES ] [ ] = { { 50, 60, 75, 90, 130 }, { 100, 120, 150, 190, 250 }, { 80, 100, 150 } } /////////////////P R E F I X///////////////////////////////////////////////// new const gPrefix [ ] = "^4[CZ] HideNSeek Shop:^3" new const gMenuPrefix [ ] = "\r[CZ]\w HideNSeek Shop^n" /////////////////M E N U . C O M M A N D S/////////////////////////////////// new const gMenuCommands [ ] [ ] = { "say /shop", "say_team /shop", "shopmenu" } /////////////////V A R I A B L E S/////////////////////////////////////////// new gPoint [ MAXPLAYERS + 1 ] new gKillCount [ MAXPLAYERS + 1 ] new gSurviveCount [ MAXPLAYERS + 1 ] new gItemLevel [ MAXPLAYERS + 1 ] [ UPGRADES ] /////////////////V I P/////////////////////////////////////////////////// new bool: gIsVip [ MAXPLAYERS + 1 ] new gVIPFile [ 128 ] new Trie:gVIPSteamIDs /////////////////S A V E / L O A D/////////////////////////////////////////// new gVault /////////////////M A X P L A Y E R S///////////////////////////////////////// new gMaxPlayers /////////////////C V A R S/////////////////////////////////////////////////// enum _:g_Cvars { Kill, // Points gained per kill Survive, // Points gained per survive Headshot, // Points gained for Headshot Bonus BonusCT, // Points gained for each kill ( if killing more than two per round ) additional as Bonus Points BonusT, // Points gained for surviving 3 rounds in a row Suicide, // Points lost for Suiciding PriceVip // Price for buying VIP Skin ( double points gained from anything ) } new gCvars [ g_Cvars ] public plugin_precache( ) { LoadVIPs( ) } ////////////////P L U G I N S T A R T//////////////////////////////////////// public plugin_init ( ) { ////////C O M M A N D S////////////////////////////////////////////// new gCommand [ 24 ], gFunction [ ] = "CmdShopMenu" for ( new i = 0; i < sizeof ( gMenuCommands ); i++ ) { formatex ( gCommand, charsmax ( gCommand ), "%s", gMenuCommands [ i ] ) register_clcmd ( gCommand, gFunction ) } register_clcmd ( "say /vips", "CmdShowVips" ) ////////E V E N T S////////////////////////////////////////////////// register_event ( "DeathMsg", "CmdDeathMsg", "a" ) register_logevent ( "CmdRoundBegin", 2, "1=Round_Start" ) ////////M A X P L A Y E R S////////////////////////////////////////// gMaxPlayers = get_maxplayers ( ) ////////C V A R S//////////////////////////////////////////////////// gCvars [ Kill ] = register_cvar ( "hnspm_point_kill", "2" ) gCvars [ Survive ] = register_cvar ( "hnspm_point_survive", "5" ) gCvars [ Headshot ] = register_cvar ( "hnspm_bonus_headshot", "2" ) gCvars [ BonusCT ] = register_cvar ( "hnspm_bonus_ct", "2" ) gCvars [ BonusT ] = register_cvar ( "hnspm_bonus_t", "10" ) gCvars [ Suicide ] = register_cvar ( "hnspm_points_suicide", "3" ) gCvars [ PriceVip ] = register_cvar ( "hnspm_price_vip", "1000" ) ////////N V A U L T////////////////////////////////////////////////// gVault = nvault_open ( "CZONEPointMod" ) ////////V I P//////////////////////////////////////////////////////// register_srvcmd ( "vip_add", "CmdAddVip" ) } public client_connect ( id ) { if ( IsPlayer ( id ) ) { LoadData ( id ) LoadVIPs ( ) } } public client_disconnect ( id ) { if ( gIsVip [ id ] ) gIsVip [ id ] = false SaveData ( id ) } public client_authorized ( id ) { new gSteamID[ 35 ], gName [ 32 ] get_user_authid ( id, gSteamID, charsmax ( gSteamID ) ) get_user_name ( id, gName, charsmax ( gName ) ) if ( TrieKeyExists ( gVIPSteamIDs, gSteamID ) ) { gIsVip [ id ] = true; ColorChat ( 0, GREY, "%s^4 %s^3 Joined as^4 VIP^3 !", gPrefix, gName ) } LoadData ( id ) } public CmdRoundBegin ( id ) { new Players [ 32 ], num, tempid get_players ( Players, num, "a" ) for ( new i; i < num; i++ ) { tempid = Players [ i ] gKillCount [ tempid ] = 0 } } public EventRoundEnd ( ) { new Players [ 32 ], num, tempid, gPointGain get_players ( Players, num, "a" ) for ( new i; i < num; i++ ) { tempid = Players [ i ] if ( is_user_alive ( tempid ) && cs_get_user_team ( tempid ) == CS_TEAM_T ) { gPointGain = get_pcvar_num ( gCvars [ Survive ] ) if ( gIsVip [ tempid ] ) gPointGain += get_pcvar_num ( gCvars [ Survive ] ) gPoint [ tempid ] += gPointGain gSurviveCount [ tempid ]++ ColorChat ( tempid, GREY, "%s You gained^4 %i^3 Points for surviving %s!", gPrefix, gPointGain, gIsVip [ tempid ] ? "as^4 VIP^3 " : "" ) SaveData ( tempid ) } else if ( !is_user_alive ( tempid ) ) { gSurviveCount [ tempid ] = 0 } } } public CmdShopMenu ( id ) { new gTitle [ 128 ] formatex ( gTitle, charsmax ( gTitle ), "%s", gMenuPrefix ) new gMenu = menu_create ( gTitle, "CmdShopHandle", 0 ) new gPoints [ 20 ] formatex ( gPoints, charsmax ( gPoints ), "Points:\r %i", gPoints [ id ] ) menu_additem ( gMenu, "\yPlayer Info", "1" ) menu_addblank ( gMenu, 0 ) menu_additem ( gMenu, "Upgrades", "2" ) menu_addblank ( gMenu, 0 ) new gVips [ 20 ] formatex ( gVips, charsmax ( gVips ), "\yBuy VIP:\r %i", get_cvar_num ( gCvars [ PriceVip ] ) ) menu_additem ( gMenu, gVips, "3" ) menu_addblank ( gMenu ) menu_addtext ( gMenu, gPoints, 0 ) menu_addblank ( gMenu ) menu_setprop ( gMenu, MPROP_EXITNAME, "Close" ) menu_display ( id, gMenu ) return PLUGIN_HANDLED } public CmdShopHandle ( id, gMenu, gItem ) { if ( gItem == MENU_EXIT ) { menu_destroy ( gMenu ) return PLUGIN_HANDLED } new gAccess, gCallback, gData [ 3 ] menu_item_getinfo ( gMenu, gItem, gAccess, gData, charsmax ( gData ), _, _, gCallback ) new gKey = str_to_num ( gData ) switch ( gKey ) { case 1: ColorChat ( id, GREY, "%s", gPrefix )//CmdPlayerMenu ( id ) case 2: ColorChat ( id, GREY, "%s", gPrefix ) //CmdUpgradeMenu ( id ) case 3: { if ( gIsVip [ id ] ) { ColorChat ( id, GREY, "%s You already have^4 VIP^3 !", gPrefix ) return PLUGIN_HANDLED } else if ( gPoint [ id ] < get_pcvar_num ( gCvars [ PriceVip ] ) ) { ColorChat ( id, GREY, "%s You need^4 %i^3 more Points to buy^4 VIP^3 !", gPrefix, get_pcvar_num ( gCvars [ PriceVip ] ) - gPoint [ id ] ) return PLUGIN_HANDLED } else { CmdAddMenuVip ( id ) } } } return PLUGIN_HANDLED } public CmdDeathMsg ( ) { new gKiller = read_data ( 1 ) new gVictim = read_data ( 2 ) new isHeadshot = read_data ( 3 ) if ( IsPlayer ( gKiller ) && IsPlayer ( gVictim ) ) { if ( gKiller != gVictim ) { if ( cs_get_user_team ( gKiller ) != cs_get_user_team ( gVictim ) ) { new gPointsGain = get_pcvar_num ( gCvars [ Kill ] ) if ( isHeadshot ) gPointsGain += get_pcvar_num ( gCvars [ Headshot ] ) if ( gIsVip [ gKiller ] ) gPointsGain = gPointsGain + gPointsGain if ( cs_get_user_team ( gKiller ) == CS_TEAM_CT ) gKillCount [ gKiller ]++ gPoint [ gKiller ] += gPointsGain ColorChat ( gKiller, GREY, "%s You gained^4 %i^3 Points from getting a kill %s!", gPrefix, gPointsGain, isHeadshot ? "with a headshot" : "" ) SaveData ( gKiller ) } } else { gPoint [ gVictim ] -= get_pcvar_num ( gCvars [ Suicide ] ) if ( gPoint [ gVictim ] < 0 ) gPoint [ gVictim ] = 0 ColorChat ( gVictim, GREY, "%s You lost^4 %i^3 Points from suiciding !", gPrefix, get_pcvar_num ( gCvars [ Suicide ] ) ) SaveData ( gVictim ) } } return PLUGIN_HANDLED } public CmdAddMenuVip ( id ) { new gName [ 32 ], gAuthID [ 35 ] get_user_authid ( id, gAuthID, charsmax ( gAuthID ) ) get_user_name ( id, gName, charsmax ( gName ) ) gPoint [ id ] -= get_pcvar_num ( gCvars [ PriceVip ] ) ColorChat ( 0, GREY, "%s^4 %i^3 has bought^4 VIP^3 for^4 %i^3 Points !", gPrefix, get_pcvar_num ( gCvars [ PriceVip ] ) ) server_cmd ( "vip_add ^"%s^" ^"t^" ^"^" ^"steamid^"", gAuthID ) gIsVip [ id ] = true log_amx ( "VIP: %s [%s] bought VIP", gName, gAuthID ) } public CmdAddVip( ) { if( read_argc ( ) < 2 ) { server_print( "Invalid arguments! Usage: vip_add (Note: USE QUOTES AROUND STEAMID!)" ) return PLUGIN_HANDLED } new gSteamID[ 35 ] read_argv( 1, gSteamID, charsmax( gSteamID ) ) if( TrieKeyExists( gVIPSteamIDs, gSteamID ) ) { return PLUGIN_HANDLED } if( !IsValidSteamID( gSteamID ) ) { log_amx( "Invalid SteamID given to vip_add command." ) return PLUGIN_HANDLED } TrieSetCell( gVIPSteamIDs, gSteamID, 1 ) format( gSteamID, charsmax( gSteamID ), "%s", gSteamID ) write_file( gVIPFile, gSteamID ) return PLUGIN_HANDLED } bool:IsValidSteamID( gSteamID[ ] ) { return ( strlen( gSteamID ) > 10 && equal( gSteamID, "STEAM_0:", 8 ) && ( '0' <= gSteamID[ 8 ] <= '1' ) && gSteamID[ 9 ] == ':' && is_str_num( gSteamID[ 10 ] ) ) } public plugin_end( ) { TrieDestroy( gVIPSteamIDs ) } LoadVIPs( ) { gVIPSteamIDs = TrieCreate( ) get_configsdir( gVIPFile, charsmax( gVIPFile ) ) add( gVIPFile, charsmax( gVIPFile ), "/vip.ini" ) new iFile = fopen( gVIPFile, "rt" ) if( !iFile ) { return } new gData[ 64 ], gSteamID[ 35 ], iLine while( !feof( iFile ) ) { iLine++ fgets( iFile, gData, charsmax( gData ) ) trim( gData ) strbreak( gData, gSteamID, charsmax( gSteamID ), gData, charsmax( gData ) ) if( IsValidSteamID( gSteamID ) ) { TrieSetCell( gVIPSteamIDs, gSteamID, 1 ) } else { log_amx( "Invalid SteamID on line %d in vip.ini!", iLine ) } } fclose( iFile ) } public SaveData ( id ) { static gData [ 256 ] new gAuthID [ 35 ] get_user_authid ( id, gAuthID, charsmax ( gAuthID ) ) new gLen = formatex ( gData, charsmax ( gData ), "%i", gPoint [ id ] ) for ( new iItem = 0; iItem < UPGRADES; iItem++ ) { gLen += formatex ( gData [ gLen ], charsmax ( gData ) - gLen, " %i", gItemLevel [ id ] [ iItem ] ) } nvault_set ( gVault, gAuthID, gData ) } public LoadData ( id ) { static gData [ 256 ] new gAuthID [ 35 ], timestamp get_user_authid ( id, gAuthID, charsmax ( gAuthID ) ) if ( nvault_lookup ( gVault, gAuthID, gData, charsmax ( gData ), timestamp ) ) { ParseLoadData ( id, gData ) } else { for ( new iItem = 0; iItem < UPGRADES; iItem++ ) { gItemLevel [ id ] [ iItem ] = 0 } gPoint [ id ] = 0 } } ParseLoadData ( id, gData [ 256 ] ) { static gNum [ 11 ] strbreak ( gData, gNum, charsmax ( gNum ), gData, charsmax ( gData ) ) gPoint [ id ] = str_to_num ( gNum ) for ( new iItem = 0; iItem < UPGRADES; iItem++ ) { strbreak ( gData, gNum, charsmax ( gNum ), gData, charsmax ( gData ) ) gItemLevel [ id ] [ iItem ] = str_to_num ( gNum ) } }