Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.25 KB | None | 0 0
  1. #include < amxmodx >
  2. #include < amxmisc >
  3. #include < cstrike >
  4. #include < hamsandwich >
  5. #include < nvault >
  6. #include < colorchat >
  7. #include < fun >
  8. #include < engine >
  9. #include < fakemeta >
  10.  
  11. #define PLUGIN "HidenSeek Shop"
  12. #define VERSION "1.0"
  13. #define AUTHOR "dinnk"
  14. #define MAXPLAYERS 32
  15. #define IsPlayer(%1) (1 <= %1 <= gMaxPlayers)
  16.  
  17. enum _:UPGRADES
  18. {
  19. Health,
  20. Respawn,
  21. Damage
  22. }
  23.  
  24. enum _:ITEMINFO
  25. {
  26. Name [ 20 ],
  27. Levels,
  28. MaxValue,
  29. Prefix [ 5 ]
  30. }
  31.  
  32. new const ItemInfo [ UPGRADES ] [ ITEMINFO ] =
  33. {
  34. { "Extra Health", 5, 25, " HP" },
  35. { "Respawn Chance", 5, 15, "%" },
  36. { "Extra Damage", 3, 15, "%" }
  37. }
  38.  
  39. new const ItemPrice [ UPGRADES ] [ ] =
  40. {
  41. { 50, 60, 75, 90, 130 },
  42. { 100, 120, 150, 190, 250 },
  43. { 80, 100, 150 }
  44. }
  45.  
  46. /////////////////P R E F I X/////////////////////////////////////////////////
  47. new const gPrefix [ ] = "^4[CZ] HideNSeek Shop:^3"
  48. new const gMenuPrefix [ ] = "\r[CZ]\w HideNSeek Shop^n"
  49.  
  50. /////////////////M E N U . C O M M A N D S///////////////////////////////////
  51. new const gMenuCommands [ ] [ ] =
  52. {
  53. "say /shop",
  54. "say_team /shop",
  55. "shopmenu"
  56. }
  57.  
  58. /////////////////V A R I A B L E S///////////////////////////////////////////
  59. new gPoint [ MAXPLAYERS + 1 ]
  60. new gKillCount [ MAXPLAYERS + 1 ]
  61. new gSurviveCount [ MAXPLAYERS + 1 ]
  62. new gItemLevel [ MAXPLAYERS + 1 ] [ UPGRADES ]
  63.  
  64. /////////////////V I P///////////////////////////////////////////////////
  65. new bool: gIsVip [ MAXPLAYERS + 1 ]
  66. new gVIPFile [ 128 ]
  67. new Trie:gVIPSteamIDs
  68.  
  69. /////////////////S A V E / L O A D///////////////////////////////////////////
  70. new gVault
  71.  
  72. /////////////////M A X P L A Y E R S/////////////////////////////////////////
  73. new gMaxPlayers
  74.  
  75. /////////////////C V A R S///////////////////////////////////////////////////
  76. enum _:g_Cvars
  77. {
  78. Kill, // Points gained per kill
  79. Survive, // Points gained per survive
  80. Headshot, // Points gained for Headshot Bonus
  81. BonusCT, // Points gained for each kill ( if killing more than two per round ) additional as Bonus Points
  82. BonusT, // Points gained for surviving 3 rounds in a row
  83. Suicide, // Points lost for Suiciding
  84. PriceVip // Price for buying VIP Skin ( double points gained from anything )
  85. }
  86. new gCvars [ g_Cvars ]
  87.  
  88. public plugin_precache( )
  89. {
  90. LoadVIPs( )
  91. }
  92. ////////////////P L U G I N S T A R T////////////////////////////////////////
  93. public plugin_init ( )
  94. {
  95. ////////C O M M A N D S//////////////////////////////////////////////
  96. new gCommand [ 24 ], gFunction [ ] = "CmdShopMenu"
  97. for ( new i = 0; i < sizeof ( gMenuCommands ); i++ )
  98. {
  99. formatex ( gCommand, charsmax ( gCommand ), "%s", gMenuCommands [ i ] )
  100. register_clcmd ( gCommand, gFunction )
  101. }
  102. register_clcmd ( "say /vips", "CmdShowVips" )
  103.  
  104. ////////E V E N T S//////////////////////////////////////////////////
  105. register_event ( "DeathMsg", "CmdDeathMsg", "a" )
  106. register_logevent ( "CmdRoundBegin", 2, "1=Round_Start" )
  107.  
  108. ////////M A X P L A Y E R S//////////////////////////////////////////
  109. gMaxPlayers = get_maxplayers ( )
  110.  
  111. ////////C V A R S////////////////////////////////////////////////////
  112. gCvars [ Kill ] = register_cvar ( "hnspm_point_kill", "2" )
  113. gCvars [ Survive ] = register_cvar ( "hnspm_point_survive", "5" )
  114. gCvars [ Headshot ] = register_cvar ( "hnspm_bonus_headshot", "2" )
  115. gCvars [ BonusCT ] = register_cvar ( "hnspm_bonus_ct", "2" )
  116. gCvars [ BonusT ] = register_cvar ( "hnspm_bonus_t", "10" )
  117. gCvars [ Suicide ] = register_cvar ( "hnspm_points_suicide", "3" )
  118. gCvars [ PriceVip ] = register_cvar ( "hnspm_price_vip", "1000" )
  119.  
  120. ////////N V A U L T//////////////////////////////////////////////////
  121. gVault = nvault_open ( "CZONEPointMod" )
  122.  
  123. ////////V I P////////////////////////////////////////////////////////
  124. register_srvcmd ( "vip_add", "CmdAddVip" )
  125.  
  126. }
  127.  
  128. public client_connect ( id )
  129. {
  130. if ( IsPlayer ( id ) )
  131. {
  132. LoadData ( id )
  133. LoadVIPs ( )
  134. }
  135. }
  136.  
  137. public client_disconnect ( id )
  138. {
  139. if ( gIsVip [ id ] )
  140. gIsVip [ id ] = false
  141. SaveData ( id )
  142. }
  143.  
  144. public client_authorized ( id )
  145. {
  146. new gSteamID[ 35 ], gName [ 32 ]
  147. get_user_authid ( id, gSteamID, charsmax ( gSteamID ) )
  148. get_user_name ( id, gName, charsmax ( gName ) )
  149.  
  150. if ( TrieKeyExists ( gVIPSteamIDs, gSteamID ) )
  151. {
  152. gIsVip [ id ] = true;
  153. ColorChat ( 0, GREY, "%s^4 %s^3 Joined as^4 VIP^3 !", gPrefix, gName )
  154. }
  155. LoadData ( id )
  156. }
  157.  
  158. public CmdRoundBegin ( id )
  159. {
  160. new Players [ 32 ], num, tempid
  161. get_players ( Players, num, "a" )
  162. for ( new i; i < num; i++ )
  163. {
  164. tempid = Players [ i ]
  165.  
  166. gKillCount [ tempid ] = 0
  167. }
  168. }
  169.  
  170. public EventRoundEnd ( )
  171. {
  172. new Players [ 32 ], num, tempid, gPointGain
  173. get_players ( Players, num, "a" )
  174. for ( new i; i < num; i++ )
  175. {
  176. tempid = Players [ i ]
  177.  
  178. if ( is_user_alive ( tempid ) && cs_get_user_team ( tempid ) == CS_TEAM_T )
  179. {
  180. gPointGain = get_pcvar_num ( gCvars [ Survive ] )
  181. if ( gIsVip [ tempid ] )
  182. gPointGain += get_pcvar_num ( gCvars [ Survive ] )
  183. gPoint [ tempid ] += gPointGain
  184. gSurviveCount [ tempid ]++
  185. ColorChat ( tempid, GREY, "%s You gained^4 %i^3 Points for surviving %s!", gPrefix, gPointGain, gIsVip [ tempid ] ? "as^4 VIP^3 " : "" )
  186. SaveData ( tempid )
  187. }
  188. else if ( !is_user_alive ( tempid ) )
  189. {
  190. gSurviveCount [ tempid ] = 0
  191. }
  192. }
  193. }
  194.  
  195. public CmdShopMenu ( id )
  196. {
  197. new gTitle [ 128 ]
  198. formatex ( gTitle, charsmax ( gTitle ), "%s", gMenuPrefix )
  199. new gMenu = menu_create ( gTitle, "CmdShopHandle", 0 )
  200.  
  201. new gPoints [ 20 ]
  202. formatex ( gPoints, charsmax ( gPoints ), "Points:\r %i", gPoints [ id ] )
  203.  
  204. menu_additem ( gMenu, "\yPlayer Info", "1" )
  205. menu_addblank ( gMenu, 0 )
  206. menu_additem ( gMenu, "Upgrades", "2" )
  207. menu_addblank ( gMenu, 0 )
  208. new gVips [ 20 ]
  209. formatex ( gVips, charsmax ( gVips ), "\yBuy VIP:\r %i", get_cvar_num ( gCvars [ PriceVip ] ) )
  210. menu_additem ( gMenu, gVips, "3" )
  211. menu_addblank ( gMenu )
  212. menu_addtext ( gMenu, gPoints, 0 )
  213. menu_addblank ( gMenu )
  214.  
  215. menu_setprop ( gMenu, MPROP_EXITNAME, "Close" )
  216. menu_display ( id, gMenu )
  217.  
  218. return PLUGIN_HANDLED
  219. }
  220.  
  221. public CmdShopHandle ( id, gMenu, gItem )
  222. {
  223. if ( gItem == MENU_EXIT )
  224. {
  225. menu_destroy ( gMenu )
  226. return PLUGIN_HANDLED
  227. }
  228.  
  229. new gAccess, gCallback, gData [ 3 ]
  230. menu_item_getinfo ( gMenu, gItem, gAccess, gData, charsmax ( gData ), _, _, gCallback )
  231.  
  232. new gKey = str_to_num ( gData )
  233. switch ( gKey )
  234. {
  235. case 1: ColorChat ( id, GREY, "%s", gPrefix )//CmdPlayerMenu ( id )
  236. case 2: ColorChat ( id, GREY, "%s", gPrefix ) //CmdUpgradeMenu ( id )
  237. case 3:
  238. {
  239. if ( gIsVip [ id ] )
  240. {
  241. ColorChat ( id, GREY, "%s You already have^4 VIP^3 !", gPrefix )
  242. return PLUGIN_HANDLED
  243. }
  244. else if ( gPoint [ id ] < get_pcvar_num ( gCvars [ PriceVip ] ) )
  245. {
  246. ColorChat ( id, GREY, "%s You need^4 %i^3 more Points to buy^4 VIP^3 !", gPrefix, get_pcvar_num ( gCvars [ PriceVip ] ) - gPoint [ id ] )
  247. return PLUGIN_HANDLED
  248. }
  249. else
  250. {
  251. CmdAddMenuVip ( id )
  252. }
  253. }
  254. }
  255. return PLUGIN_HANDLED
  256. }
  257.  
  258. public CmdDeathMsg ( )
  259. {
  260. new gKiller = read_data ( 1 )
  261. new gVictim = read_data ( 2 )
  262. new isHeadshot = read_data ( 3 )
  263.  
  264. if ( IsPlayer ( gKiller ) && IsPlayer ( gVictim ) )
  265. {
  266. if ( gKiller != gVictim )
  267. {
  268. if ( cs_get_user_team ( gKiller ) != cs_get_user_team ( gVictim ) )
  269. {
  270. new gPointsGain = get_pcvar_num ( gCvars [ Kill ] )
  271. if ( isHeadshot )
  272. gPointsGain += get_pcvar_num ( gCvars [ Headshot ] )
  273. if ( gIsVip [ gKiller ] )
  274. gPointsGain = gPointsGain + gPointsGain
  275. if ( cs_get_user_team ( gKiller ) == CS_TEAM_CT )
  276. gKillCount [ gKiller ]++
  277.  
  278. gPoint [ gKiller ] += gPointsGain
  279.  
  280. ColorChat ( gKiller, GREY, "%s You gained^4 %i^3 Points from getting a kill %s!", gPrefix, gPointsGain, isHeadshot ? "with a headshot" : "" )
  281. SaveData ( gKiller )
  282. }
  283. }
  284. else
  285. {
  286. gPoint [ gVictim ] -= get_pcvar_num ( gCvars [ Suicide ] )
  287. if ( gPoint [ gVictim ] < 0 )
  288. gPoint [ gVictim ] = 0
  289. ColorChat ( gVictim, GREY, "%s You lost^4 %i^3 Points from suiciding !", gPrefix, get_pcvar_num ( gCvars [ Suicide ] ) )
  290. SaveData ( gVictim )
  291. }
  292. }
  293. return PLUGIN_HANDLED
  294. }
  295.  
  296. public CmdAddMenuVip ( id )
  297. {
  298. new gName [ 32 ], gAuthID [ 35 ]
  299. get_user_authid ( id, gAuthID, charsmax ( gAuthID ) )
  300. get_user_name ( id, gName, charsmax ( gName ) )
  301.  
  302. gPoint [ id ] -= get_pcvar_num ( gCvars [ PriceVip ] )
  303. ColorChat ( 0, GREY, "%s^4 %i^3 has bought^4 VIP^3 for^4 %i^3 Points !", gPrefix, get_pcvar_num ( gCvars [ PriceVip ] ) )
  304.  
  305. server_cmd ( "vip_add ^"%s^" ^"t^" ^"^" ^"steamid^"", gAuthID )
  306. gIsVip [ id ] = true
  307.  
  308. log_amx ( "VIP: %s [%s] bought VIP", gName, gAuthID )
  309. }
  310.  
  311. public CmdAddVip( )
  312. {
  313. if( read_argc ( ) < 2 )
  314. {
  315. server_print( "Invalid arguments! Usage: vip_add <steamid> (Note: USE QUOTES AROUND STEAMID!)" )
  316. return PLUGIN_HANDLED
  317. }
  318.  
  319. new gSteamID[ 35 ]
  320. read_argv( 1, gSteamID, charsmax( gSteamID ) )
  321.  
  322. if( TrieKeyExists( gVIPSteamIDs, gSteamID ) )
  323. {
  324. return PLUGIN_HANDLED
  325. }
  326.  
  327. if( !IsValidSteamID( gSteamID ) )
  328. {
  329. log_amx( "Invalid SteamID given to vip_add command." )
  330. return PLUGIN_HANDLED
  331. }
  332.  
  333. TrieSetCell( gVIPSteamIDs, gSteamID, 1 )
  334.  
  335. format( gSteamID, charsmax( gSteamID ), "%s", gSteamID )
  336.  
  337. write_file( gVIPFile, gSteamID )
  338.  
  339. return PLUGIN_HANDLED
  340. }
  341.  
  342. bool:IsValidSteamID( gSteamID[ ] )
  343. {
  344. return ( strlen( gSteamID ) > 10 && equal( gSteamID, "STEAM_0:", 8 ) && ( '0' <= gSteamID[ 8 ] <= '1' ) && gSteamID[ 9 ] == ':' && is_str_num( gSteamID[ 10 ] ) )
  345. }
  346.  
  347. public plugin_end( )
  348. {
  349. TrieDestroy( gVIPSteamIDs )
  350. }
  351.  
  352. LoadVIPs( )
  353. {
  354. gVIPSteamIDs = TrieCreate( )
  355.  
  356. get_configsdir( gVIPFile, charsmax( gVIPFile ) )
  357. add( gVIPFile, charsmax( gVIPFile ), "/vip.ini" )
  358.  
  359. new iFile = fopen( gVIPFile, "rt" )
  360.  
  361. if( !iFile )
  362. {
  363. return
  364. }
  365.  
  366. new gData[ 64 ], gSteamID[ 35 ], iLine
  367.  
  368. while( !feof( iFile ) )
  369. {
  370. iLine++
  371.  
  372. fgets( iFile, gData, charsmax( gData ) )
  373. trim( gData )
  374.  
  375. strbreak( gData, gSteamID, charsmax( gSteamID ), gData, charsmax( gData ) )
  376.  
  377. if( IsValidSteamID( gSteamID ) )
  378. {
  379. TrieSetCell( gVIPSteamIDs, gSteamID, 1 )
  380. }
  381. else
  382. {
  383. log_amx( "Invalid SteamID on line %d in vip.ini!", iLine )
  384. }
  385. }
  386.  
  387. fclose( iFile )
  388. }
  389.  
  390. public SaveData ( id )
  391. {
  392. static gData [ 256 ]
  393. new gAuthID [ 35 ]
  394. get_user_authid ( id, gAuthID, charsmax ( gAuthID ) )
  395.  
  396. new gLen = formatex ( gData, charsmax ( gData ), "%i", gPoint [ id ] )
  397.  
  398. for ( new iItem = 0; iItem < UPGRADES; iItem++ )
  399. {
  400. gLen += formatex ( gData [ gLen ], charsmax ( gData ) - gLen, " %i", gItemLevel [ id ] [ iItem ] )
  401. }
  402. nvault_set ( gVault, gAuthID, gData )
  403. }
  404.  
  405. public LoadData ( id )
  406. {
  407. static gData [ 256 ]
  408. new gAuthID [ 35 ], timestamp
  409. get_user_authid ( id, gAuthID, charsmax ( gAuthID ) )
  410.  
  411. if ( nvault_lookup ( gVault, gAuthID, gData, charsmax ( gData ), timestamp ) )
  412. {
  413. ParseLoadData ( id, gData )
  414. }
  415. else
  416. {
  417. for ( new iItem = 0; iItem < UPGRADES; iItem++ )
  418. {
  419. gItemLevel [ id ] [ iItem ] = 0
  420. }
  421. gPoint [ id ] = 0
  422. }
  423. }
  424.  
  425. ParseLoadData ( id, gData [ 256 ] )
  426. {
  427. static gNum [ 11 ]
  428. strbreak ( gData, gNum, charsmax ( gNum ), gData, charsmax ( gData ) )
  429. gPoint [ id ] = str_to_num ( gNum )
  430.  
  431. for ( new iItem = 0; iItem < UPGRADES; iItem++ )
  432. {
  433. strbreak ( gData, gNum, charsmax ( gNum ), gData, charsmax ( gData ) )
  434. gItemLevel [ id ] [ iItem ] = str_to_num ( gNum )
  435. }
  436. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement