HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /* AMX Mod X
  2. * Teleport Smoke Grenade
  3. *
  4. * (c) Copyright 2006 by VEN
  5. *
  6. * This file is provided as is (no warranties)
  7. *
  8. * DESCRIPTION
  9. * Plugin changes the smoke grenade to teleport grenade with a bit of smoke.
  10. * Usage: drop the grenade, you will be teleported to the spot of explosion.
  11. * Try to crouch if the height of the spot are small for uncrouched player.
  12. *
  13. * CREDITS
  14. * Dread Pirate - idea
  15. */
  16.  
  17. #include <amxmodx>
  18. #include <fakemeta>
  19.  
  20. #define PLUGIN_NAME "Teleport Smoke Grenade"
  21. #define PLUGIN_VERSION "0.1"
  22. #define PLUGIN_AUTHOR "VEN"
  23.  
  24. #define SMOKE_SCALE 30
  25. #define SMOKE_FRAMERATE 12
  26. #define SMOKE_GROUND_OFFSET 6
  27.  
  28. // do not edit
  29. new const g_sound_explosion[] = "weapons/sg_explode.wav"
  30. new const g_classname_grenade[] = "grenade"
  31.  
  32. new const Float:g_sign[4][2] = {{1.0, 1.0}, {1.0, -1.0}, {-1.0, -1.0}, {-1.0, 1.0}}
  33.  
  34. new g_spriteid_steam1
  35. new g_eventid_createsmoke
  36.  
  37. public plugin_init() {
  38. register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
  39.  
  40. register_forward(FM_EmitSound, "forward_emitsound")
  41. register_forward(FM_PlaybackEvent, "forward_playbackevent")
  42.  
  43. // we do not precaching, but retrieving the indexes
  44. g_spriteid_steam1 = engfunc(EngFunc_PrecacheModel, "sprites/steam1.spr")
  45. g_eventid_createsmoke = engfunc(EngFunc_PrecacheEvent, 1, "events/createsmoke.sc")
  46. }
  47.  
  48. public forward_emitsound(ent, channel, const sound[]) {
  49. if (!equal(sound, g_sound_explosion) || !is_grenade(ent))
  50. return FMRES_IGNORED
  51.  
  52. static id, Float:origin[3]
  53. id = pev(ent, pev_owner)
  54. pev(ent, pev_origin, origin)
  55. engfunc(EngFunc_EmitSound, ent, CHAN_WEAPON, g_sound_explosion, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  56. engfunc(EngFunc_RemoveEntity, ent)
  57. origin[2] += SMOKE_GROUND_OFFSET
  58. create_smoke(origin)
  59.  
  60. if (is_user_alive(id)) {
  61. static Float:mins[3], hull
  62. pev(id, pev_mins, mins)
  63. origin[2] -= mins[2] + SMOKE_GROUND_OFFSET
  64. hull = pev(id, pev_flags) & FL_DUCKING ? HULL_HEAD : HULL_HUMAN
  65. if (is_hull_vacant(origin, hull))
  66. engfunc(EngFunc_SetOrigin, id, origin)
  67. else { // close to a solid object, trying to find a vacant spot
  68. static Float:vec[3]
  69. vec[2] = origin[2]
  70. for (new i; i < sizeof g_sign; ++i) {
  71. vec[0] = origin[0] - mins[0] * g_sign[i][0]
  72. vec[1] = origin[1] - mins[1] * g_sign[i][1]
  73. if (is_hull_vacant(vec, hull)) {
  74. engfunc(EngFunc_SetOrigin, id, vec)
  75. break
  76. }
  77. }
  78. }
  79. }
  80.  
  81. return FMRES_SUPERCEDE
  82. }
  83.  
  84. public forward_playbackevent(flags, invoker, eventindex) {
  85. // we do not need a large amount of smoke
  86. if (eventindex == g_eventid_createsmoke)
  87. return FMRES_SUPERCEDE
  88.  
  89. return FMRES_IGNORED
  90. }
  91.  
  92. bool:is_grenade(ent) {
  93. if (!pev_valid(ent))
  94. return false
  95.  
  96. static classname[sizeof g_classname_grenade + 1]
  97. pev(ent, pev_classname, classname, sizeof g_classname_grenade)
  98. if (equal(classname, g_classname_grenade))
  99. return true
  100.  
  101. return false
  102. }
  103.  
  104. create_smoke(const Float:origin[3]) {
  105. // engfunc because origin are float
  106. engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0)
  107. write_byte(TE_SMOKE)
  108. engfunc(EngFunc_WriteCoord, origin[0])
  109. engfunc(EngFunc_WriteCoord, origin[1])
  110. engfunc(EngFunc_WriteCoord, origin[2])
  111. write_short(g_spriteid_steam1)
  112. write_byte(SMOKE_SCALE)
  113. write_byte(SMOKE_FRAMERATE)
  114. message_end()
  115. }
  116.  
  117. stock bool:is_hull_vacant(const Float:origin[3], hull) {
  118. new tr = 0
  119. engfunc(EngFunc_TraceHull, origin, origin, 0, hull, 0, tr)
  120. if (!get_tr2(tr, TR_StartSolid) && !get_tr2(tr, TR_AllSolid) && get_tr2(tr, TR_InOpen))
  121. return true
  122.  
  123. return false
  124. }
  125.