Guest User

Untitled

a guest
Mar 10th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.43 KB | None | 0 0
  1. /* AMX Mod X
  2. * AFK Bomb Transfer
  3. *
  4. * (c) Copyright 2006 by VEN
  5. *
  6. * This file is provided as is (no warranties)
  7. *
  8. * DESCRIPTION
  9. * Plugin allow transfer bomb from AFK terrorist to closest non-AFK teammate.
  10. * Plugin will have no effect:
  11. * - at the freezetime
  12. * - if bomb is planting
  13. * - on non-bomb maps (comment #define BOMB_MAP_CHECK to suppress)
  14. *
  15. * MODULES
  16. * fakemeta
  17. *
  18. * CVARS
  19. * afk_bombtransfer_spawn (N: seconds, default: 7) - max. allowed bomb carrier AFK time
  20. * affects on spawned AFK bomb carrier which never moved after spawn
  21. *
  22. * afk_bombtransfer_time (N: seconds, default: 15) - max. allowed bomb carrier AFK time
  23. * affects on any AFK bomb carrier except one which obey previous CVAR
  24. *
  25. * HUD MESSAGES
  26. * Terrorist team (green color)
  27. * Bomb transferred to "NEW_CARRIER_NAME"
  28. * since "AFK_CARRIER_NAME" is AFK
  29. *
  30. * New bomb carrier (yellow color)
  31. * You got the bomb!
  32. *
  33. * Note: by defult message display time is 7 seconds (define MSG_TIME)
  34. *
  35. * VERSIONS
  36. * 0.4 backpack transfer method greatly improved
  37. * added pcvar natives support (backward compatibility saved)
  38. * few code optimization
  39. * 0.3 now fakemeta instead of engine required (efficiency++ if engine is disabled)
  40. * "non-bomb map" check can be disabled (//#define BOMB_MAP_CHECK)
  41. * backpack finding method improved
  42. * few code optimization
  43. * added comments to the plugin source code
  44. * 0.2 fixed format issue
  45. * code optimized
  46. * description improved
  47. *
  48. * 0.1 first release
  49. */
  50.  
  51. /* *************************************************** Init **************************************************** */
  52.  
  53. #include <amxmodx>
  54. #include <fakemeta>
  55.  
  56. // plugin's main information
  57. #define PLUGIN_NAME "AFK Bomb Transfer"
  58. #define PLUGIN_VERSION "0.4"
  59. #define PLUGIN_AUTHOR "VEN"
  60.  
  61. // comment to avoid autodisabling the plugin on maps which not contain bomb targets
  62. #define BOMB_MAP_CHECK
  63.  
  64. // float value, hud messages display time (in seconds)
  65. #define MSG_TIME 7.0
  66.  
  67. // CVAR name, affects on spawned AFK bomb carrier which never moved after spawn
  68. new CVAR_SPAWN[] = "afk_bombtransfer_spawn"
  69.  
  70. // CVAR value, max. allowed bomb carrier AFK time (in seconds)
  71. new DEFAULT_SPAWN[] = "7"
  72.  
  73. // CVAR name, affects on any AFK bomb carrier except one which obey previous CVAR
  74. new CVAR_TIME[] = "afk_bombtransfer_time"
  75.  
  76. // CVAR value, max. allowed bomb carrier AFK time (in seconds)
  77. new DEFAULT_TIME[] = "15"
  78.  
  79. // do not set this value less than "maxplayers"
  80. #define MAX_PLAYERS 32
  81.  
  82. // initial AMXX version number supported CVAR pointers in get/set_pcvar_* natives
  83. #define CVAR_POINTERS_AMXX_INIT_VER_NUM 170
  84.  
  85. // determine if get/set_pcvar_* natives can be used
  86. #if defined AMXX_VERSION_NUM && AMXX_VERSION_NUM >= CVAR_POINTERS_AMXX_INIT_VER_NUM
  87. #define CVAR_POINTERS
  88. new g_pcvar_spawn
  89. new g_pcvar_time
  90. #endif
  91.  
  92. new TEAM[] = "TERRORIST"
  93. new WEAPON[] = "weapon_c4"
  94.  
  95. #define FL_ONGROUND (1<<9)
  96.  
  97. new bool:g_freezetime = true
  98. new bool:g_spawn
  99. new bool:g_planting
  100.  
  101. new g_carrier
  102.  
  103. new g_pos[MAX_PLAYERS + 1][3]
  104. new g_time[MAX_PLAYERS + 1]
  105.  
  106. new g_maxplayers
  107.  
  108. public plugin_init() {
  109. register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
  110.  
  111. #if defined CVAR_POINTERS
  112. g_pcvar_spawn = register_cvar(CVAR_SPAWN, DEFAULT_SPAWN)
  113. g_pcvar_time = register_cvar(CVAR_TIME, DEFAULT_TIME)
  114. #else
  115. register_cvar(CVAR_SPAWN, DEFAULT_SPAWN)
  116. register_cvar(CVAR_TIME, DEFAULT_TIME)
  117. #endif
  118.  
  119. #if defined BOMB_MAP_CHECK
  120. // is current map not contain bomb targets?
  121. if (!engfunc(EngFunc_FindEntityByString, -1, "classname", "func_bomb_target"))
  122. return
  123. #endif
  124.  
  125. register_event("WeapPickup", "event_got_bomb", "be", "1=6")
  126. register_event("BarTime", "event_bar_time", "be")
  127. register_event("TextMsg", "event_bomb_drop", "bc", "2=#Game_bomb_drop")
  128. register_event("TextMsg", "event_bomb_drop", "a", "2=#Bomb_Planted")
  129. register_event("HLTV", "event_new_round", "a", "1=0", "2=0")
  130.  
  131. register_logevent("logevent_round_start", 2, "1=Round_Start")
  132.  
  133. set_task(1.0, "task_afk_check", _, _, _, "b") // plugin's core loop
  134.  
  135. g_maxplayers = get_maxplayers()
  136. }
  137.  
  138. /* *************************************************** Base **************************************************** */
  139.  
  140. public event_new_round() {
  141. g_freezetime = true
  142. g_spawn = true
  143. g_planting = false
  144. g_carrier = 0
  145. }
  146.  
  147. public event_got_bomb(id) {
  148. g_carrier = id
  149. }
  150.  
  151. public event_bar_time(id) {
  152. if (id == g_carrier) {
  153. g_planting = bool:read_data(1)
  154. get_user_origin(id, g_pos[id])
  155. g_time[id] = 0
  156. }
  157. }
  158.  
  159. public event_bomb_drop() {
  160. g_spawn = false
  161. g_planting = false
  162. g_carrier = 0
  163. }
  164.  
  165. public logevent_round_start() {
  166. new id[32], num
  167. get_players(id, num, "ae", TEAM)
  168.  
  169. if (!num) // is server empty?
  170. return
  171.  
  172. g_freezetime = false
  173.  
  174. // update afk timers and current positions
  175. new x
  176. for (new i = 0; i < num; ++i) {
  177. x = id[i]
  178. get_user_origin(x, g_pos[x])
  179. g_time[x] = 0
  180. }
  181. }
  182.  
  183. public task_afk_check() {
  184. if (g_freezetime) // is freezetime right now?
  185. return
  186.  
  187. // afk check
  188. new id[32], num, x, origin[3]
  189. get_players(id, num, "ae", TEAM)
  190. for (new i = 0; i < num; ++i) {
  191. x = id[i]
  192. get_user_origin(x, origin)
  193. if (origin[0] != g_pos[x][0] || origin[1] != g_pos[x][1] || (x == g_carrier && g_planting)) {
  194. g_time[x] = 0
  195. g_pos[x][0] = origin[0]
  196. g_pos[x][1] = origin[1]
  197. if (g_spawn && x == g_carrier)
  198. g_spawn = false
  199. }
  200. else
  201. g_time[x]++
  202. }
  203.  
  204. // is bomb not currently carried or Ts number less than 2?
  205. if (!g_carrier || num < 2)
  206. return
  207.  
  208. #if defined CVAR_POINTERS
  209. new max_time = get_pcvar_num(g_spawn ? g_pcvar_spawn : g_pcvar_time)
  210. #else
  211. new max_time = get_cvar_num(g_spawn ? CVAR_SPAWN : CVAR_TIME)
  212. #endif
  213.  
  214. // is plugin disabled (cvar <= 0) or carrier isn't afk?
  215. if (max_time <= 0 || g_time[g_carrier] < max_time)
  216. return
  217.  
  218. // find who from non-afk Ts is the closest to the afk carrier
  219. get_user_origin(g_carrier, origin)
  220. new min_dist = 999999, dist, recipient, origin2[3]
  221. for (new i = 0; i < num; ++i) {
  222. x = id[i]
  223. if (g_time[x] < max_time) {
  224. get_user_origin(x, origin2)
  225. dist = get_distance(origin, origin2)
  226. if (dist < min_dist) {
  227. min_dist = dist
  228. recipient = x
  229. }
  230. }
  231. }
  232.  
  233. if (!recipient) // is all Ts afk?
  234. return
  235.  
  236. new carrier = g_carrier
  237. engclient_cmd(carrier, "drop", WEAPON) // drop the backpack
  238. new c4 = engfunc(EngFunc_FindEntityByString, -1, "classname", WEAPON) // find weapon_c4 entity
  239. if (!c4)
  240. return
  241.  
  242. new backpack = pev(c4, pev_owner) // get backpack entity
  243. if (backpack <= g_maxplayers)
  244. return
  245.  
  246. // my backpack transfer trick (improved)
  247. set_pev(backpack, pev_flags, pev(backpack, pev_flags) | FL_ONGROUND)
  248. dllfunc(DLLFunc_Touch, backpack, recipient)
  249.  
  250. // hud messages stuff below
  251. set_hudmessage(0, 255, 0, 0.35, 0.8, _, _, MSG_TIME)
  252. new message[128], c_name[32], r_name[32]
  253. get_user_name(carrier, c_name, 31)
  254. get_user_name(recipient, r_name, 31)
  255. format(message, 127, "Bomb transferred to ^"%s^"^nsince ^"%s^" is AFK", r_name, c_name)
  256. for (new i = 0; i < num; ++i)
  257. show_hudmessage(id[i], "%s", message)
  258.  
  259. set_hudmessage(255, 255, 0, 0.42, 0.3, _, _, MSG_TIME, _, _, 3)
  260. show_hudmessage(recipient, "You got the bomb!")
  261. }
  262.  
  263. /* **************************************************** EOF **************************************************** */
Add Comment
Please, Sign In to add comment