SHARE
TWEET

Untitled

a guest Feb 1st, 2019 146 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include < amxmodx >
  2. #include < amxmisc >
  3. #include < fvault >
  4.  
  5. #define PLUGIN  "Zombie XP"
  6. #define VERSION "1.0 Beta"
  7. #define AUTHOR  "LondoN eXtream"
  8.  
  9. #define SAVE_FILE_NAME  "ZPXP_fVault"
  10. #define MAX_LEVEL   10
  11.  
  12. new g_PlayerName [ 33 ] [ 32 ];
  13. new g_Experience [ 33 ], g_Level [ 33 ];
  14. new g_CvarAmmoPacksDamage;
  15.  
  16. new const ExperienceNeed [ MAX_LEVEL ] =
  17. {
  18.     0,  //  Level 1
  19.     500,    //  Level 2
  20.     1000,   //  Level 3
  21.     2000,   //  Level 4
  22.     3500,   //  Level 5
  23.     4000,   //  Level 6
  24.     5500,   //  Level 7
  25.     6300,   //  Level 8
  26.     7200,   //  Level 9
  27.     9000,   //  Level 10
  28. }
  29.  
  30. public plugin_init ( )
  31. {
  32.     register_plugin ( PLUGIN, VERSION, AUTHOR );
  33.     register_cvar ( "zombie_xp_london", VERSION, FCVAR_SERVER|FCVAR_SPONLY );
  34.     set_cvar_string ( "zombie_xp_london", VERSION );
  35.  
  36.     g_CvarAmmoPacksDamage = register_cvar ( "zp_xp_damage_for_experience", "500" );
  37.  
  38.     register_event ( "Damage", "Event_UserMakeDamage", "b", "2!=0" );
  39.     register_event ( "DeathMsg", "Event_UserKillSomeone", "a" );
  40. }
  41.  
  42. public plugin_natives ( )
  43. {
  44.     register_native ( "zpxp_set_experience", "_set_experience", 1 );
  45.     register_native ( "zpxp_get_experience", "_get_experience", 1 );
  46.     register_native ( "zpxp_set_level", "_set_level", 1 );
  47.     register_native ( "zpxp_get_level", "_get_level", 1 );
  48. }
  49.  
  50. public _set_experience ( Player, Amount )
  51. {
  52.     if ( !is_user_connected ( Player ) )
  53.         return;
  54.  
  55.     g_Experience [ Player ] += Amount;
  56.  
  57.     check_user_level ( Player );
  58. }
  59.  
  60. public _get_experience ( Player )
  61. {
  62.     return g_Experience [ Player ];
  63. }
  64.  
  65. public _set_level ( Player, Level )
  66. {
  67.     if ( !is_user_connected ( Player ) )
  68.         return;
  69.  
  70.     if ( Level > MAX_LEVEL )
  71.         return;
  72.  
  73.     g_Level [ Player ] = Level;
  74.  
  75.     g_Experience [ Player ] = ExperienceNeed [ g_Level [ Player ] ];
  76. }
  77.  
  78. public _get_level ( Player )
  79. {
  80.     return g_Level [ Player ];
  81. }
  82.  
  83. public Event_UserMakeDamage ( Player )
  84. {
  85.     new Damage = read_data ( 2 );
  86.     new ID = get_user_attacker ( Player );
  87.  
  88.     if ( ID == Player || !ID || !is_user_alive ( ID ) )
  89.         return;
  90.  
  91.     while ( Damage >= get_pcvar_num ( g_CvarAmmoPacksDamage ) )
  92.     {
  93.         Damage -= get_pcvar_num ( g_CvarAmmoPacksDamage );
  94.         g_Experience [ ID ] += random_num ( 1, 3 );
  95.     }
  96.  
  97.     check_user_level ( ID );
  98.  
  99. }
  100.  
  101.  
  102. public Event_UserKillSomeone ( )
  103. {
  104.     new Attacker;   Attacker = read_data ( 1 );
  105.     new Victim; Victim = read_data ( 2 );
  106.  
  107.     if ( Attacker == Victim || !Attacker || !is_user_alive ( Attacker ) )
  108.         return;
  109.  
  110.     g_Experience [ Attacker ] += 20;
  111.  
  112.     check_user_level ( Attacker );
  113. }
  114.  
  115. public check_user_level ( Player )
  116. {
  117.     if ( g_Level [ Player ] < MAX_LEVEL )
  118.     {
  119.         while ( g_Experience [ Player ] >= ExperienceNeed [ g_Level [ Player ] ] )
  120.         {
  121.             g_Level [ Player ]++;
  122.         }
  123.     }
  124.  
  125.     save_user_data ( Player );
  126. }
  127.  
  128. public client_connect ( Player )
  129. {
  130.     if ( is_user_bot ( Player ) || is_user_hltv ( Player ) )
  131.         return;
  132.  
  133.     get_user_name ( Player, g_PlayerName [ Player ], charsmax ( g_PlayerName ) );
  134.  
  135.     load_user_data ( Player );
  136. }
  137.  
  138. public client_disconnect ( Player )
  139. {
  140.     if ( is_user_bot ( Player ) || is_user_hltv ( Player ) )
  141.         return;
  142.  
  143.     save_user_data ( Player );
  144. }
  145.  
  146. public save_user_data ( Player )
  147. {
  148.     new g_String [ 32 ];
  149.     formatex ( g_String, charsmax ( g_String ), "%s %s", g_Level [ Player ], g_Experience [ Player ] );
  150.  
  151.     fvault_set_data ( SAVE_FILE_NAME, g_PlayerName [ Player ], g_String );
  152. }
  153.  
  154. public load_user_data ( Player )
  155. {
  156.     new g_String [ 32 ];
  157.    
  158.     if ( fvault_get_data ( SAVE_FILE_NAME, g_PlayerName [ Player ], g_String, charsmax ( g_String ) ) )
  159.     {
  160.         // a = level | b = experience
  161.         new a [ 16 ], b [ 16 ];
  162.         parse ( g_String, a, charsmax ( a ), b, charsmax ( b ) );
  163.  
  164.         g_Level [ Player ] = str_to_num ( a );
  165.         g_Experience [ Player ] = str_to_num ( b );
  166.     }
  167.     else
  168.     {
  169.         g_Level [ Player ] = 0;
  170.         g_Experience [ Player ] = 0;
  171.     }
  172. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top