HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <fakemeta>
  3. #include <xs>
  4.  
  5. #define PLUGIN "CS Revo: Gun Drop Effect"
  6. #define VERSION "1.0"
  7. #define AUTHOR "Wilian M."
  8.  
  9. #define DROP_GUN_MODEL "models/gundrop.mdl"
  10. #define DROP_GUN_CLASSNAME "drop_gun_ef"
  11.  
  12. public plugin_init()
  13. {
  14. register_plugin(PLUGIN, VERSION, AUTHOR)
  15.  
  16. register_forward(FM_SetModel, "xFwSetModel")
  17. register_forward(FM_Think, "xFwThink")
  18. register_forward(FM_Touch, "xFwTouch")
  19. }
  20.  
  21. public plugin_precache()
  22. {
  23. precache_model(DROP_GUN_MODEL)
  24. }
  25.  
  26. public xFwTouch(touched, ent)
  27. {
  28. if(!pev_valid(ent))
  29. return FMRES_IGNORED
  30.  
  31. static xClassName[32]
  32. pev(ent, pev_classname, xClassName, charsmax(xClassName))
  33.  
  34. if(equal(xClassName, "weaponbox") || equal(xClassName, DROP_GUN_CLASSNAME))
  35. {
  36. xFlatEnt(ent)
  37. }
  38.  
  39. return FMRES_IGNORED
  40. }
  41.  
  42. public xFwThink(ent)
  43. {
  44. if(!pev_valid(ent))
  45. return FMRES_IGNORED
  46.  
  47. static xClassName[32]
  48. pev(ent, pev_classname, xClassName, charsmax(xClassName))
  49.  
  50. if(!equal(xClassName, DROP_GUN_CLASSNAME))
  51. return FMRES_IGNORED
  52.  
  53. static xWpn
  54. xWpn = pev(ent, pev_iuser1)
  55.  
  56. if(!pev_valid(xWpn))
  57. {
  58. set_pev(ent, pev_flags, pev(ent, pev_flags) | FL_KILLME)
  59.  
  60. return FMRES_SUPERCEDE
  61. }
  62.  
  63. set_pev(ent, pev_nextthink, get_gametime())
  64.  
  65. return FMRES_IGNORED
  66. }
  67.  
  68. public xFwSetModel(ent, model[])
  69. {
  70. if(!pev_valid(ent) || !equali(model, "models/w_", 8) || equali(model, "models/w_weaponbox.mdl"))
  71. return FMRES_IGNORED
  72.  
  73. static xClassName[32]
  74. pev(ent, pev_classname, xClassName, charsmax(xClassName))
  75.  
  76. if(!equal(xClassName, "weaponbox"))
  77. return FMRES_IGNORED
  78.  
  79. static xGunDrop
  80. xGunDrop = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
  81.  
  82. if(!pev_valid(xGunDrop))
  83. return FMRES_IGNORED
  84.  
  85. set_pev(xGunDrop, pev_classname, DROP_GUN_CLASSNAME)
  86. engfunc(EngFunc_SetModel, xGunDrop, DROP_GUN_MODEL)
  87. set_pev(xGunDrop, pev_iuser1, ent)
  88. set_pev(xGunDrop, pev_framerate, 1.0)
  89. set_pev(xGunDrop, pev_animtime, get_gametime())
  90. set_pev(xGunDrop, pev_movetype, MOVETYPE_FOLLOW)
  91. set_pev(xGunDrop, pev_aiment, ent)
  92. set_pev(xGunDrop, pev_nextthink, get_gametime())
  93.  
  94. return FMRES_IGNORED
  95. }
  96.  
  97. stock xFlatEnt(ent)
  98. {
  99. if(pev(ent, pev_flags) & ~FL_ONGROUND) return
  100.  
  101. static Float:origin[3], Float:traceto[3], trace = 0, Float:fraction, Float:angles[3], Float:angles2[3]
  102.  
  103. pev(ent, pev_origin, origin)
  104. pev(ent, pev_angles, angles)
  105.  
  106. xs_vec_sub(origin, Float:{0.0, 0.0, 10.0}, traceto)
  107.  
  108. engfunc(EngFunc_TraceLine, origin, traceto, IGNORE_MONSTERS, ent, trace)
  109.  
  110. get_tr2(trace, TR_flFraction, fraction)
  111.  
  112. if(fraction == 1.0) return
  113.  
  114. static Float:original_forward[3]
  115. angle_vector(angles, ANGLEVECTOR_FORWARD, original_forward)
  116.  
  117. static Float:right[3], Float:up[3], Float:fwd[3]
  118.  
  119. get_tr2(trace, TR_vecPlaneNormal, up)
  120.  
  121. if(up[2] == 1.0) return
  122.  
  123. xs_vec_cross(original_forward, up, right)
  124. xs_vec_cross(up, right, fwd)
  125. vector_to_angle(fwd, angles)
  126. vector_to_angle(right, angles2)
  127.  
  128. angles[2] = -1.0 * angles2[0]
  129.  
  130. set_pev(ent, pev_angles, angles)
  131. }