HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2. * Description *
  3.  
  4. Allows players to buy respawn to return to play again, it is possible to set the price.
  5.  
  6. Converted my plugin for Sourcemod:
  7.  
  8. https://forums.alliedmods.net/showthread.php?p=1960942
  9.  
  10. * CVARs *
  11. amxx_buyrespawn_enabled = 1/0 - plugin is enabled/disabled (def. 1)
  12. amxx_buyrespawn_cost = 0-16000 - Set the price for the respawn (def. 500)
  13. amxx_buyrespawn_per_round = 0-99 - Set the max respawns per round (def. 2)
  14. amxx_buyrespawn_message = 1/0 plugin message is enabled/disabled (def. 1)
  15. amxx_buyrespawn_version - current plugin version
  16.  
  17. * Commands *
  18. !respawn
  19. /respawn
  20.  
  21. * Changelog *
  22.  
  23. Version 1.0.0
  24. Initial Release
  25.  
  26. Version 1.0.1
  27. Updated with wickedd tips
  28. Little clean code
  29.  
  30. Version 1.0.2
  31. Now the plugin checks if the player is Spectator, to prevent bugs.
  32. */
  33.  
  34. /*
  35. Libraries
  36. */
  37. #include <amxmodx>
  38. #include <hamsandwich>
  39. #include <cstrike>
  40.  
  41. /*
  42. Plugin info
  43. */
  44. #define PLUGIN "Buy Respawn"
  45. #define VERSION "1.0.2"
  46. #define AUTHOR "Rodrigo286"
  47.  
  48. /*
  49. Variables
  50. */
  51. new gCost;
  52. new gUses;
  53. new gEnabled;
  54. new gMessages;
  55. new respawns[33];
  56.  
  57. public plugin_init()
  58. {
  59. register_plugin(PLUGIN, VERSION, AUTHOR)
  60.  
  61. /*
  62. Cvars
  63. */
  64. register_cvar("amxx_buy_respawn_version", VERSION, FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_UNLOGGED|FCVAR_SPONLY)
  65. gEnabled = register_cvar("amxx_buy_respawn_enabled", "1") // Plugin is enbaled?
  66. gCost = register_cvar("amxx_buy_respawn_cost", "500") // How much respawn cost?
  67. gUses = register_cvar("amxx_buy_respawn_per_round", "2") // How many respawns allowed per round?
  68. gMessages = register_cvar("amxx_buy_respawn_messages", "1") // Info messages enabled?
  69. /*
  70. Commands
  71. */
  72. register_clcmd("say !respawn", "respawnCMD"); // Command to buy respawn
  73. register_clcmd("say /respawn", "respawnCMD"); // Command to buy respawn
  74.  
  75. /*
  76. Events
  77. */
  78. register_event("HLTV", "LogEvent_RoundStart", "a", "1=0", "2=0");
  79. }
  80.  
  81. public LogEvent_RoundStart()
  82. {
  83. arrayset(respawns, 0, sizeof(respawns));
  84. }
  85.  
  86. public respawnCMD(client)
  87. {
  88. /*
  89. Get player money
  90. */
  91. new money = cs_get_user_money(client);
  92. /*
  93. Get respawn cost
  94. */
  95. new cost = get_pcvar_num(gCost);
  96. /*
  97. Get respawn max uses allowed
  98. */
  99. new uses = get_pcvar_num(gUses);
  100. /*
  101. Calculate payment value of respawn
  102. */
  103. new payment = money - cost;
  104. /*
  105. Get message enabled cvar value
  106. */
  107. new messages = get_pcvar_num(gMessages);
  108. /*
  109. Get if player is spector or unassigned
  110. */
  111. if(get_user_team(client) == 3 || get_user_team(client) == 0)
  112. {
  113. if(messages != 0)
  114. client_print(client, print_chat, "[Respawn] Válaszd ki a csapatot újraéledés elõtt.");
  115.  
  116. return PLUGIN_HANDLED;
  117. }
  118.  
  119. if(get_pcvar_num(gEnabled) != 1)
  120. {
  121. if(messages != 0)
  122. client_print(client, print_chat, "[Respawn] Respawn vásárlás le van tiltva ebben az idõben.");
  123.  
  124. return PLUGIN_HANDLED;
  125. }
  126.  
  127. if(is_user_alive(client))
  128. {
  129. if(messages != 0)
  130. client_print(client, print_chat, "[Respawn] Halottnak kell lenned, hogy respawnt vegyél.");
  131.  
  132. return PLUGIN_HANDLED;
  133. }
  134.  
  135. if(uses == respawns[client])
  136. {
  137. if(messages != 0)
  138. client_print(client, print_chat, "[Respawn] Elõfordulhat, hogy elérted a maximális vásárlási szintet.");
  139.  
  140. return PLUGIN_HANDLED;
  141. }
  142.  
  143. if(money < cost)
  144. {
  145. if(messages != 0)
  146. client_print(client, print_chat, "[Respawn] Nincs elég pénzed! ($%d)", cost);
  147.  
  148. return PLUGIN_HANDLED;
  149. }
  150. /*
  151. Set user money to pay for respawn
  152. */
  153. cs_set_user_money(client, payment);
  154. /*
  155. Spawn player using hamsandwich
  156. */
  157. ExecuteHamB(Ham_CS_RoundRespawn, client);
  158. /*
  159. Add +1 to respawn uses
  160. */
  161. respawns[client] += 1;
  162. /*
  163. Print message to player
  164. */
  165. if(messages != 0)
  166. client_print(client, print_chat, "[Respawn] Te vettél új életet $%d dollárért!", cost);
  167.  
  168. return PLUGIN_CONTINUE;
  169. }
  170.  
  171. public client_connect(client)
  172. {
  173. /*
  174. Reset respawn uses on player connect
  175. */
  176. respawns[client] = 0;
  177. }