HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <nvault>
  4.  
  5. #if AMXX_VERSION_NUM < 183
  6. #include <dhudmessage>
  7. #endif
  8.  
  9. #define PLUGIN_VERSION "1.2"
  10. #define FLAG_ADMIN ADMIN_BAN
  11.  
  12. new g_iVault, g_cvType, g_cvRed, g_cvGreen, g_cvBlue, g_cvXPos, g_cvYPos, g_cvTime
  13. new g_iType, g_iRed, g_iGreen, g_iBlue
  14. new g_msgSayText, g_msgTeamInfo, g_iMaxPlayers
  15. new Float:g_flXPos, Float:g_flYPos, Float:g_flTime
  16. new g_szNote[33][128]
  17. new const g_szPrefix[] = "^1[^3HalálÜzenet^1]"
  18. new const g_szError[] = "^3[HIBA]^1"
  19.  
  20. enum Color
  21. {
  22. NORMAL = 1,
  23. GREEN,
  24. TEAM_COLOR,
  25. GREY,
  26. RED,
  27. BLUE,
  28. }
  29.  
  30. new TeamName[][] =
  31. {
  32. "",
  33. "TERRORIST",
  34. "CT",
  35. "SPECTATOR"
  36. }
  37.  
  38. public plugin_init()
  39. {
  40. register_plugin("Death Note", PLUGIN_VERSION, "OciXCrom")
  41. register_cvar("DeathNote", PLUGIN_VERSION, FCVAR_SERVER|FCVAR_SPONLY|FCVAR_UNLOGGED)
  42. register_dictionary("DeathNote.txt")
  43. register_event("DeathMsg", "eventPlayerKilled", "a")
  44. register_clcmd("say", "cmdSay")
  45. register_clcmd("say_team", "cmdSay")
  46. g_msgSayText = get_user_msgid("SayText")
  47. g_msgTeamInfo = get_user_msgid("TeamInfo")
  48. g_iMaxPlayers = get_maxplayers()
  49. g_cvType = register_cvar("dn_type", "3")
  50. g_cvRed = register_cvar("dn_hud_red", "0")
  51. g_cvGreen = register_cvar("dn_hud_green", "255")
  52. g_cvBlue = register_cvar("dn_hud_blue", "0")
  53. g_cvXPos = register_cvar("dn_hud_xpos", "-1.0")
  54. g_cvYPos = register_cvar("dn_hud_ypos", "0.80")
  55. g_cvTime = register_cvar("dn_hud_time", "5.0")
  56. g_iVault = nvault_open("DeathNote")
  57. readCvars()
  58. }
  59.  
  60. readCvars()
  61. {
  62. g_iType = get_pcvar_num(g_cvType)
  63. g_iRed = get_pcvar_num(g_cvRed)
  64. g_iGreen = get_pcvar_num(g_cvGreen)
  65. g_iBlue = get_pcvar_num(g_cvBlue)
  66. g_flXPos = get_pcvar_float(g_cvXPos)
  67. g_flYPos = get_pcvar_float(g_cvYPos)
  68. g_flTime = get_pcvar_float(g_cvTime)
  69. }
  70.  
  71. public client_putinserver(id)
  72. {
  73. if(!is_user_bot(id))
  74. LoadData(id)
  75. }
  76.  
  77. public client_disconnect(id)
  78. {
  79. if(!is_user_bot(id))
  80. SaveData(id)
  81. }
  82.  
  83. SaveData(id)
  84. {
  85. new szName[32]
  86. get_user_name(id, szName, charsmax(szName))
  87. nvault_set(g_iVault, szName, g_szNote[id])
  88. }
  89.  
  90. LoadData(id)
  91. {
  92. new szName[32]
  93. get_user_name(id, szName, charsmax(szName))
  94. nvault_get(g_iVault, szName, g_szNote[id], charsmax(g_szNote[]))
  95. }
  96.  
  97. public plugin_end()
  98. nvault_close(g_iVault)
  99.  
  100. public cmdSay(id)
  101. {
  102. new szSay[128], szCmd[6], szArg[6], szNote[96]
  103. read_args(szSay, charsmax(szSay))
  104. remove_quotes(szSay)
  105.  
  106. if(szSay[0] != '/')
  107. return PLUGIN_CONTINUE
  108.  
  109. parse(szSay, szCmd, charsmax(szCmd), szArg, charsmax(szArg), szNote, charsmax(szNote))
  110.  
  111. if(!equal(szCmd, "/note") && !equal(szCmd, "/dn"))
  112. return PLUGIN_CONTINUE
  113.  
  114. switch(szArg[0])
  115. {
  116. case 'h': // help
  117. {
  118. ColorChat(id, BLUE, "%s %L", g_szPrefix, LANG_SERVER, "HELP_LINE_1")
  119. ColorChat(id, BLUE, "%s %L", g_szPrefix, LANG_SERVER, "HELP_LINE_2")
  120. ColorChat(id, BLUE, "%s %L", g_szPrefix, LANG_SERVER, "HELP_LINE_3")
  121. }
  122. case 's': // set
  123. {
  124. if(is_blank(szNote))
  125. {
  126. ColorChat(id, RED, "%s %L", g_szError, LANG_SERVER, "NOTE_SET_ERR")
  127. return PLUGIN_HANDLED
  128. }
  129.  
  130. replace(szSay, charsmax(szSay), szCmd, "")
  131. replace(szSay, charsmax(szSay), szArg, "")
  132. trim(szSay)
  133. copy(g_szNote[id], charsmax(g_szNote[]), szSay)
  134. ColorChat(id, BLUE, "%s %L", g_szPrefix, LANG_SERVER, "NOTE_SET", szSay)
  135. }
  136. case 'r': // remove
  137. {
  138. if(is_blank(g_szNote[id])) ColorChat(id, RED, "%s %L", g_szError, LANG_SERVER, "NOTE_REMOVE_ERR")
  139. else
  140. {
  141. clearNote(id)
  142. ColorChat(id, BLUE, "%s %L", g_szPrefix, LANG_SERVER, "NOTE_REMOVE")
  143. }
  144. }
  145. case 'c': // current
  146. {
  147. if(is_blank(g_szNote[id])) ColorChat(id, BLUE, "%s %L", g_szError, LANG_SERVER, "NOTE_CURRENT_ERR")
  148. else ColorChat(id, BLUE, "%s %L", g_szPrefix, LANG_SERVER, "NOTE_CURRENT", g_szNote[id])
  149. }
  150. case 'l': // load
  151. {
  152. if(!is_admin(id)) ColorChat(id, RED, "%s %L", g_szError, LANG_SERVER, "NOTE_NOACCESS")
  153. else
  154. {
  155. ColorChat(id, BLUE, "%s %L", g_szPrefix, LANG_SERVER, "NOTE_LOAD")
  156. readCvars()
  157. }
  158. }
  159. case 'd', 'p': // delete, player
  160. {
  161. if(!is_admin(id)) ColorChat(id, RED, "%s %L", g_szError, LANG_SERVER, "NOTE_NOACCESS")
  162. else
  163. {
  164. new bool:blDelete = (szArg[0] == 'd') ? true : false
  165. if(is_blank(szNote)) ColorChat(id, RED, "%s %L", g_szError, LANG_SERVER, "NOTE_USAGE_ADMIN", szArg)
  166. else
  167. {
  168. new iPlayer = cmd_target(id, szNote, blDelete ? 4 : 0)
  169. if(!iPlayer) ColorChat(id, RED, "%s %L", g_szError, LANG_SERVER, "NOTE_NOTFOUND")
  170. else
  171. {
  172. new szName[32], szName2[32]
  173. get_user_name(id, szName, charsmax(szName))
  174. get_user_name(iPlayer, szName2, charsmax(szName2))
  175. if(is_blank(g_szNote[iPlayer])) ColorChat(id, RED, "%s %L", g_szError, LANG_SERVER, "NOTE_NOTHAVE", szName2)
  176. else
  177. {
  178. if(blDelete)
  179. {
  180. ColorChat(id, BLUE, "%s %L", g_szPrefix, LANG_SERVER, "NOTE_DELETE_SUCCESS", szName2)
  181. if(id != iPlayer) ColorChat(id, BLUE, "%s %L", g_szPrefix, LANG_SERVER, "NOTE_DELETE_NOTIFY", szName)
  182. clearNote(iPlayer)
  183. }
  184. else ColorChat(id, BLUE, "%s %L", g_szPrefix, LANG_SERVER, "NOTE_PLAYER", szName2, g_szNote[iPlayer])
  185. }
  186. }
  187. }
  188. }
  189. }
  190. default: ColorChat(id, BLUE, "%s %L", g_szError, LANG_SERVER, "NOTE_USAGE")
  191. }
  192.  
  193. return PLUGIN_HANDLED
  194. }
  195.  
  196. public eventPlayerKilled()
  197. {
  198. new iAttacker = read_data(1), iVictim = read_data(2)
  199.  
  200. if(!is_user_connected(iAttacker) || !is_user_connected(iVictim) || iAttacker == iVictim || is_blank(g_szNote[iAttacker]))
  201. return
  202.  
  203. new szNote[192], szName[32]
  204. get_user_name(iAttacker, szName, charsmax(szName))
  205. copy(szNote, charsmax(szNote), g_szNote[iAttacker])
  206. replace(szNote, charsmax(szNote), "<name>", szName)
  207.  
  208. switch(g_iType)
  209. {
  210. case 1: ColorChat(iVictim, TEAM_COLOR, "%s", szNote)
  211. case 2:
  212. {
  213. set_hudmessage(g_iRed, g_iGreen, g_iBlue, g_flXPos, g_flYPos, 0, 1.0, g_flTime, 0.1, 0.1, -1)
  214. show_hudmessage(iVictim, szNote)
  215. }
  216. case 3:
  217. {
  218. set_dhudmessage(g_iRed, g_iGreen, g_iBlue, g_flXPos, g_flYPos, 0, 1.0, g_flTime, 0.1, 0.1)
  219. show_dhudmessage(iVictim, szNote)
  220. }
  221. }
  222. }
  223.  
  224. public clearNote(id)
  225. g_szNote[id][0] = EOS
  226.  
  227. bool:is_admin(id)
  228. return (get_user_flags(id) & FLAG_ADMIN) ? true : false
  229.  
  230. bool:is_blank(szMessage[])
  231. return (szMessage[0] == EOS) ? true : false
  232.  
  233. /* ColorChat */
  234.  
  235. ColorChat(id, Color:type, const msg[], {Float,Sql,Result,_}:...)
  236. {
  237. static message[256];
  238.  
  239. switch(type)
  240. {
  241. case NORMAL: // clients scr_concolor cvar color
  242. {
  243. message[0] = 0x01;
  244. }
  245. case GREEN: // Green
  246. {
  247. message[0] = 0x04;
  248. }
  249. default: // White, Red, Blue
  250. {
  251. message[0] = 0x03;
  252. }
  253. }
  254.  
  255. vformat(message[1], charsmax(message) - 4, msg, 4);
  256.  
  257. replace_all(message, charsmax(message), "!n", "^x01");
  258. replace_all(message, charsmax(message), "!t", "^x03");
  259. replace_all(message, charsmax(message), "!g", "^x04");
  260.  
  261. // Make sure message is not longer than 192 character. Will crash the server.
  262. message[192] = '^0';
  263.  
  264. static team, ColorChange, index, MSG_Type;
  265.  
  266. if(id)
  267. {
  268. MSG_Type = MSG_ONE;
  269. index = id;
  270. } else {
  271. index = FindPlayer();
  272. MSG_Type = MSG_ALL;
  273. }
  274.  
  275. team = get_user_team(index);
  276. ColorChange = ColorSelection(index, MSG_Type, type);
  277.  
  278. ShowColorMessage(index, MSG_Type, message);
  279.  
  280. if(ColorChange)
  281. {
  282. Team_Info(index, MSG_Type, TeamName[team]);
  283. }
  284. }
  285.  
  286. ShowColorMessage(id, type, message[])
  287. {
  288. message_begin(type, g_msgSayText, _, id);
  289. write_byte(id)
  290. write_string(message);
  291. message_end();
  292. }
  293.  
  294. Team_Info(id, type, team[])
  295. {
  296. message_begin(type, g_msgTeamInfo, _, id);
  297. write_byte(id);
  298. write_string(team);
  299. message_end();
  300.  
  301. return 1;
  302. }
  303.  
  304. ColorSelection(index, type, Color:Type)
  305. {
  306. switch(Type)
  307. {
  308. case RED:
  309. {
  310. return Team_Info(index, type, TeamName[1]);
  311. }
  312. case BLUE:
  313. {
  314. return Team_Info(index, type, TeamName[2]);
  315. }
  316. case GREY:
  317. {
  318. return Team_Info(index, type, TeamName[0]);
  319. }
  320. }
  321.  
  322. return 0;
  323. }
  324.  
  325. FindPlayer()
  326. {
  327. static i;
  328. i = -1;
  329.  
  330. while(i <= g_iMaxPlayers)
  331. {
  332. if(is_user_connected(++i))
  333. {
  334. return i;
  335. }
  336. }
  337.  
  338. return -1;
  339. }