HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2. Copyright © 2014, zmd94.
  3.  
  4. This plugin is free software;
  5. you can redistribute it and/or modify it under the terms of the
  6. GNU General Public License as published by the Free Software Foundation.
  7.  
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. */
  13.  
  14. #include <amxmodx>
  15. #include <cs_core>
  16. #include <hamsandwich>
  17. #include <engine>
  18.  
  19. // Configure access flag to open war menu and start vote command. ;)
  20. #define ADMIN_FLAG ADMIN_VOTE
  21.  
  22. #define MAXPLAYERS 32
  23. #define TASK_RESPAWN 1994
  24.  
  25. enum (+= 123)
  26. {
  27. TASK_HUD = 1234,
  28. TASK_VOTE
  29. }
  30.  
  31. enum _:TOTAL_FORWARDS
  32. {
  33. FW_WAR_ROUND_START = 0,
  34. FW_WAR_ROUND_END,
  35. FW_WAR_VOTE_START,
  36. FW_WAR_VOTE_END,
  37. }
  38.  
  39. enum _:WEAPONSWAR
  40. {
  41. WeaponType[64],
  42. WeaponName[64],
  43. WeaponID[64]
  44. }
  45.  
  46. new const WeaponsData[][WEAPONSWAR] =
  47. {
  48. {"Hand-gun", "9x19mm Side-arm", "weapon_glock18"},
  49. {"Hand-gun", "KM.45 Tactical", "weapon_usp"},
  50. {"Hand-gun", "228 Compact", "weapon_p228"},
  51. {"Hand-gun", "Night Haw2.50c", "weapon_deagle"},
  52. {"Hand-gun", "Elites", "weapon_elite"},
  53. {"Hand-gun", "Five-Seven", "weapon_fiveseven"},
  54. {"Shotgun", "12 gauge", "weapon_m3"},
  55. {"Shotgun", "Auto-Shotgun", "weapon_xm1014"},
  56. {"Sub-machine", "TMP", "weapon_tmp"},
  57. {"Sub-machine", "MP5-Navy", "weapon_mp5navy"},
  58. {"Sub-machine", "KM-UMP45", "weapon_ump45"},
  59. {"Sub-machine", "ES-C90", "weapon_p90"},
  60. {"Sub-machine", "Ingram MAC-10", "weapon_mac10"},
  61. {"Rifles", "IDF-Defender", "weapon_galil"},
  62. {"Rifles", "Famas", "weapon_famas"},
  63. {"Rifles", "AK-47", "weapon_ak47"},
  64. {"Rifles", "M4A1", "weapon_m4a1"},
  65. {"Rifles", "Scout", "weapon_scout"},
  66. {"Rifles", "Ster-Aug", "weapon_aug"},
  67. {"Rifles", "Krieg 552", "weapon_sg552"},
  68. {"Rifles", "Krieg 550", "weapon_sg550"},
  69. {"Rifles", "Magnum", "weapon_awp"},
  70. {"Rifles", "D3/AU-1", "weapon_g3sg1"},
  71. {"Heavy", "Machine-gun", "weapon_m249"},
  72. {"Melee", "Knife", "weapon_knife"},
  73. {"Nade", "HE grenade", "weapon_hegrenade"}
  74. }
  75.  
  76. // Bool
  77. new bool:g_bInWar
  78. new bool:g_bHEWar
  79. new bool:g_bStartWar
  80. new bool:g_bVote
  81.  
  82. // Floats
  83. const Float:HUD_MODE_X = 0.75 // X Position ( --- )
  84. const Float:HUD_MODE_Y = 0.20 // Y Position ( ||| )
  85.  
  86. // String
  87. new g_sWeaponWar[32], g_sWeaponID[32]
  88.  
  89. // Variables
  90. new g_ForwardResult
  91. new g_Forwards[TOTAL_FORWARDS]
  92.  
  93. new g_iPoints[MAXPLAYERS+1]
  94. new g_iAllVote[MAXPLAYERS+1]
  95. new g_iVotes[2]
  96. new g_iVoteMenu, g_iVoteTime
  97.  
  98. new g_WarMenu
  99. new g_iVotingTime, g_iBullet, g_iUnlimitClip, g_iShowHud
  100. new g_iPointLeader, g_iPointBonus, g_iBonusAmount
  101. new g_iAutoWarVote, g_iVoteCountdown, g_iAutoWarStart, g_iWarCountdown
  102. new g_iVoteDelay, g_iWarDelay
  103. new g_iAutoRespawn
  104.  
  105. new g_iMsgSayTxt, g_iSyncHud
  106.  
  107. public plugin_init()
  108. {
  109. register_plugin("Weapons War", "6.2", "zmd94")
  110.  
  111. register_dictionary("cs_war.txt")
  112.  
  113. register_clcmd("drop", "clcmd_drop")
  114.  
  115. register_clcmd("say /ww", "clcmd_war")
  116. register_clcmd("say_team /ww", "clcmd_war")
  117. register_clcmd("say /wvote", "clcmd_vote")
  118. register_clcmd("say_team /wvote", "clcmd_vote")
  119.  
  120. register_event("HLTV", "event_new_round", "a", "1=0", "2=0")
  121. register_event("TextMsg", "event_restart", "a", "2&#Game_C", "2&#Game_w")
  122. register_event("CurWeapon", "event_CurWeapon", "be", "1=1")
  123.  
  124. register_logevent("logevent_round_start", 2, "1=Round_Start")
  125. register_logevent("logevent_round_end", 2, "1=Round_End")
  126.  
  127. RegisterHam(Ham_Spawn, "player", "fw_PlayerRespawn", 1)
  128. RegisterHam(Ham_Killed, "player", "fw_PlayerKilled", 1)
  129.  
  130. RegisterHam(Ham_Touch, "weaponbox", "fw_TouchWeapon")
  131. RegisterHam(Ham_Touch, "weapon_shield", "fw_TouchWeapon")
  132. RegisterHam(Ham_Touch, "armoury_entity", "fw_TouchWeapon")
  133.  
  134. g_iBullet = register_cvar("ww_allow_bullet", "0") // Allow player to have unlimited bullet
  135. g_iShowHud = register_cvar("ww_show_war_hud", "1") // Show current war round. ;)
  136. g_iVotingTime = register_cvar("ww_vote_time", "30") // Time for vote
  137. g_iPointLeader = register_cvar("ww_point_leader", "1") // Enable showing point leader
  138. g_iPointBonus = register_cvar("ww_leader_bonus", "1") // Enable point leader bonus
  139. g_iBonusAmount = register_cvar("ww_bonus_amount", "2000") // Amount of money given
  140. g_iAutoWarVote = register_cvar("ww_auto_vote", "1") // Allow auto war vote
  141. g_iVoteDelay = register_cvar("ww_vote_delay", "2") // Amount of round delay for auto war vote
  142. g_iAutoWarStart = register_cvar("ww_auto_war", "1") // Allow auto war start
  143. g_iWarDelay = register_cvar("ww_war_delay", "3") // Amount of round delay for auto war start
  144. g_iAutoRespawn = register_cvar("ww_allow_respawn", "1") // Allow auto respawn during war round
  145.  
  146. // Forwards
  147. g_Forwards[FW_WAR_ROUND_START] = CreateMultiForward("cs_fw_war_start", ET_IGNORE, FP_CELL)
  148. g_Forwards[FW_WAR_ROUND_END] = CreateMultiForward("cs_fw_war_end", ET_IGNORE, FP_CELL)
  149. g_Forwards[FW_WAR_VOTE_START] = CreateMultiForward("cs_fw_vote_start", ET_IGNORE)
  150. g_Forwards[FW_WAR_VOTE_END] = CreateMultiForward("cs_fw_vote_end", ET_IGNORE)
  151.  
  152. g_iMsgSayTxt = get_user_msgid("SayText")
  153. g_iSyncHud = CreateHudSyncObj()
  154.  
  155. g_WarMenu = menu_create("\yWeapons War \rv6.2", "war_handler")
  156.  
  157. new szItem[64]
  158. for(new i; i < sizeof(WeaponsData); i++)
  159. {
  160. formatex(szItem, charsmax(szItem), "%s: \y%s", WeaponsData[i][WeaponType], WeaponsData[i][WeaponName])
  161. menu_additem(g_WarMenu, szItem)
  162. }
  163. }
  164.  
  165. public plugin_cfg()
  166. {
  167. g_iUnlimitClip = get_pcvar_num(g_iBullet)
  168. }
  169.  
  170. public plugin_end()
  171. {
  172. menu_destroy(g_WarMenu)
  173. }
  174.  
  175. public plugin_natives()
  176. {
  177. register_library("cs_war")
  178. register_native("cs_is_war_round", "native_is_war_round")
  179. register_native("cs_current_war", "native_current_war")
  180. register_native("cs_get_war_id", "native_get_war_id")
  181. }
  182.  
  183. public native_is_war_round()
  184. {
  185. return g_bInWar
  186. }
  187.  
  188. public native_current_war()
  189. {
  190. return g_sWeaponWar
  191. }
  192.  
  193. public native_get_war_id()
  194. {
  195. new szWarID[32]
  196. get_string(1, szWarID, charsmax(szWarID))
  197. }
  198.  
  199. public event_new_round()
  200. {
  201. new iPlayers[32], iPlayerCount, i, id
  202.  
  203. get_players(iPlayers, iPlayerCount, "c")
  204. for(i = 0; i < iPlayerCount; i++)
  205. {
  206. id = iPlayers[i]
  207. g_iAllVote[id] = false
  208.  
  209. g_iPoints[id] = 0
  210. }
  211.  
  212. g_bInWar = false
  213. g_bHEWar = false
  214. g_bVote = false
  215.  
  216. remove_task(TASK_HUD)
  217. remove_task(TASK_VOTE)
  218. }
  219.  
  220. public event_restart()
  221. {
  222. g_iWarCountdown = 0
  223. g_iVoteCountdown = 0
  224. }
  225.  
  226. public logevent_round_start()
  227. {
  228. if(g_bStartWar)
  229. {
  230. StartWar()
  231.  
  232. g_bStartWar = false
  233. }
  234. else
  235. {
  236. if(get_pcvar_num(g_iAutoWarVote))
  237. {
  238. if(g_iVoteCountdown >= get_pcvar_num(g_iVoteDelay))
  239. {
  240. new iWeaponIndex = random(sizeof WeaponsData)
  241.  
  242. copy(g_sWeaponWar, charsmax(g_sWeaponWar), WeaponsData[iWeaponIndex][WeaponName])
  243. copy(g_sWeaponID, charsmax(g_sWeaponID), WeaponsData[iWeaponIndex][WeaponID])
  244.  
  245. set_task(get_pcvar_float(g_iVotingTime), "EndVote", TASK_VOTE)
  246.  
  247. print_colored(0, "!g[WW]!t %L", LANG_PLAYER, "VOTE3", get_pcvar_num(g_iVotingTime))
  248.  
  249. g_bVote = true
  250. g_iVoteTime --
  251.  
  252. StartVote()
  253.  
  254. g_iVoteCountdown = 0
  255. }
  256.  
  257. g_iVoteCountdown ++
  258. }
  259.  
  260. if(get_pcvar_num(g_iAutoWarStart))
  261. {
  262. if(g_iWarCountdown >= get_pcvar_num(g_iWarDelay))
  263. {
  264. new iWeaponIndex = random(sizeof WeaponsData)
  265.  
  266. copy(g_sWeaponWar, charsmax(g_sWeaponWar), WeaponsData[iWeaponIndex][WeaponName])
  267. copy(g_sWeaponID, charsmax(g_sWeaponID), WeaponsData[iWeaponIndex][WeaponID])
  268.  
  269. StartWar()
  270.  
  271. g_iWarCountdown = 0
  272. }
  273.  
  274. g_iWarCountdown ++
  275. }
  276. }
  277. }
  278.  
  279. public logevent_round_end()
  280. {
  281. if(g_bInWar)
  282. {
  283. new iPlayers[32], iPlayerCount, i, id
  284.  
  285. get_players(iPlayers, iPlayerCount, "a")
  286. for(i = 0; i < iPlayerCount; i++)
  287. {
  288. id = iPlayers[i]
  289.  
  290. if(g_bHEWar)
  291. {
  292. cs_grenade_reward(id, 191, 0)
  293.  
  294. g_bHEWar = false
  295. }
  296.  
  297. remove_task(id+TASK_RESPAWN)
  298. }
  299.  
  300. if(get_pcvar_num(g_iPointLeader))
  301. {
  302. new iPoints, Others
  303. new iLeader = FindLeader(iPoints)
  304.  
  305. get_players(iPlayers, iPlayerCount, "c" )
  306. for ( new i = 0; i < iPlayerCount; i++ )
  307. {
  308. Others = g_iPoints[i]
  309. }
  310.  
  311. if(iPoints == Others)
  312. {
  313. set_hudmessage(random_num(10,255), random(256), random(256), -1.0, 0.20, 0, 3.0, 6.0, 0.0, 0.0, -1)
  314. show_hudmessage(0, "%L", LANG_PLAYER, "EQUAL")
  315. }
  316. else
  317. {
  318. new szName[32]
  319. get_user_name(iLeader, szName, charsmax(szName))
  320.  
  321. set_hudmessage(random_num(10,255), random(256), random(256), -1.0, 0.20, 0, 3.0, 6.0, 0.0, 0.0, -1)
  322. show_hudmessage(0, "%L", LANG_PLAYER, "LEADER", szName, iPoints)
  323.  
  324. if (get_pcvar_num(g_iPointBonus))
  325. {
  326. cs_money_reward(iLeader, get_pcvar_num(g_iBonusAmount), 1)
  327. print_colored(0, "!g[WW]!t %L", LANG_PLAYER, "WORD3", szName, iPoints)
  328. }
  329. }
  330. }
  331.  
  332. ExecuteForward(g_Forwards[FW_WAR_ROUND_END], g_ForwardResult, g_sWeaponWar)
  333. }
  334. }
  335.  
  336. FindLeader(&iPoints)
  337. {
  338. new iPlayers[32], iPlayerCount, i, id
  339. new iLeader, iAllPoints
  340.  
  341. get_players(iPlayers, iPlayerCount, "c")
  342. for ( i = 0; i < iPlayerCount; i++ )
  343. {
  344. id = iPlayers[i]
  345. iAllPoints = g_iPoints[id]
  346.  
  347. if (iAllPoints > iPoints)
  348. {
  349. iPoints = iAllPoints
  350. iLeader = id
  351. }
  352. }
  353.  
  354. return iLeader;
  355. }
  356.  
  357. public fw_PlayerRespawn(id)
  358. {
  359. if (g_bInWar && is_user_alive(id))
  360. {
  361. if(g_bHEWar)
  362. {
  363. cs_grenade_reward(id, 191, 0)
  364. }
  365. else
  366. {
  367. cs_weapon_reward(id, g_sWeaponID)
  368. }
  369.  
  370. if(g_iUnlimitClip)
  371. {
  372. cs_unlimited_reward(id, 2, 0, 0.0)
  373. }
  374. }
  375. }
  376.  
  377. public fw_PlayerKilled(iVictim, iKiller)
  378. {
  379. if (!g_bInWar || !is_user_alive(iKiller) || iVictim == iKiller)
  380. return
  381.  
  382. if(get_pcvar_num(g_iPointLeader))
  383. {
  384. g_iPoints[iKiller] ++
  385. }
  386.  
  387. if(get_pcvar_num(g_iAutoRespawn))
  388. {
  389. set_task(3.0, "AutoRespawn", iVictim+TASK_RESPAWN)
  390. }
  391. }
  392.  
  393. public AutoRespawn(id)
  394. {
  395. id -= TASK_RESPAWN
  396. if(!is_user_alive(id))
  397. {
  398. ExecuteHamB(Ham_CS_RoundRespawn, id)
  399. }
  400. }
  401.  
  402. public event_CurWeapon(id)
  403. {
  404. if(g_bInWar)
  405. {
  406. engclient_cmd(id, g_sWeaponID)
  407. }
  408. }
  409.  
  410. public client_disconnect(id)
  411. {
  412. g_iAllVote[id] = false
  413. g_iPoints[id] = 0
  414. }
  415.  
  416. public clcmd_drop(id)
  417. {
  418. if(g_bInWar)
  419. {
  420. print_colored(id, "!g[WW]!t %L", LANG_PLAYER, "WORD", g_sWeaponWar)
  421. return PLUGIN_HANDLED
  422. }
  423.  
  424. return PLUGIN_CONTINUE
  425. }
  426.  
  427. public clcmd_vote(id)
  428. {
  429. if(get_user_flags(id) & ADMIN_FLAG)
  430. {
  431. if(g_bVote)
  432. {
  433. print_colored(id, "!g[WW]!t %L", LANG_PLAYER, "VOTE")
  434. }
  435. else
  436. {
  437. if(g_bStartWar)
  438. {
  439. print_colored(id, "!g[WW]!t %L", LANG_PLAYER, "VOTE7", g_sWeaponWar)
  440. }
  441. else
  442. {
  443. if(g_bInWar)
  444. {
  445. print_colored(id, "!g[WW]!t %L", LANG_PLAYER, "VOTE6", g_sWeaponWar)
  446. }
  447. else
  448. {
  449. g_iAllVote[id] = true
  450.  
  451. menu_display(id, g_WarMenu, 0)
  452. }
  453. }
  454. }
  455. }
  456. }
  457.  
  458. public vote_handler(const id, const menuid, const item)
  459. {
  460. if(item == MENU_EXIT || !g_bVote)
  461. {
  462. return PLUGIN_HANDLED
  463. }
  464.  
  465. g_iVotes[item] ++
  466.  
  467. return PLUGIN_HANDLED
  468. }
  469.  
  470. public clcmd_war(id)
  471. {
  472. if(get_user_flags(id) & ADMIN_FLAG)
  473. {
  474. if(g_bVote)
  475. {
  476. print_colored(id, "!g[WW]!t %L", LANG_PLAYER, "VOTE")
  477. }
  478. else
  479. {
  480. if(g_bStartWar)
  481. {
  482. print_colored(id, "!g[WW]!t %L", LANG_PLAYER, "VOTE7", g_sWeaponWar)
  483. }
  484. else
  485. {
  486. if(g_bInWar)
  487. {
  488. print_colored(0, "!g[WW]!t %L", LANG_PLAYER, "WORD2", g_sWeaponWar)
  489. }
  490. else
  491. {
  492. menu_display(id, g_WarMenu, 0)
  493. }
  494. }
  495. }
  496. }
  497. }
  498.  
  499. public war_handler(const id, const menuid, const item)
  500. {
  501. if(is_user_alive(id))
  502. {
  503. copy(g_sWeaponWar, charsmax(g_sWeaponWar), WeaponsData[item][WeaponName])
  504. copy(g_sWeaponID, charsmax(g_sWeaponID), WeaponsData[item][WeaponID])
  505.  
  506. menu_cancel(id)
  507.  
  508. WarType(id)
  509. }
  510. }
  511.  
  512. public WarType(id)
  513. {
  514. if(g_iAllVote[id])
  515. {
  516. new szADMIN[32]
  517. get_user_name(id, szADMIN, charsmax(szADMIN))
  518.  
  519. set_task(get_pcvar_float(g_iVotingTime), "EndVote", TASK_VOTE)
  520.  
  521. print_colored(0, "!g[WW]!t %L", LANG_PLAYER, "VOTE2", szADMIN, g_sWeaponWar)
  522. print_colored(0, "!g[WW]!t %L", LANG_PLAYER, "VOTE3", get_pcvar_num(g_iVotingTime))
  523.  
  524. g_bVote = true
  525. g_iVoteTime --
  526.  
  527. StartVote()
  528. }
  529. else
  530. {
  531. StartWar()
  532. }
  533. }
  534.  
  535. public StartVote()
  536. {
  537. g_iVotes[0] = g_iVotes[1] = 0
  538.  
  539. new szVote[101]
  540. formatex(szVote, charsmax(szVote), "Vote for War Round! ^n\rNext is %s war!", g_sWeaponWar)
  541.  
  542. g_iVoteMenu = menu_create(szVote, "vote_handler")
  543.  
  544. menu_additem(g_iVoteMenu, "Yes!", "", 0)
  545. menu_additem(g_iVoteMenu, "No!", "", 0)
  546.  
  547. new iPlayers[32], iPlayerCount, id
  548.  
  549. get_players(iPlayers, iPlayerCount, "ac")
  550. for(new i; i < iPlayerCount; i++)
  551. {
  552. id = iPlayers[i];
  553. menu_display(id, g_iVoteMenu, 0)
  554. }
  555.  
  556. // Forward
  557. ExecuteForward(g_Forwards[FW_WAR_VOTE_START], g_ForwardResult)
  558. }
  559.  
  560. public EndVote()
  561. {
  562. if(g_iVotes[0] > g_iVotes[1])
  563. {
  564. print_colored(0, "!g[WW]!t %L", LANG_PLAYER, "VOTE4")
  565. print_colored(0, "!g[WW]!t %L", LANG_PLAYER, "VOTE7", g_sWeaponWar)
  566.  
  567. g_bStartWar = true
  568. }
  569. else
  570. {
  571. print_colored(0, "!g[WW]!t %L", LANG_PLAYER, "VOTE5")
  572. }
  573.  
  574. menu_destroy(g_iVoteMenu)
  575.  
  576. g_bVote = false
  577.  
  578. // Forward
  579. ExecuteForward(g_Forwards[FW_WAR_VOTE_END], g_ForwardResult)
  580. }
  581.  
  582. public StartWar()
  583. {
  584. new iPlayers[32], iPlayerCount, i, id
  585.  
  586. get_players(iPlayers, iPlayerCount, "a")
  587. for(i = 0; i < iPlayerCount; i++)
  588. {
  589. id = iPlayers[i]
  590.  
  591. if(equal(g_sWeaponID, "weapon_hegrenade",16))
  592. {
  593. cs_grenade_reward(id, 191, 0)
  594.  
  595. g_bHEWar = true
  596. }
  597. else
  598. {
  599. cs_weapon_reward(id, g_sWeaponID)
  600. }
  601.  
  602. if(g_iUnlimitClip)
  603. {
  604. cs_unlimited_reward(id, 2, 0, 0.0)
  605. }
  606. }
  607.  
  608. g_bInWar = true
  609.  
  610. if(get_pcvar_num(g_iShowHud))
  611. {
  612. set_task(1.0, "WarHud", TASK_HUD, _, _, "b")
  613. }
  614.  
  615. set_hudmessage(random_num(10,255), random(256), random(256), -1.0, 0.20, 0, 6.0, 12.0, 0.0, 0.0, -1)
  616. show_hudmessage(0, "%s round!", g_sWeaponWar)
  617.  
  618. // Execute war round started forward
  619. ExecuteForward(g_Forwards[FW_WAR_ROUND_START], g_ForwardResult, g_sWeaponWar)
  620. }
  621.  
  622. public WarHud()
  623. {
  624. set_hudmessage(255, 0, 0, HUD_MODE_X, HUD_MODE_Y, 0, 1.0, 1.0)
  625. ShowSyncHudMsg(0, g_iSyncHud, "Current round: ^n%s war!", g_sWeaponWar)
  626. }
  627.  
  628. public fw_TouchWeapon(ent, id)
  629. {
  630. if(is_valid_ent(ent) && is_user_alive(id) && g_bInWar)
  631. {
  632. return HAM_SUPERCEDE
  633. }
  634.  
  635. return HAM_IGNORED
  636. }
  637.  
  638. stock print_colored(const index, const input [ ], const any:...)
  639. {
  640. new message[191]
  641. vformat(message, 190, input, 3)
  642. replace_all(message, 190, "!y", "^1")
  643. replace_all(message, 190, "!t", "^3")
  644. replace_all(message, 190, "!g", "^4")
  645.  
  646. if(index)
  647. {
  648. message_begin(MSG_ONE_UNRELIABLE , g_iMsgSayTxt, _, index)
  649. write_byte(index)
  650. write_string(message)
  651. message_end()
  652. }
  653. else
  654. {
  655. new players[32], count, i, id
  656. get_players(players, count, "ch")
  657. for( i = 0; i < count; i ++ )
  658. {
  659. id = players[i]
  660. if(!is_user_alive(id)) continue;
  661.  
  662. message_begin(MSG_ONE_UNRELIABLE, g_iMsgSayTxt, _, id)
  663. write_byte(id)
  664. write_string(message)
  665. message_end()
  666. }
  667. }
  668. }