Advertisement
shahars1445

Knife System Code - Help

Feb 26th, 2020
664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.56 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <fvault>
  4. #include <engine>
  5. #include <cstrike>
  6. #include <fun>
  7.  
  8. #define PLUGIN "Knife System"
  9. #define VERSION "1.0"
  10. #define AUTHOR "@.Hacker-`"
  11.  
  12. #define Prefix "Replay"
  13.  
  14. native hnr_set_user_credits( id, amount );
  15. native hnr_get_user_credits( id );
  16.  
  17. new Currect[ 33 ], Knife[ 33 ], UseKnife[ 33 ];
  18.  
  19. new bool:uGetCash[ 33 ];
  20.  
  21. enum _:info{
  22.  
  23. Name[ 33 ],
  24. Price,
  25. GetCash
  26. }
  27.  
  28. new const szKnife[ ][ info ] =
  29. {
  30. { "Normal Knife", 0, 25 },
  31. { "Knife #1", 10000, 50 },
  32. { "Knife #2", 15000, 75 }
  33. }
  34.  
  35. new const v_KnifeModels[ 3 ][ ] =
  36. {
  37. "models/v_knife.mdl",
  38. "models/ReplayHnr/Knivess/v_knife1.mdl",
  39. "models/ReplayHnr/Knivess/v_knife2.mdl"
  40. }
  41.  
  42. new const p_KnifeModels[ 3 ][ ] =
  43. {
  44. "models/p_knife.mdl",
  45. "models/ReplayHnr/Knivess/p_knife1.mdl",
  46. "models/ReplayHnr/Knivess/p_knife2.mdl"
  47. }
  48.  
  49. new szVault[ ] = "Knife_VAULT";
  50.  
  51. public plugin_init()
  52. {
  53. register_plugin(PLUGIN, VERSION, AUTHOR);
  54.  
  55. register_clcmd( "say", "CmdSay" );
  56.  
  57. register_event( "CurWeapon", "Event_CurWeapon", "be", "1=1" );
  58.  
  59. register_logevent( "evRoundStart", 2, "1=Round_Start" );
  60. }
  61.  
  62. public evRoundStart()
  63. {
  64. for ( new client = 1; client < get_maxplayers(); client++ )
  65. {
  66. if ( !is_user_connected( client ) )
  67. continue;
  68.  
  69. uGetCash[ client ] = false;
  70. }
  71. }
  72.  
  73. public client_putinserver( id )
  74. {
  75. CmdLoad( id );
  76.  
  77. uGetCash[ id ] = true;
  78.  
  79. UseKnife[ id ] = 0;
  80. }
  81.  
  82. public client_disconnect( id )
  83. {
  84. CmdSave( id );
  85. }
  86.  
  87. public plugin_precache()
  88. {
  89. for ( new i = 0; i < sizeof v_KnifeModels; i++ )
  90. precache_model( v_KnifeModels[ i ] );
  91.  
  92. for ( new i = 0; i < sizeof p_KnifeModels; i++ )
  93. precache_model( p_KnifeModels[ i ] );
  94. }
  95.  
  96. public Event_CurWeapon( id )
  97. {
  98. new Clip, Ammo, Weapon = get_user_weapon(id, Clip, Ammo)
  99.  
  100. if ( Weapon == CSW_KNIFE && Knife[ id ] >= Currect[ id ] && UseKnife[ id ] == Currect[ id ] )
  101. {
  102. entity_set_string( id, EV_SZ_viewmodel, v_KnifeModels[ UseKnife[ id ] ] );
  103. entity_set_string( id, EV_SZ_weaponmodel, p_KnifeModels[ UseKnife[ id ] ] );
  104. }
  105. }
  106.  
  107. public CmdSay( client )
  108. {
  109.  
  110. new authid[ 50 ];
  111.  
  112. get_user_authid( client, authid, charsmax( authid ) );
  113.  
  114. new szMsg[ 192 ], szArgs[ 3 ][ 32 ];
  115.  
  116. read_argv( 1, szMsg, charsmax( szMsg ) );
  117.  
  118. parse( szMsg, szArgs[ 0 ], 31, szArgs[ 1 ], 31, szArgs[ 2 ], 31 );
  119.  
  120. if ( equali( szMsg, "/knife" ) || equali( szMsg, "/knifes" ) )
  121. return CmdKnife( client );
  122.  
  123. if ( equali( szMsg, "/getcash" ) || equali( szMsg, "/gc" ) )
  124. {
  125. if ( get_playersnum() <= 3 )
  126. return ColorPrint( client, "^1You need^4 3 ^1Players for ^4getcash" );
  127.  
  128. if ( uGetCash[ client ] )
  129. return ColorPrint( client, "You can only use^4 get cash^1 one time^3 per round^1!" );
  130.  
  131. uGetCash[ client ] = true;
  132.  
  133. hnr_set_user_credits( client, hnr_get_user_credits( client ) + szKnife[ Knife[ client ] ][ GetCash ] );
  134.  
  135. return ColorPrint( client, "You received^4 %i cash^1,^3 good luck^1!", szKnife[ Knife[ client ] ][ GetCash ] );
  136. }
  137.  
  138. if ( equali( szArgs[ 0 ], "/cash" ) || equali( szArgs[ 0 ], "/cash" ) )
  139. {
  140. new iPlayer = cmd_target( client, szArgs[ 1 ], 8 );
  141.  
  142. if ( equali( szMsg, "/cash" ) || equali( szMsg, "/cash" ) )
  143. iPlayer = client;
  144.  
  145. if( iPlayer == client )
  146. return ColorPrint( client, "You have^3 %i ^1cash, You using a^4 %s^1.", hnr_get_user_credits( client ), szKnife[ UseKnife[ client ] ][ Name ] );
  147.  
  148. if ( !iPlayer )
  149. return ColorPrint( client, "^3%s^1 was not found!", szArgs[ 1 ] );
  150.  
  151. new szNameiPlayer[ 33 ];
  152. get_user_name( iPlayer, szNameiPlayer, charsmax( szNameiPlayer ) );
  153.  
  154. 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 ] );
  155. }
  156.  
  157. return 0;
  158. }
  159.  
  160. public CmdKnife(id)
  161. {
  162. new szMenu[ 300 ];
  163.  
  164. 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 ] )
  165.  
  166. new Menu = menu_create( szMenu, "CmdKnife_sub" );
  167.  
  168. for ( new i = 0; i < sizeof szKnife; i++ )
  169. {
  170. new iText[ 32 ] = ""
  171.  
  172. if( Knife[ id ] >= i )
  173. iText = "\y[ UNLOCKED ]";
  174.  
  175. if( Knife[ id ] < i )
  176. iText = "\r[ LOCKED ]";
  177.  
  178. if( UseKnife[ id ] == i )
  179. iText = "\d[ USING ]";
  180.  
  181. formatex( szMenu, charsmax( szMenu ), "%s%s %s", Knife[ id ]+1 < i ? "\d" : "\w", szKnife[ i ][ Name ], iText);
  182. menu_additem( Menu, szMenu );
  183. }
  184.  
  185. menu_setprop(Menu, MPROP_EXIT, MEXIT_ALL );
  186. menu_setprop(Menu, MPROP_EXITNAME, "\wExit" )
  187. menu_setprop(Menu, MPROP_NUMBER_COLOR, "\r" )
  188. menu_display(id, Menu, 0);
  189.  
  190. return PLUGIN_HANDLED;
  191.  
  192. }
  193.  
  194. public CmdKnife_sub(id, Menu, item)
  195. {
  196. if( item == MENU_EXIT )
  197. {
  198. menu_destroy(Menu);
  199. return PLUGIN_HANDLED;
  200. }
  201.  
  202. new data[6], iName[64];
  203. new access, callback;
  204. menu_item_getinfo(Menu, item, access, data, 6, iName, 63, callback)
  205.  
  206. Currect[ id ] = item;
  207. ViewKnife( id );
  208.  
  209. menu_destroy(Menu);
  210. return PLUGIN_HANDLED;
  211. }
  212.  
  213. public ViewKnife(id)
  214. {
  215. new mCall1 = menu_makecallback( "MenuCallBackb1" );
  216. new mCall2 = menu_makecallback( "MenuCallBackb2" );
  217.  
  218. new szMenu[ 300 ];
  219.  
  220. 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 ] )
  221.  
  222. new Menu = menu_create( szMenu, "ViewKnife_sub" );
  223.  
  224.  
  225. formatex( szMenu, charsmax( szMenu ), "\wPurchase Knife");
  226. menu_additem( Menu, szMenu, "0",_, mCall1 );
  227.  
  228. if(UseKnife[ id ] == Currect[ id ])
  229. {
  230. formatex( szMenu, charsmax( szMenu ), "\dYou already use this knife." );
  231. }
  232.  
  233. else{
  234. formatex( szMenu, charsmax( szMenu ), "\wUse Knife" );
  235. }
  236.  
  237. menu_additem( Menu, szMenu, "1",_, mCall2 );
  238.  
  239. 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 ] );
  240. menu_addtext( Menu, szMenu );
  241.  
  242. menu_setprop(Menu, MPROP_EXIT, MEXIT_ALL );
  243. menu_setprop(Menu, MPROP_EXITNAME, "\wExit" )
  244. menu_setprop(Menu, MPROP_NUMBER_COLOR, "\r" )
  245. menu_display(id, Menu, 0);
  246.  
  247. return PLUGIN_HANDLED;
  248.  
  249. }
  250. public ViewKnife_sub(id, Menu, item)
  251. {
  252. if( item == MENU_EXIT )
  253. {
  254. menu_destroy(Menu);
  255. CmdKnife( id );
  256. return PLUGIN_HANDLED;
  257. }
  258.  
  259. new data[6], iName[64];
  260. new access, callback;
  261. menu_item_getinfo(Menu, item, access, data, 6, iName, 63, callback)
  262.  
  263. switch( item )
  264. {
  265.  
  266. case 0:
  267. {
  268. if( Knife[ id ] >= Currect[ id ] )
  269. return ColorPrint( id, "You have already bought ^4%s^1.", szKnife[ Currect[ id ] ][ Name ] );
  270.  
  271. if( hnr_get_user_credits( id ) < szKnife[ Currect[ id ] ][ Price ] )
  272. return ColorPrint( id,"You don't have enough cash Missing: ^4%i^1.", szKnife[ Currect[ id ] ][ Price ] - hnr_get_user_credits( id ) );
  273.  
  274. if( hnr_get_user_credits( id ) >= szKnife[ Currect[ id ] ][ Price ] )
  275. {
  276. ColorPrint( 0, "^3%s ^1have just bought ^4%s^1.", szName( id ), szKnife[ Currect[ id ] ][ Name ] )
  277. hnr_set_user_credits( id, hnr_get_user_credits( id ) - szKnife[ Currect[ id ] ][ Price ] )
  278. Knife[ id ]++
  279.  
  280. CmdSave( id )
  281. }
  282. }
  283.  
  284. case 1:
  285. {
  286. if( Knife[ id ] >= Currect[ id ] )
  287. {
  288. UseKnife[ id ] = Currect[ id ];
  289. Event_CurWeapon( id );
  290. }
  291.  
  292. return ViewKnife( id );
  293. }
  294.  
  295. }
  296.  
  297. menu_destroy(Menu);
  298. return PLUGIN_HANDLED;
  299. }
  300.  
  301. public MenuCallBackb1( id )
  302. {
  303. if( Knife[ id ] >= Currect[ id ] || Knife[ id ] != Currect[ id ]-1 ) return ITEM_DISABLED
  304. return ITEM_ENABLED
  305. }
  306.  
  307. public MenuCallBackb2( id )
  308. {
  309. if( Knife[ id ] < Currect[ id ] || UseKnife[ id ] == Currect[ id ] ) return ITEM_DISABLED
  310. return ITEM_ENABLED
  311. }
  312.  
  313. /* Data Storage */
  314.  
  315. stock CmdSave( const index )
  316. {
  317. new szKey[ 64 ], szData[ 256 ];
  318.  
  319. formatex( szKey, charsmax( szKey ), "%s-Save", szAuth( index ) );
  320.  
  321. formatex( szData, charsmax( szData ), "%i#", Knife[ index ] );
  322.  
  323. fvault_set_data( szVault, szKey, szData );
  324. }
  325.  
  326. stock CmdLoad( const index )
  327. {
  328. new szKey[ 64 ], szData[ 256 ];
  329.  
  330. formatex( szKey, charsmax( szKey ), "%s-Save", szAuth( index ) );
  331.  
  332. formatex( szData, charsmax( szData ), "%i#", Knife[ index ] );
  333.  
  334. fvault_get_data( szVault, szKey, szData, 255 );
  335.  
  336. replace_all( szData, 255, "#", " " );
  337.  
  338. new SetData[ 1 ][ 32 ];
  339.  
  340. parse( szData, SetData[ 0 ], 31 );
  341.  
  342. Knife[ index ] = str_to_num( SetData[ 0 ] );
  343. }
  344.  
  345. stock szAuth( const index )
  346. {
  347. static g_szAuthID[ 35 ];
  348.  
  349. get_user_authid( index, g_szAuthID, charsmax( g_szAuthID ) );
  350.  
  351. return g_szAuthID;
  352. }
  353.  
  354. stock szName( const index )
  355. {
  356. static wName[ 32 ];
  357.  
  358. get_user_name( index, wName, charsmax( wName ) );
  359.  
  360. return wName;
  361. }
  362.  
  363. stock ColorPrint( const index, const string[], any:... )
  364. {
  365. new szMsg[ 191 ], Players[ 32 ], PNum = 1;
  366.  
  367. static iLen; iLen = formatex( szMsg, charsmax( szMsg ), "^3[%s]^1 ", Prefix );
  368.  
  369. vformat( szMsg[ iLen ], charsmax( szMsg ) - iLen, string, 3 );
  370.  
  371. if ( index )
  372. Players[ 0 ] = index;
  373.  
  374. else
  375. get_players( Players, PNum, "ch" );
  376.  
  377. for ( new i; i < PNum; i++ )
  378. {
  379. if( is_user_connected( Players[ i ] ) )
  380. {
  381. message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ), _, Players[ i ] );
  382.  
  383. write_byte( Players[ i ] );
  384.  
  385. write_string( szMsg );
  386.  
  387. message_end( );
  388. }
  389. }
  390.  
  391. return 1;
  392. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement