HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2. _______________________________________________________
  3. |
  4. .:> TheArmagedon's Plugin - Life System |
  5. _______________________________________________________|
  6. |
  7. .:> Cvar: |
  8. .:> amx_life [1/0] - On/Off Life System. |
  9. .:> amx_life_cost [Amount] - Life Price. |
  10. .:> amx_life_start [Amount] - How many lifes at start. |
  11. .:> V1.1 |
  12. .:> amx_life_max [Amount] - Max life to player |
  13. .:> V1.2 |
  14. .:> amx_life_auto_respawn [1/0] - On/off Auto. Respawn |
  15. _______________________________________________________|
  16. */
  17.  
  18. // Includes.
  19. #include <amxmodx>
  20. #include <hamsandwich>
  21. #include <cstrike>
  22.  
  23. // Color Chat
  24. #define MAXSLOTS 32
  25. enum Color
  26. {
  27. YELLOW = 1, // Yellow
  28. GREEN, // Green Color
  29. TEAM_COLOR, // Red, grey, blue
  30. GREY, // grey
  31. RED, // Red
  32. BLUE, // Blue
  33. }
  34.  
  35. new TeamInfo;
  36. new SayText;
  37. new MaxSlots;
  38.  
  39. new TeamName[][] =
  40. {
  41. "",
  42. "TERRORIST",
  43. "CT",
  44. "SPECTATOR"
  45. }
  46. new bool:IsConnected[MAXSLOTS + 1];
  47.  
  48. // Plugin Version
  49. #define VERSION "1.2"
  50.  
  51. // Principal Command.
  52. new g_Life[33];
  53. new bool:autoSpawn[33];
  54.  
  55. // Pcvar's
  56. new lifepreco;
  57. new lifeonoff;
  58. new lifestart;
  59. new lifemax;
  60. new lifespawn;
  61.  
  62. // Lets start the tutorial
  63. public plugin_init() {
  64.  
  65. // Register
  66. register_plugin("Life System", VERSION, "TheArmagedon");
  67. register_cvar("life_system", VERSION, FCVAR_SPONLY|FCVAR_SERVER)
  68. set_cvar_string("life_system", VERSION)
  69.  
  70. // Say command
  71. register_clcmd("say /respawn", "ComCMD"); // Uses the life.
  72. register_clcmd("say /ujra", "ComCMD"); // Uses the life.
  73. register_clcmd("say /uselife", "ComCMD"); // Uses the life.
  74. register_clcmd("say /buylife", "BuyCMD"); // Buy a life.
  75. register_clcmd("say /elet", "BuyCMD"); // Buy a life.
  76.  
  77. // Cvar's
  78. lifeonoff = register_cvar("amx_life", "1");
  79. lifepreco = register_cvar("amx_life_cost", "15000");
  80. lifestart = register_cvar("amx_life_start", "0"); // How many lifes at start?
  81. lifemax = register_cvar("amx_life_max", "8"); // Max life for a player
  82. lifespawn = register_cvar("amx_life_auto_respawn", "0"); // If 1 Respawn Automatically | If 0 use the /respawn command
  83.  
  84. // ColorChat
  85. TeamInfo = get_user_msgid("TeamInfo");
  86. SayText = get_user_msgid("SayText");
  87. MaxSlots = get_maxplayers();
  88.  
  89. // Death
  90. register_event( "DeathMsg", "EventDeath", "a");
  91.  
  92. // Player Spawn
  93. RegisterHam(Ham_Spawn, "player", "fw_PlayerSpawn_Post", 1);
  94. }
  95. // Start with how many lives?
  96. public client_putinserver(id)
  97. {
  98. g_Life[id] = get_pcvar_num(lifestart);
  99. }
  100. // Show Hud.
  101. public fw_PlayerSpawn_Post(id)
  102. {
  103. hudreset(id);
  104. }
  105. // DeathEvent.
  106. public EventDeath()
  107. {
  108. new iVictim = read_data( 2 );
  109.  
  110. FreeLife(iVictim); // Show the Command "FreeLife"
  111. AutoResp(iVictim); // Command Auto Respawn
  112. }
  113. // Command "say /buylife"
  114. public BuyCMD(id)
  115. {
  116. // If Cvar = 1.
  117. if(get_pcvar_num(lifeonoff) == 1) {
  118.  
  119. new money = cs_get_user_money(id);
  120. new custo = get_pcvar_num(lifepreco); // Life Price.
  121.  
  122. if(money > custo || money == custo) {
  123. if(g_Life[id] < get_pcvar_num(lifemax)) {
  124. cs_set_user_money(id, money - custo);
  125. g_Life[id]++
  126. ColorChat(id, TEAM_COLOR, "Eletet vettel");
  127. hudreset(id);
  128. if(!is_user_alive(id) && autoSpawn[id] == true) {
  129. set_task(2.0, "RespawnCommand", id);
  130. g_Life[id]--
  131. }
  132. } else
  133. ColorChat(id, TEAM_COLOR, "Nem vehetsz tobb eletet, max: %d", get_pcvar_num(lifemax))
  134. } else
  135. ColorChat(id, TEAM_COLOR, "Nincs eleg penzed.");
  136. } else
  137. ColorChat(id, TEAM_COLOR, "Parancs kikapcsolva.");
  138. }
  139. // Auto respawn command
  140. public AutoResp(id)
  141. {
  142. // If user is dead.
  143. if(!is_user_alive(id)) {
  144. // If cvar is 1
  145. if(get_pcvar_num(lifeonoff) == 1) {
  146. // If auto. spawn cvar 1
  147. if(get_pcvar_num(lifespawn) == 1) {
  148. autoSpawn[id] = true;
  149. if(autoSpawn[id] == true) {
  150. // If dont have any life, dont respawn
  151. if(!g_Life[id]) {
  152. hudreset(id);
  153. return PLUGIN_HANDLED
  154. }
  155. set_task(2.0, "RespawnCommand", id);
  156. g_Life[id]--
  157. hudreset(id);
  158. }
  159. } else
  160. autoSpawn[id] = false;
  161. }
  162. }
  163. return PLUGIN_CONTINUE;
  164. }
  165. // If you death you have chance to get a free life.
  166. public FreeLife(id)
  167. {
  168. // If Cvar = 1.
  169. if(get_pcvar_num(lifeonoff)) {
  170.  
  171. if( random_num( 1, 5 /*5 = chance 1 in 5 to get a free Life.*/) == 5 ) {
  172. if(g_Life[id] < get_pcvar_num(lifemax)) {
  173. g_Life[id]++
  174. ColorChat(id, TEAM_COLOR, "Eletet kaptal.");
  175. hudreset(id);
  176. if(!is_user_alive(id) && autoSpawn[id] == true) {
  177. set_task(2.0, "RespawnCommand", id);
  178. }
  179. }
  180. } else {
  181. client_print(id, print_console, "Nem kaphatsz eletet.");
  182. hudreset(id);
  183. }
  184. }
  185. }
  186. // Command "say /respawn"
  187. public ComCMD(id)
  188. {
  189. // If Cvar = 1.
  190. if(get_pcvar_num(lifeonoff) == 1) {
  191.  
  192. // If dont have any life, dont respawn
  193. if(!g_Life[id]) {
  194. hudreset(id);
  195. return PLUGIN_HANDLED
  196. }
  197. // If player dead and have life, Respawn.
  198. if(!is_user_alive(id)) {
  199. if(autoSpawn[id] == false) {
  200. g_Life[id]--
  201. RespawnCommand(id); // Respawn Command.
  202. hudreset(id);
  203. } else
  204. ColorChat(id, TEAM_COLOR, "Parancs kikapcsolva. Automata ujraelesztes bekapcsolva.");
  205. } else
  206. ColorChat(id, TEAM_COLOR, "Nem hasznalhatod ezt a parancsot ha elsz.");
  207. } else
  208. ColorChat(id, TEAM_COLOR, "Parancs kikapcsolva.")
  209.  
  210. return PLUGIN_CONTINUE;
  211. }
  212. // Show Hud, How many lives you got.
  213. public hudshow(id)
  214. {
  215. if(get_pcvar_num(lifeonoff) == 1) {
  216. set_hudmessage(255, 0, 0, 0.01, 0.2, 0, 6.0, 30.0)
  217. show_hudmessage(id, "--[ Elet Rendszer ]--^nNeked van %d/%d %s^n^nElet vasarlas: /elet^nElet ara: %d$", g_Life[id], get_pcvar_num(lifemax),g_Life[id] == 1 ? "Eleted" : "Eleted", get_pcvar_num(lifepreco))
  218. }
  219. }
  220. // Reset HUD MSG.
  221. public hudreset(id)
  222. {
  223. hudshow(id)
  224. }
  225. public RespawnCommand(id)
  226. {
  227. if(!is_user_alive(id)) {
  228. ExecuteHamB(Ham_CS_RoundRespawn, id);
  229. ColorChat(id, TEAM_COLOR, "Ujra lettel elesztve!");
  230. }
  231. }
  232. // Color Chat
  233. public ColorChat(id, Color:type, const msg[], {Float,Sql,Result,_}:...)
  234. {
  235. static message[256];
  236.  
  237. switch(type)
  238. {
  239. case YELLOW: // Yellow
  240. {
  241. message[0] = 0x01;
  242. }
  243. case GREEN: // Green
  244. {
  245. message[0] = 0x04;
  246. }
  247. default: // White, Red, Blue
  248. {
  249. message[0] = 0x03;
  250. }
  251. }
  252.  
  253. vformat(message[1], 251, msg, 4);
  254.  
  255. // Make sure message is not longer than 192 character. Will crash the server.
  256. message[192] = '^0';
  257.  
  258. new team, ColorChange, index, MSG_Type;
  259.  
  260. if(!id)
  261. {
  262. index = FindPlayer();
  263. MSG_Type = MSG_ALL;
  264.  
  265. } else {
  266. MSG_Type = MSG_ONE;
  267. index = id;
  268. }
  269.  
  270. team = get_user_team(index);
  271. ColorChange = ColorSelection(index, MSG_Type, type);
  272.  
  273. ShowColorMessage(index, MSG_Type, message);
  274.  
  275. if(ColorChange)
  276. {
  277. Team_Info(index, MSG_Type, TeamName[team]);
  278. }
  279. }
  280.  
  281. ShowColorMessage(id, type, message[])
  282. {
  283. message_begin(type, SayText, _, id);
  284. write_byte(id)
  285. write_string(message);
  286. message_end();
  287. }
  288.  
  289. Team_Info(id, type, team[])
  290. {
  291. message_begin(type, TeamInfo, _, id);
  292. write_byte(id);
  293. write_string(team);
  294. message_end();
  295.  
  296. return 1;
  297. }
  298.  
  299. ColorSelection(index, type, Color:Type)
  300. {
  301. switch(Type)
  302. {
  303. case RED:
  304. {
  305. return Team_Info(index, type, TeamName[1]);
  306. }
  307. case BLUE:
  308. {
  309. return Team_Info(index, type, TeamName[2]);
  310. }
  311. case GREY:
  312. {
  313. return Team_Info(index, type, TeamName[0]);
  314. }
  315. }
  316.  
  317. return 0;
  318. }
  319.  
  320. FindPlayer()
  321. {
  322. new i = -1;
  323.  
  324. while(i <= MaxSlots)
  325. {
  326. if(IsConnected[++i])
  327. {
  328. return i;
  329. }
  330. }
  331.  
  332. return -1;
  333. }
  334. /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
  335. *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1034\\ f0\\ fs16 \n\\ par }
  336. */
  337.