seroff

OciXCrom

Apr 17th, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <fakemeta>
  4.  
  5. #define PLUGIN_VERSION "1.1"
  6. #define CMD_MULTI -69
  7.  
  8. new Trie:g_tArgs
  9.  
  10. public plugin_init()
  11. {
  12. register_plugin("Command Targeting Plus", PLUGIN_VERSION, "OciXCrom")
  13. register_cvar("CRXCMDTarget", PLUGIN_VERSION, FCVAR_SERVER|FCVAR_SPONLY|FCVAR_UNLOGGED)
  14. g_tArgs = TrieCreate()
  15. ReadFile()
  16. }
  17.  
  18. public plugin_end()
  19. TrieDestroy(g_tArgs)
  20.  
  21. ReadFile()
  22. {
  23. new szConfigsName[256], szFilename[256]
  24. get_configsdir(szConfigsName, charsmax(szConfigsName))
  25. formatex(szFilename, charsmax(szFilename), "%s/CMDTargetPlus.ini", szConfigsName)
  26. new iFilePointer = fopen(szFilename, "rt")
  27.  
  28. if(iFilePointer)
  29. {
  30. new szData[64], szCommand[60], szArg[3]
  31.  
  32. while(!feof(iFilePointer))
  33. {
  34. fgets(iFilePointer, szData, charsmax(szData)); trim(szData)
  35.  
  36. switch(szData[0])
  37. {
  38. case EOS, ';', '/': continue
  39. default:
  40. {
  41. parse(szData, szCommand, charsmax(szCommand), szArg, charsmax(szArg))
  42. TrieSetCell(g_tArgs, szCommand, szArg[0] == EOS ? 1 : str_to_num(szArg))
  43. register_concmd(szCommand, "OnCommand")
  44. szArg[0] = EOS
  45. }
  46. }
  47. }
  48.  
  49. fclose(iFilePointer)
  50. }
  51. }
  52.  
  53. public OnCommand(id)
  54. {
  55. new szCmd[32], szArg[32], iArgNum
  56. read_argv(0, szCmd, charsmax(szCmd))
  57. TrieGetCell(g_tArgs, szCmd, iArgNum)
  58. read_argv(iArgNum, szArg, charsmax(szArg))
  59.  
  60. if(szArg[0] == '@')
  61. {
  62. new szFullCmd[128]
  63. read_args(szFullCmd, charsmax(szFullCmd))
  64. format(szFullCmd, charsmax(szFullCmd), "%s %s", szCmd, szFullCmd)
  65.  
  66. if(is_this_command(id, szArg, "aim", false, false))
  67. {
  68. new iPlayer, iBody
  69. get_user_aiming(id, iPlayer, iBody)
  70.  
  71. if(iPlayer) { do_cmd_by_index(id, iPlayer, szFullCmd, szArg); }
  72. }
  73. else if(is_this_command(id, szArg, "spectating", false, false))
  74. {
  75. new iPlayer = pev(id, pev_iuser2)
  76. if(iPlayer) { do_cmd_by_index(id, iPlayer, szFullCmd, szArg); }
  77. }
  78. else if(is_this_command(id, szArg, "alive", true, true)) { do_cmd_by_index(id, CMD_MULTI, szFullCmd, szArg, "a"); }
  79. else if(is_this_command(id, szArg, "alivect", true, true)) { do_cmd_by_index(id, CMD_MULTI, szFullCmd, szArg, "ae", "CT"); }
  80. else if(is_this_command(id, szArg, "alivet", true, true)) { do_cmd_by_index(id, CMD_MULTI, szFullCmd, szArg, "ae", "TERRORIST"); }
  81. else if(is_this_command(id, szArg, "all", true, true)) { do_cmd_by_index(id, CMD_MULTI, szFullCmd, szArg); }
  82. else if(is_this_command(id, szArg, "bots", false, true)) { do_cmd_by_index(id, CMD_MULTI, szFullCmd, szArg, "d"); }
  83. else if(is_this_command(id, szArg, "ct", true, true)) { do_cmd_by_index(id, CMD_MULTI, szFullCmd, szArg, "e", "CT"); }
  84. else if(is_this_command(id, szArg, "dead", true, true)) { do_cmd_by_index(id, CMD_MULTI, szFullCmd, szArg, "b"); }
  85. else if(is_this_command(id, szArg, "deadct", true, true)) { do_cmd_by_index(id, CMD_MULTI, szFullCmd, szArg, "be", "CT"); }
  86. else if(is_this_command(id, szArg, "deadt", true, true)) { do_cmd_by_index(id, CMD_MULTI, szFullCmd, szArg, "be", "T"); }
  87. else if(is_this_command(id, szArg, "humans", true, true)) { do_cmd_by_index(id, CMD_MULTI, szFullCmd, szArg, "ch"); }
  88. else if(is_this_command(id, szArg, "me", false, false)) { do_cmd_by_index(id, id, szFullCmd, szArg); }
  89. else if(is_this_command(id, szArg, "spec", true, true)) { do_cmd_by_index(id, CMD_MULTI, szFullCmd, szArg, "e", "SPECTATOR"); }
  90. else if(is_this_command(id, szArg, "t", true, true)) { do_cmd_by_index(id, CMD_MULTI, szFullCmd, szArg, "e", "TERRORIST"); }
  91.  
  92. return PLUGIN_HANDLED
  93. }
  94.  
  95. return PLUGIN_CONTINUE
  96. }
  97.  
  98. do_cmd_by_index(id, iPlayer, szCmd[], szArg[], szFlags[] = "", szTeam[] = "")
  99. {
  100. if(iPlayer == CMD_MULTI)
  101. {
  102. new iPlayers[32], iPnum, bool:bNoSelf = szArg[1] == '!'
  103. get_players(iPlayers, iPnum, szFlags, szTeam)
  104.  
  105. for(new i, iPlayer; i < iPnum; i++)
  106. {
  107. iPlayer = iPlayers[i]
  108.  
  109. if(id == iPlayer && bNoSelf)
  110. continue
  111.  
  112. create_and_execute(id, iPlayer, szCmd, szArg)
  113. }
  114. }
  115. else create_and_execute(id, iPlayer, szCmd, szArg)
  116. }
  117.  
  118. create_and_execute(id, iPlayer, szCmd[], szArg[])
  119. {
  120. new szFullCmd[128], szId[16]
  121. copy(szFullCmd, charsmax(szFullCmd), szCmd)
  122. formatex(szId, charsmax(szId), "#%i", get_user_userid(iPlayer))
  123. replace(szFullCmd, charsmax(szFullCmd), szArg, szId)
  124. client_cmd(id, szFullCmd)
  125. }
  126.  
  127. bool:is_this_command(id, szArg[], szCommand[], bool:bNoSelf, bool:bAllowServer)
  128. {
  129. if(!bAllowServer && !is_user_connected(id))
  130. return false
  131.  
  132. return (equali(szArg[1], szCommand) || (bNoSelf && szArg[1] == '!' && equali(szArg[2], szCommand)))
  133. }
Add Comment
Please, Sign In to add comment