HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2.  * Title:
  3.  * CS Armor Drop (on death)
  4.  *
  5.  * Summary:
  6.  * When a player dies, if they have armor, they will drop their armor on the ground next to their corpse.
  7.  * A player can then walk over it and pick it up, letting them get a "percentage" of the armor left behind.
  8.  * Also, the player will recieve the same armor type as what they picked up.
  9.  * All armor will be deleted when round ends. Or on specified time (see cvars).
  10.  *
  11.  * Cvars:
  12.  * armor_pct - (Default 20%) This is percentage of armor that will be received when its picked up.
  13.  * armor_max - (Default 100) This is the max amount of armor a user can get from picking up.
  14.  * armor_min - (Default 15) Minimum armor needed, for player to drop when killed.
  15.  * armor_removetime - (Default 2min) Time before armor is removed from map (unless round ends).
  16.  *
  17.  *
  18.  * Requires : AMXX 1.60
  19.  * Modules : Engine, FakeMeta
  20.  * Tested : Win32 (Linux untested)
  21.  *
  22.  * Author: OneEyed
  23.  * Version: 1.1
  24.  *
  25.  * Thanks : ccnncc99, sXy-Schreck, phear of rice, and Aunt Friggin' Connie,
  26.  * For helping me test and fix this plugin!
  27.  *
  28.  *
  29.  * - Change Log:
  30.  * -v1.1
  31.  * - Fixed to work on AMXX 1.60
  32.  * - Added "Armor Drop" CVAR for queries to pick up.
  33.  */
  34.  
  35. #include <amxmodx>
  36. #include <engine>
  37. #include <fakemeta>
  38. #include <zombieplague>
  39.  
  40. //---------------These values are default, they are added to the CVAR's---------------------
  41. //---------------Change if you want these to be defaulted to the CVAR on SERVER RESTART-----
  42.  
  43. //----------------------------------------------------------------------
  44. //Az eldobott kevlár hány %-ét adja oda annak aki felveszi azt.
  45. #define ARMOR_TAX "25"
  46. //----------------------------------------------------------------------
  47. // Maximum engedélyezett páncél (Lehet magasabbra is)
  48. #define MAXARMOR "100"
  49. //----------------------------------------------------------------------
  50. // Mennyi az a minimum páncél amivel rendelkeznie kell az adott embernek,hogy kidobja azt halála után.
  51. #define MINARMOR "15"
  52. //----------------------------------------------------------------------
  53. // Idõ, ami után eltûnjön a páncél (másodpercben)
  54. #define REMOVE_TIME "120"
  55. //----------------------------------------------------------------------
  56.  
  57. //-------------------------------------------------------------------------------------------------------------
  58. //-----------------------------------DO NOT EDIT BELOW THIS LINE-----------------------------------------------
  59. //-------------------------------------------------------------------------------------------------------------
  60. #define KEVLAR 1
  61. #define VESTHELM 2
  62. #define ARMORTYPE_OFFSET 112
  63.  
  64. #define TITLE "Armor Drop"
  65. #define VERSION "1.0"
  66. #define AUTHOR "djodjo1996"
  67.  
  68. new g_ArmorType[33], Float:g_ArmorAmount[33], fArmor[33]
  69.  
  70. //Change this if you want a custom kevlar model
  71. new armormodel[] = "models/w_kevlar.mdl"
  72. new Float:multiplier
  73. //-------------------------------------------------------------------------------------------------------------
  74. public plugin_precache()
  75. precache_model(armormodel)
  76. //-------------------------------------------------------------------------------------------------------------
  77. public plugin_init() {
  78. register_plugin(TITLE, VERSION, AUTHOR)
  79. register_cvar(TITLE,VERSION,FCVAR_SERVER)
  80.  
  81. if(!cvar_exists("armor_pct"))
  82. register_cvar("armor_pct",ARMOR_TAX)
  83. if(!cvar_exists("armor_max"))
  84. register_cvar("armor_max",MINARMOR)
  85. if(!cvar_exists("armor_min"))
  86. register_cvar("armor_min",MINARMOR)
  87. if(!cvar_exists("armor_removetime"))
  88. register_cvar("armor_removetime",REMOVE_TIME)
  89.  
  90. register_touch("FakeArmor","player","grabArmor")
  91.  
  92. register_event("DeathMsg","createArmor","a")
  93. register_event( "SendAudio", "EndRound", "a", "2=%!MRAD_terwin", "2=%!MRAD_ctwin", "2=%!MRAD_rounddraw" )
  94. }
  95. //-------------------------------------------------------------------------------------------------------------
  96. //-----------Delayed it to be right at the end, (doesnt work if i try to erase it on Round Start)--------------
  97. public EndRound()
  98. set_task(5.0,"removeArmor",1111)
  99.  
  100. public removeArmor() {
  101. new tempid = -1
  102. while ( ( tempid = find_ent_by_class(tempid, "FakeArmor") ) > 0)
  103. if(is_valid_ent(tempid)) {
  104. remove_entity(tempid)
  105. remove_task(tempid)
  106. }
  107. return PLUGIN_CONTINUE
  108. }
  109. //-------------------------------------------------------------------------------------------------------------
  110. // Set task to this to remove the armor after specified amount of time. (armor_removetime)
  111. public removeThisArmor(id)
  112. if(is_valid_ent(id))
  113. remove_entity(id)
  114. //-------------------------------------------------------------------------------------------------------------
  115. public grabArmor(pToucher, pTouched) {
  116. if(zp_get_user_zombie(pTouched))
  117. {
  118. client_print(pTouched, print_center, "Zombi nem tudja használni a páncélt!")
  119. }
  120. else
  121. {
  122. if(is_user_alive(pTouched) && is_user_connected(pTouched) && entity_get_float(pTouched,EV_FL_armorvalue) < float(get_cvar_num("armor_max"))) {
  123. new owner = entity_get_int(pToucher, EV_INT_iuser1)
  124. if(is_valid_ent(fArmor[owner])) {
  125. get_armor_values(pTouched)
  126. multiplier = float(get_cvar_num("armor_pct")) * 0.01
  127.  
  128. //Retrieve armor values left on the dropped kevlar
  129. new armortype = entity_get_int(fArmor[owner], EV_INT_iuser3)
  130. new armoramt = entity_get_int(fArmor[owner], EV_INT_iuser4)
  131.  
  132. //Set armor accordingly to how player has theirs, and what type they grab.
  133. if(g_ArmorType[pTouched] == 0)
  134. csset_user_armor(pTouched, armoramt*multiplier, (armortype==1?KEVLAR:VESTHELM))
  135. else if(g_ArmorType[pTouched] == 1 && armortype == 1)
  136. csset_user_armor(pTouched, entity_get_float(pTouched,EV_FL_armorvalue)+(armoramt*multiplier), KEVLAR)
  137. else if((g_ArmorType[pTouched] == 1 && armortype == 2) || g_ArmorType[pTouched] == 2)
  138. csset_user_armor(pTouched, entity_get_float(pTouched,EV_FL_armorvalue)+(armoramt*multiplier), VESTHELM)
  139.  
  140. // If their armor goes over MAXARMOR set it to MAXARMOR
  141. if(entity_get_float(pTouched,EV_FL_armorvalue) > float(get_cvar_num("armor_max")))
  142. entity_set_float(pTouched,EV_FL_armorvalue, float(get_cvar_num("armor_max")))
  143.  
  144. g_ArmorType[pTouched] = armortype
  145. remove_entity(fArmor[owner])
  146. remove_task(fArmor[owner])
  147. }
  148. }
  149. }
  150. return PLUGIN_HANDLED
  151. }
  152. //-------------------------------------------------------------------------------------------------------------
  153. public createArmor(id) {
  154. new victim = read_data(2) //grab user ID who died
  155.  
  156. get_armor_values(victim)
  157.  
  158. if(g_ArmorType[victim] <= 0 || g_ArmorAmount[victim] <= float(get_cvar_num("armor_min")))
  159. return PLUGIN_CONTINUE
  160. new origin[3]
  161. new Float:fOrigin[3]
  162. get_user_origin(victim,origin)
  163. for(new a=0;a<3;a++)
  164. fOrigin[a]=float(origin[a])
  165.  
  166. fArmor[victim] = create_entity("info_target")
  167. if(fArmor[victim]) {
  168. entity_set_string(fArmor[victim],EV_SZ_classname,"FakeArmor")
  169. entity_set_model(fArmor[victim], armormodel)
  170.  
  171. new Float:MinBox[3]
  172. new Float:MaxBox[3]
  173. MinBox[0] = -6.0
  174. MinBox[1] = -8.0
  175. MinBox[2] = -1.5
  176. MaxBox[0] = 6.0
  177. MaxBox[1] = 8.0
  178. MaxBox[2] = 1.5
  179.  
  180. entity_set_vector(fArmor[victim], EV_VEC_mins, MinBox)
  181. entity_set_vector(fArmor[victim], EV_VEC_maxs, MaxBox)
  182.  
  183. entity_set_int(fArmor[victim], EV_INT_solid, SOLID_BBOX)
  184. entity_set_int(fArmor[victim], EV_INT_movetype, MOVETYPE_TOSS)
  185.  
  186. // Sets iuser1 to victim ID
  187. entity_set_int(fArmor[victim], EV_INT_iuser1, victim)
  188. // Sets iuser3 to Armor Type (kevlar of vest+helm)
  189. entity_set_int(fArmor[victim], EV_INT_iuser3, g_ArmorType[victim])
  190. // Sets iuser4 to Armor Value (amount victim had when he died)
  191. entity_set_int(fArmor[victim], EV_INT_iuser4, floatround(g_ArmorAmount[victim]))
  192.  
  193. entity_set_origin(fArmor[victim], fOrigin)
  194. set_task(float(get_cvar_num("armor_removetime")),"removeThisArmor",fArmor[victim])
  195. }
  196. return PLUGIN_HANDLED
  197. }
  198. //-------------------------------------------------------------------------------------------------------------
  199. public get_armor_values(id) {
  200. if(entity_get_float(id,EV_FL_armorvalue) <= 0.0)
  201. g_ArmorType[id] = 0
  202. else {
  203. g_ArmorAmount[id] = entity_get_float(id,EV_FL_armorvalue)
  204. g_ArmorType[id] = get_pdata_int(id,ARMORTYPE_OFFSET)
  205. }
  206. }
  207. //-------------------------------------------------------------------------------------------------------------
  208. //Cstrike.inc has this function, but its broken, so i made my own that works =).
  209. public csset_user_armor(id, Float:amount, type) {
  210. entity_set_float(id,EV_FL_armorvalue, amount)
  211. set_pdata_int(id,ARMORTYPE_OFFSET,type)
  212. }
  213. //-------------------------------------------------------------------------------------------------------------