daily pastebin goal
29%
SHARE
TWEET

Untitled

a guest Jun 17th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <amxmodx>
  3. #include <fakemeta>
  4. #include <hamsandwich>
  5. #include <nvault>
  6. #include <zombieplague>
  7.  
  8. new const RANKS_ZOMBIE[][]=
  9. {
  10.     "Normal Infected", // 0
  11.     "Experimental Zombie", // 1
  12.     "Mutant", // 2
  13.     "Advanced Mutant", // 3
  14.     "Staff Sergeant", // 4
  15.     "Special Infected", // 5
  16.     "Soldier Infected", // 6
  17.     "Umbrella Infected", // 7
  18.     "Majini", // 8
  19.     "Chainsaw Majini", // 9
  20.     "Giant Majini", // 10
  21.     "Gatling Gun Majini", // 11
  22.     "Executioner", // 12
  23.     "Regenerator", // 13
  24.     "Bio-Organic Zombie", // 14
  25.     "Verdugo", // 15
  26.     "Thanatos", // 16
  27.     "Tyrant", // 17
  28.     "Nemesis" // 18
  29. }
  30.  
  31. new const EXP_ZOMBIE[] =
  32. {
  33.     0, // 0
  34.     50, // 1
  35.     100, // 2
  36.     200, // 3
  37.     400, // 4
  38.     800, // 5
  39.     1600, // 6
  40.     3200, // 7
  41.     6400, // 8
  42.     12800, // 9
  43.     25600, // 10
  44.     51200, // 11
  45.     102400, // 12
  46.     204800, // 13
  47.     409600, // 14
  48.     819200, // 15
  49.     1638400, // 16
  50.     3276800, // 17
  51.     6553600 // 18
  52. }
  53.  
  54. #define ADMIN_FLAG  ADMIN_BAN
  55.  
  56. new g_bitConnectedPlayers, g_bitAlivePlayers, g_bitAuthorizedPlayers
  57.  
  58. #define MarkUserConnected(%0)   g_bitConnectedPlayers |= (1 << (%0 & 31))
  59. #define ClearUserConnected(%0)  g_bitConnectedPlayers &= ~(1 << (%0 & 31))
  60. #define IsUserConnected(%0) g_bitConnectedPlayers & (1 << (%0 & 31))
  61.  
  62. #define MarkUserAlive(%0)       g_bitAlivePlayers |= (1 << (%0 & 31))
  63. #define ClearUserAlive(%0)      g_bitAlivePlayers &= ~(1 << (%0 & 31))
  64. #define IsUserAlive(%0)     g_bitAlivePlayers & (1 << (%0 & 31))
  65.  
  66. #define MarkUserAllow(%0)       g_bitAuthorizedPlayers |= (1 << (%0 & 31))
  67. #define ClearUserAllow(%0)      g_bitAuthorizedPlayers &= ~(1 << (%0 & 31))
  68. #define IsUserAllow(%0)     g_bitAuthorizedPlayers & (1 << (%0 & 31))
  69.  
  70. #define IsPlayer(%0)        (1 <= %0 <= g_iMaxPlayers)
  71.  
  72. new cvar_xp, cvar_hsxp, cvar_assistxp, cvar_divide
  73. new cached_xp, cached_hsxp, cached_assistxp, cached_divide
  74.  
  75. new g_msgSayText, g_iMaxPlayers
  76.  
  77. new iXP[33], iRank[33], iMaxHealth[33]
  78. new iDamage[33][33], iKilledHuman[33][33]
  79.  
  80. new iIP[33][32]
  81.  
  82. new g_iVault
  83.  
  84. public plugin_init()
  85. {
  86.     register_plugin("[ZP] Addon: Military Ranks", "1.0", "Snaker-Beatter+eXcalibur.007")
  87.    
  88.     cvar_xp = register_cvar("zp_rank_zombie_kill", "10")
  89.     cvar_hsxp = register_cvar("zp_rank_zombie_hkill", "25")
  90.     cvar_assistxp = register_cvar("zp_rank_zombie_assisth", "15")
  91.     cvar_divide = register_cvar("zp_rank_zombie_assisthpdivide", "5")
  92.    
  93.     register_concmd("rankzombieclear", "clear_vault", ADMIN_FLAG, "Clears rank database")
  94.    
  95.     register_clcmd("say", "hook_say")
  96.     register_clcmd("say_team", "hook_say_team")
  97.     register_clcmd("say /showrank_zombie", "show_stats")
  98.     register_clcmd("say_team /showrank_zombie", "show_stats")
  99.    
  100.     register_event("HLTV", "event_new_round", "a", "1=0", "2=0")
  101.     register_event("Damage", "event_Damage", "be", "2!0", "3=0", "4!0")
  102.     register_event("DeathMsg", "event_DeathMsg", "a", "1>0")
  103.     RegisterHam(Ham_Spawn, "player", "Fw_SpawnPost", 1)
  104.    
  105.     g_msgSayText = get_user_msgid("SayText")
  106.    
  107.     g_iMaxPlayers = get_maxplayers()
  108.    
  109.     g_iVault = nvault_open("zp_vault_rank")
  110.    
  111.     if(g_iVault == INVALID_HANDLE)
  112.         set_fail_state("Vault file error")
  113.    
  114.     register_message(g_msgSayText, "message_SayText")
  115. }
  116.  
  117. public plugin_cfg()
  118. {
  119.     cached_xp = get_pcvar_num(cvar_xp)
  120.     cached_hsxp = get_pcvar_num(cvar_hsxp)
  121.     cached_assistxp = get_pcvar_num(cvar_assistxp)
  122.     cached_divide = get_pcvar_num(cvar_divide)
  123. }
  124.  
  125. public plugin_end()
  126. {
  127.     new iPlayers[32], iNum
  128.     get_players(iPlayers, iNum)
  129.    
  130.     new iPlayer
  131.     for(new i = 0; i < iNum; i++)
  132.     {
  133.         iPlayer = iPlayers[i]
  134.        
  135.         SaveData(iPlayer)
  136.     }
  137.    
  138.     nvault_close(g_iVault)
  139. }
  140.  
  141. public client_putinserver(id)
  142. {
  143.     MarkUserConnected(id)
  144.    
  145.     get_user_ip(id, iIP[id], 31)
  146.    
  147.     LoadData(id)
  148. }
  149.  
  150. public client_authorized(id)
  151. {
  152.     MarkUserAllow(id)
  153. }
  154.  
  155. public client_disconnect(id)
  156. {
  157.     if(IsUserAllow(id))
  158.         SaveData(id)
  159.    
  160.     iRank[id] = 0
  161.     iXP[id] = 0
  162.    
  163.     ClearUserConnected(id)
  164.     ClearUserAlive(id)
  165.     ClearUserAllow(id)
  166. }
  167.  
  168. public clear_vault()
  169. {
  170.     if(g_iVault)
  171.         nvault_prune(g_iVault, 0, get_systime())
  172. }
  173.  
  174. public hook_say(id)
  175. {
  176.     new szMessage[192], szName[32]
  177.    
  178.     read_args(szMessage, 191)
  179.     remove_quotes(szMessage)
  180.     get_user_name(id, szName, 31)
  181.    
  182.     if(equali(szMessage[0], " ") || equali(szMessage[0], "") || !is_valid_msg(szMessage))
  183.         return PLUGIN_HANDLED_MAIN
  184.        
  185.     if(IsUserAlive(id))
  186.         format(szMessage, 191, "^4[%s] ^3%s : ^1%s", RANKS_ZOMBIE[iRank[id]], szName, szMessage)
  187.     else
  188.         format(szMessage, 191, "^1*DEAD* ^4[%s] ^3%s : ^1%s", RANKS_ZOMBIE[iRank[id]], szName, szMessage)
  189.    
  190.     new iPlayers[32]
  191.     new iPlayerCount, i, player
  192.     get_players(iPlayers, iPlayerCount, "ch")
  193.    
  194.     for(i = 0; i < iPlayerCount; i++)
  195.     {
  196.         player = iPlayers[i]
  197.        
  198.         if(IsUserAlive(id) && IsUserAlive(player) || ~IsUserAlive(id) && ~IsUserAlive(player))
  199.         {
  200.             message_begin(MSG_ONE, g_msgSayText, {0, 0, 0}, player)
  201.             write_byte(id)
  202.             write_string(szMessage)
  203.             message_end()
  204.         }
  205.     }
  206.    
  207.     return PLUGIN_CONTINUE
  208. }
  209.  
  210. public hook_say_team(id)
  211. {
  212.     new szMessage[192], szName[32]
  213.    
  214.     read_args(szMessage, 191)
  215.     remove_quotes(szMessage)
  216.     get_user_name(id, szName, 31)
  217.    
  218.     if(equali(szMessage[0], " ") || equali(szMessage[0], "") || !is_valid_msg(szMessage))
  219.         return PLUGIN_HANDLED_MAIN
  220.    
  221.     if(IsUserAlive(id))
  222.         format(szMessage, 191, "^4[%s] ^3%s : ^1%s", RANKS_ZOMBIE[iRank[id]], szName, szMessage)
  223.     else
  224.         format(szMessage, 191, "^1*DEAD* ^4[%s] ^3%s : ^1%s", RANKS_ZOMBIE[iRank[id]], szName, szMessage)
  225.    
  226.     new teamid = get_user_team(id)
  227.    
  228.     new iPlayers[32]
  229.     new iPlayerCount, i, player
  230.     get_players(iPlayers, iPlayerCount, "ch")
  231.    
  232.     for(i = 0; i < iPlayerCount; i++)
  233.     {
  234.         player = iPlayers[i]
  235.        
  236.         new teami = get_user_team(player)
  237.        
  238.         if(IsUserAlive(id) && IsUserAlive(player) && teamid == teami || ~IsUserAlive(id) && ~IsUserAlive(player) && teamid == teami)
  239.         {
  240.             message_begin(MSG_ONE, g_msgSayText, {0, 0, 0}, player)
  241.             write_byte(id)
  242.             write_string(szMessage)
  243.             message_end()
  244.         }
  245.     }
  246.    
  247.     return PLUGIN_CONTINUE
  248. }
  249.  
  250. public show_stats(id)
  251. {
  252.     if(IsUserConnected(id))
  253.     {
  254.         client_print(id, print_chat, "[ZP] Rank: %s | EXP: %d | EXP needed to next rank: %d", RANKS_ZOMBIE[iRank[id]], iXP[id], (EXP_ZOMBIE[iRank[id] + 1] - iXP[id]))
  255.     }
  256. }
  257.  
  258. public event_new_round()
  259. {
  260.     cached_xp = get_pcvar_num(cvar_xp)
  261.     cached_hsxp = get_pcvar_num(cvar_hsxp)
  262.     cached_assistxp = get_pcvar_num(cvar_assistxp)
  263.     cached_divide = get_pcvar_num(cvar_divide)
  264.    
  265.     new iPlayers[32]
  266.     new iPlayerCount, i, player
  267.     get_players(iPlayers, iPlayerCount, "h")
  268.    
  269.     for(i = 0; i < iPlayerCount; i++)
  270.     {
  271.         player = iPlayers[i]
  272.        
  273.         iDamage[player][player] = 0
  274.     }
  275. }
  276.  
  277. public event_Damage(iVictim)
  278. {
  279.     if(IsUserAlive(iVictim) && IsPlayer(iVictim) && !zp_get_user_zombie(iVictim))
  280.     {
  281.         static iAttacker; iAttacker = get_user_attacker(iVictim)
  282.        
  283.         if(IsPlayer(iAttacker))
  284.             iDamage[iAttacker][iVictim] += read_data(2)
  285.     }
  286. }
  287.  
  288. public event_DeathMsg()
  289. {
  290.     static iKiller; iKiller = read_data(1)
  291.     static iVictim; iVictim = read_data(2)
  292.     static iIsHeadshot; iIsHeadshot = read_data(3)
  293.    
  294.     ClearUserAlive(iVictim)
  295.    
  296.     if(iVictim == iKiller || !zp_get_user_zombie(iKiller) || zp_get_user_zombie(iVictim))
  297.         return PLUGIN_CONTINUE
  298.        
  299.     if(~IsUserAllow(iKiller))
  300.     {
  301.         client_print(iKiller, print_chat, "[ZP] Your will not gain EXP until you are registered or logged in to save your rank")
  302.         return PLUGIN_CONTINUE
  303.     }
  304.    
  305.     if(iIsHeadshot)
  306.     {
  307.                
  308.         iKilledHuman[iKiller][iVictim] = true
  309.         iXP[iKiller] += cached_hsxp
  310.        
  311.         client_print(iKiller, print_chat, "[ZP] You've gained %d EXP for killing a human with a headshot", cached_hsxp)
  312.     }
  313.     else
  314.     {
  315.         iKilledHuman[iKiller][iVictim] = true
  316.         iXP[iKiller] += cached_xp
  317.        
  318.         client_print(iKiller, print_chat, "[ZP] You've gained %d EXP for killing a human", cached_xp)
  319.     }
  320.        
  321.     while((iXP[iKiller] >= EXP_ZOMBIE[iRank[iKiller] + 1] && iRank[iKiller] < 18))
  322.     {
  323.         iRank[iKiller] += 1
  324.        
  325.         client_print(iKiller, print_chat, "[ZP] Congratulations, your rank is now^x04 %s", RANKS_ZOMBIE[iRank[iKiller]])
  326.     }
  327.    
  328.     new iPlayers[32]
  329.     new iPlayerCount, i, id
  330.     get_players(iPlayers, iPlayerCount, "h")
  331.    
  332.     for(i = 0; i < iPlayerCount; i++)
  333.     {
  334.         id = iPlayers[i]
  335.        
  336.         if(iDamage[id][iVictim] >= iMaxHealth[iVictim] / cached_divide)
  337.         {
  338.             if(!iKilledHuman[id][iVictim])
  339.             {
  340.                 iXP[id] += cached_assistxp
  341.                
  342.                 new szName[32]
  343.                 get_user_name(iKiller, szName, charsmax(szName))
  344.                
  345.                 client_print(id, print_chat, "[ZP] You've gained %d EXP for assisting %s %s", cached_assistxp, RANKS_ZOMBIE[iRank[iKiller]], szName)
  346.                
  347.                 while((iXP[id] >= EXP_ZOMBIE[iRank[id] + 1] && iRank[id] < 18))
  348.                 {
  349.                     iRank[id] += 1
  350.                    
  351.                     client_print(i, print_chat, "[ZP] Congratulations, your rank is now %s", RANKS_ZOMBIE[iRank[id]])
  352.                 }
  353.                
  354.                 iDamage[id][iVictim] = 0
  355.             }
  356.             else
  357.             {
  358.                 iKilledHuman[id][iVictim] = false
  359.             }
  360.         }
  361.            
  362.     }
  363.    
  364.     return PLUGIN_CONTINUE
  365. }
  366.  
  367. public Fw_SpawnPost(id)
  368. {
  369.     if(is_user_alive(id))
  370.         MarkUserAlive(id)
  371. }
  372.  
  373. public message_SayText(id)
  374. {
  375.     return PLUGIN_HANDLED
  376. }
  377.  
  378. public zp_user_infected_post(id)
  379. {
  380.     iMaxHealth[id] = zp_get_zombie_maxhealth(id)
  381. }
  382.  
  383. SaveData(id)
  384. {
  385.     new szData[35]
  386.     new szKey[40]
  387.    
  388.     formatex(szKey, 39, "%s", iIP[id])
  389.     formatex(szData, 34, "%d %d", iRank[id], iXP[id])
  390.    
  391.     nvault_set(g_iVault, szKey, szData)
  392. }
  393.  
  394. LoadData(id)
  395. {
  396.     new szData[32]
  397.     new szKey[40]
  398.    
  399.     formatex(szKey , 39, "%s" , iIP[id])
  400.    
  401.     if(nvault_get(g_iVault, szKey, szData, 31))
  402.     {
  403.         new iSpacePos = contain(szData, " ")
  404.        
  405.         if(iSpacePos > -1)
  406.         {    
  407.             new szRank[2]
  408.             new szXP[32]
  409.            
  410.             parse(szData , szRank, 1, szXP, 31)
  411.            
  412.             iRank[id] = str_to_num(szRank)
  413.             iXP[id] = str_to_num(szXP)
  414.         }
  415.     }
  416. }
  417.  
  418. bool:is_valid_msg(const szMessage[])
  419. {
  420.     if(szMessage[0] == '@' || szMessage[0] == '/' || szMessage[0] == '!' || !strlen(szMessage))
  421.         return false
  422.        
  423.     return true
  424. }
  425.  
  426. stock Create_TE_PLAYERATTACHMENT(id, entity, vOffset, iSprite, life)
  427. {
  428.     message_begin(MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, _, id)
  429.     write_byte(TE_PLAYERATTACHMENT)
  430.     write_byte(entity)
  431.     write_coord(vOffset)
  432.     write_short(iSprite)
  433.     write_short(life)
  434.     message_end()
  435. }
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