HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <cstrike>
  4. #include <csdm>
  5.  
  6. new D_PLUGIN[] = "CSDM Main"
  7. new D_ACCESS = ADMIN_MAP
  8.  
  9. #define CSDM_OPTIONS_TOTAL 2
  10.  
  11. new bool:g_StripWeapons = true
  12. new bool:g_RemoveBomb = true
  13. new g_StayTime
  14. new g_drop_fwd
  15. new g_options[CSDM_OPTIONS_TOTAL]
  16.  
  17. //new g_MenuPages[33]
  18. new g_MainMenu = -1
  19.  
  20. public plugin_natives()
  21. {
  22. register_native("csdm_main_menu", "native_main_menu")
  23. register_native("csdm_set_mainoption", "__csdm_allow_option")
  24. register_native("csdm_fwd_drop", "__csdm_fwd_drop")
  25. register_library("csdm_main")
  26. }
  27.  
  28. public native_main_menu(id, num)
  29. {
  30. return g_MainMenu
  31. }
  32.  
  33. public __csdm_allow_option(id, num)
  34. {
  35. new option = get_param(1)
  36.  
  37. if (option <= 0 || option >= CSDM_OPTIONS_TOTAL)
  38. {
  39. log_error(AMX_ERR_NATIVE, "Invalid option number: %d", option)
  40. return 0
  41. }
  42.  
  43. g_options[option] = get_param(2)
  44.  
  45. return 1
  46. }
  47.  
  48. public __csdm_fwd_drop(id, num)
  49. {
  50. new id = get_param(1)
  51. new wp = get_param(2)
  52. new name[32]
  53.  
  54. get_string(3, name, 31)
  55.  
  56. return run_drop(id, wp, name)
  57. }
  58.  
  59. public csdm_Init(const version[])
  60. {
  61. if (version[0] == 0)
  62. {
  63. set_fail_state("CSDM failed to load.")
  64. return
  65. }
  66. }
  67.  
  68. public csdm_CfgInit()
  69. {
  70. csdm_reg_cfg("settings", "read_cfg")
  71. }
  72.  
  73. public plugin_init()
  74. {
  75. register_plugin(D_PLUGIN, CSDM_VERSION, "CSDM Team")
  76.  
  77. register_clcmd("say respawn", "say_respawn")
  78. register_clcmd("say /respawn", "say_respawn")
  79.  
  80. register_concmd("csdm_enable", "csdm_enable", D_ACCESS, "Enables CSDM")
  81. register_concmd("csdm_disable", "csdm_disable", D_ACCESS, "Disables CSDM")
  82. register_concmd("csdm_ctrl", "csdm_ctrl", D_ACCESS, "")
  83. register_concmd("csdm_reload", "csdm_reload", D_ACCESS, "Reloads CSDM Config")
  84. register_clcmd("csdm_menu", "csdm_menu", ADMIN_MENU, "CSDM Menu")
  85. register_clcmd("drop", "hook_drop")
  86.  
  87. register_concmd("csdm_cache", "cacheInfo", ADMIN_MAP, "Shows cache information")
  88.  
  89. AddMenuItem("CSDM Menu", "csdm_menu", D_ACCESS, D_PLUGIN)
  90. g_MainMenu = menu_create("CSDM Menu", "use_csdm_menu")
  91.  
  92. new callback = menu_makecallback("hook_item_display")
  93. menu_additem(g_MainMenu, "DM Be/DM Ki", "csdm_ctrl", D_ACCESS, callback)
  94. menu_additem(g_MainMenu, "DM config ujratoltese", "csdm_reload", D_ACCESS)
  95.  
  96. g_drop_fwd = CreateMultiForward("csdm_HandleDrop", ET_CONTINUE, FP_CELL, FP_CELL, FP_CELL)
  97. }
  98.  
  99. public cacheInfo(id, level, cid)
  100. {
  101. if (!cmd_access(id, level, cid, 1))
  102. return PLUGIN_HANDLED
  103.  
  104. new ar[6]
  105. csdm_cache(ar)
  106.  
  107. console_print(id, "[CSDM] Free tasks: respawn=%d, findweapon=%d", ar[0], ar[5])
  108. console_print(id, "[CSDM] Weapon removal cache: %d total, %d live", ar[4], ar[3])
  109. console_print(id, "[CSDM] Live tasks: %d (%d free)", ar[2], ar[1])
  110.  
  111. return PLUGIN_HANDLED
  112. }
  113.  
  114. public hook_drop(id)
  115. {
  116. if (!csdm_active())
  117. {
  118. return
  119. }
  120.  
  121. if (!is_user_connected(id))
  122. {
  123. return
  124. }
  125.  
  126. new wp, c, a, name[24]
  127. if (cs_get_user_shield(id))
  128. {
  129. //entirely different...
  130. wp = -1
  131. copy(name, 23, "weapon_shield")
  132. } else {
  133. if (read_argc() <= 1)
  134. {
  135. wp = get_user_weapon(id, c, a)
  136. } else {
  137. read_argv(1, name, 23)
  138. wp = getWepId(name)
  139. }
  140. }
  141.  
  142. run_drop(id, wp, name)
  143. }
  144.  
  145. run_drop(id, wp, const name[])
  146. {
  147. new ret
  148. ExecuteForward(g_drop_fwd, ret, id, wp, 0)
  149.  
  150. if (ret == CSDM_DROP_REMOVE)
  151. {
  152. new _name[24]
  153. if (name[0] == 0)
  154. {
  155. get_weaponname(wp, _name, 23)
  156. }
  157. csdm_remove_weapon(id, _name, 0, 1)
  158. return 1
  159. } else if (ret == CSDM_DROP_IGNORE) {
  160. return 0
  161. }
  162.  
  163. if (g_StayTime > 20 || g_StayTime < 0)
  164. {
  165. return 0
  166. }
  167.  
  168. if (wp)
  169. {
  170. remove_weapon(id, wp)
  171. return 1
  172. }
  173.  
  174. return 0
  175. }
  176.  
  177. public csdm_PostDeath(killer, victim, headshot, const weapon[])
  178. {
  179. if (g_StayTime > 20 || g_StayTime < 0)
  180. return PLUGIN_CONTINUE
  181.  
  182. new weapons[MAX_WEAPONS], num, name[24]
  183. new wp, slot, ret
  184.  
  185. get_user_weapons(victim, weapons, num)
  186.  
  187. for (new i=0; i<num; i++)
  188. {
  189. wp = weapons[i]
  190. slot = g_WeaponSlots[wp]
  191.  
  192. ExecuteForward(g_drop_fwd, ret, victim, wp, 1)
  193.  
  194. if (ret == CSDM_DROP_REMOVE)
  195. {
  196. get_weaponname(wp, name, 23)
  197. csdm_remove_weapon(victim, name, 0, 1)
  198. } else if (ret == CSDM_DROP_IGNORE) {
  199. continue
  200. } else {
  201. if (slot == SLOT_PRIMARY || slot == SLOT_SECONDARY || slot == SLOT_C4)
  202. {
  203. remove_weapon(victim, wp)
  204. }
  205. }
  206. }
  207.  
  208. if (cs_get_user_shield(victim))
  209. {
  210. ExecuteForward(g_drop_fwd, ret, victim, -1, 1)
  211. if (ret == CSDM_DROP_REMOVE)
  212. {
  213. csdm_remove_weapon(victim, "weapon_shield", 0, 1)
  214. } else if (ret == CSDM_DROP_IGNORE) {
  215. /* do nothing */
  216. } else {
  217. remove_weapon(victim, -1)
  218. }
  219. }
  220.  
  221. return PLUGIN_CONTINUE
  222. }
  223.  
  224. public csdm_PreSpawn(player, bool:fake)
  225. {
  226. //we'll just have to back out for now
  227. if (cs_get_user_shield(player))
  228. {
  229. return
  230. }
  231. new team = get_user_team(player)
  232. if (g_StripWeapons)
  233. {
  234. if (team == _TEAM_T)
  235. {
  236. if (cs_get_user_shield(player))
  237. {
  238. drop_with_shield(player, CSW_GLOCK18)
  239. } else {
  240. csdm_force_drop(player, "weapon_glock18")
  241. }
  242. } else if (team == _TEAM_CT) {
  243. if (cs_get_user_shield(player))
  244. {
  245. drop_with_shield(player, CSW_USP)
  246. } else {
  247. csdm_force_drop(player, "weapon_usp")
  248. }
  249. }
  250. }
  251. if (team == _TEAM_T)
  252. {
  253. if (g_RemoveBomb)
  254. {
  255. new weapons[MAX_WEAPONS], num
  256. get_user_weapons(player, weapons, num)
  257. for (new i=0; i<num; i++)
  258. {
  259. if (weapons[i] == CSW_C4)
  260. {
  261. if (cs_get_user_shield(player))
  262. {
  263. drop_with_shield(player, CSW_C4)
  264. } else {
  265. csdm_force_drop(player, "weapon_c4")
  266. }
  267. break
  268. }
  269. }
  270. }
  271. }
  272. }
  273.  
  274. remove_weapon(id, wp)
  275. {
  276. new name[24]
  277.  
  278. if (wp == -1)
  279. {
  280. copy(name, 23, "weapon_shield")
  281. } else {
  282. get_weaponname(wp, name, 23)
  283. }
  284.  
  285. if ((wp == CSW_C4) && g_RemoveBomb)
  286. {
  287. csdm_remove_weapon(id, name, 0, 1)
  288. } else {
  289. if (wp != CSW_C4)
  290. {
  291. csdm_remove_weapon(id, name, g_StayTime, 1)
  292. }
  293. }
  294. }
  295.  
  296. public hook_item_display(player, menu, item)
  297. {
  298. new paccess, command[24], call
  299.  
  300. menu_item_getinfo(menu, item, paccess, command, 23, _, 0, call)
  301.  
  302. if (equali(command, "csdm_ctrl"))
  303. {
  304. if (!csdm_active())
  305. {
  306. menu_item_setname(menu, item, "DM Be")
  307. } else {
  308. menu_item_setname(menu, item, "DM Ki")
  309. }
  310. }
  311. }
  312.  
  313. public read_cfg(readAction, line[], section[])
  314. {
  315. if (readAction == CFG_READ)
  316. {
  317. new setting[24], sign[3], value[32];
  318.  
  319. parse(line, setting, 23, sign, 2, value, 31);
  320.  
  321. if (equali(setting, "strip_weapons"))
  322. {
  323. g_StripWeapons = str_to_num(value) ? true : false
  324. } else if (equali(setting, "weapons_stay")) {
  325. g_StayTime = str_to_num(value)
  326. } else if (equali(setting, "spawnmode")) {
  327. new var = csdm_setstyle(value)
  328. if (var)
  329. {
  330. log_amx("CSDM spawn mode set to %s", value)
  331. } else {
  332. log_amx("CSDM spawn mode %s not found", value)
  333. }
  334. } else if (equali(setting, "remove_bomb")) {
  335. g_RemoveBomb = str_to_num(value) ? true : false
  336. } else if (equali(setting, "enabled")) {
  337. csdm_set_active(str_to_num(value))
  338. } else if (equali(setting, "spawn_wait_time")) {
  339. csdm_set_spawnwait(str_to_float(value))
  340. }
  341. }
  342. }
  343.  
  344. public csdm_reload(id, level, cid)
  345. {
  346. if (!cmd_access(id, level, cid, 1))
  347. return PLUGIN_HANDLED
  348.  
  349. new file[33] = ""
  350. if (read_argc() >= 2)
  351. {
  352. read_argv(1, file, 32)
  353. }
  354.  
  355. if (csdm_reload_cfg(file))
  356. {
  357. client_print(id, print_chat, "[CSDM] Deathmatch config ujratoltve.")
  358. } else {
  359. client_print(id, print_chat, "[CSDM] nem lehet ujratolteni a csdm.cfg-t.")
  360. }
  361.  
  362. return PLUGIN_HANDLED
  363. }
  364.  
  365. public csdm_menu(id, level, cid)
  366. {
  367. if (!cmd_access(id, level, cid, 1))
  368. return PLUGIN_HANDLED
  369.  
  370. menu_display(id, g_MainMenu, 0)
  371.  
  372. return PLUGIN_HANDLED
  373. }
  374.  
  375. public csdm_ctrl(id, level, cid)
  376. {
  377. if (!cmd_access(id, level, cid, 1))
  378. return PLUGIN_HANDLED
  379.  
  380. csdm_set_active( csdm_active() ? 0 : 1 )
  381. client_print(id, print_chat, "CSDM Deathmatch mod fut,Magyarositotta,Expert_IMI")
  382.  
  383. return PLUGIN_HANDLED
  384. }
  385.  
  386. public use_csdm_menu(id, menu, item)
  387. {
  388. if (item < 0)
  389. return PLUGIN_CONTINUE
  390.  
  391. new command[24], paccess, call
  392. if (!menu_item_getinfo(g_MainMenu, item, paccess, command, 23, _, 0, call))
  393. {
  394. log_amx("Error: csdm_menu_item() failed (menu %d) (page %d) (item %d)", g_MainMenu, 0, item)
  395. return PLUGIN_HANDLED
  396. }
  397. if (paccess && !(get_user_flags(id) & paccess))
  398. {
  399. client_print(id, print_chat, "Nem engedelyezett ez a menu opciok.")
  400. return PLUGIN_HANDLED
  401. }
  402.  
  403. client_cmd(id, command)
  404.  
  405. return PLUGIN_HANDLED
  406. }
  407.  
  408. public csdm_enable(id, level, cid)
  409. {
  410. if (!cmd_access(id, level, cid, 1))
  411. return PLUGIN_HANDLED
  412.  
  413. csdm_set_active(1)
  414. client_print(id, print_chat, "CSDM Deathmatch mod bekapcsolva.")
  415.  
  416. return PLUGIN_HANDLED
  417. }
  418.  
  419. public csdm_disable(id, level, cid)
  420. {
  421. if (!cmd_access(id, level, cid, 1))
  422. return PLUGIN_HANDLED
  423.  
  424. csdm_set_active(0)
  425. client_print(id, print_chat, "CSDM Deathmach mod kikapcsolva.")
  426.  
  427. return PLUGIN_HANDLED
  428. }
  429.  
  430. public say_respawn(id)
  431. {
  432. if (g_options[CSDM_OPTION_SAYRESPAWN] == CSDM_SET_DISABLED)
  433. {
  434. client_print(id, print_chat, "[CSDM] Parancs letiltva")
  435. return PLUGIN_HANDLED
  436. }
  437.  
  438. if (!is_user_alive(id) && csdm_active())
  439. {
  440. new team = get_user_team(id)
  441. if (team == _TEAM_T || team == _TEAM_CT)
  442. {
  443. csdm_respawn(id)
  444. }
  445. }
  446.  
  447. return PLUGIN_CONTINUE
  448. }
  449.