HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2.  
  3. Sunglasses SourceMOD Plugin
  4. (c) 2008 SAMURAI
  5.  
  6. */
  7.  
  8. #include <sourcemod>
  9. #include <sdktools>
  10.  
  11. #pragma semicolon 1
  12.  
  13. public Plugin:myinfo =
  14. {
  15. name = "Napszemüveg",
  16. author = "SAMURAI",
  17. description = "Vegyél napszemüveget,és nem fogsz vakulni.",
  18. version = "0.1",
  19. url = "www.cs-utilz.net"
  20. }
  21.  
  22. #define ALPHA_SET 0.5
  23. #define NULL_CHAR 0
  24. #define QUOTE_CHAR 34
  25.  
  26. // offsets
  27. new g_iMoney = -1;
  28. new g_iFlashAlpha = -1;
  29. new g_inBuyzone = -1;
  30.  
  31. new bool:had_sunglasses[MAXPLAYERS + 1] = false;
  32. new g_used_count[MAXPLAYERS + 1] = 0;
  33.  
  34. // messages
  35. stock const String:PLAYER_BE_ALIVE[] = "Élned kell,hogy napszemüveget tudj venni.";
  36. stock const String:NOT_ENOUGH_MONEY[] = "Nincs elég pénzed,hogy napszemüveget vegyél";
  37. stock const String:AD_MESSAGE[] = "Írd: 'napszemuveg' chatbe,hogy napszemüveget tudj vásárolni";
  38. stock const String:SUCC_MSG[] = "Kaptál egy napszemüveget! Mostantól nem fogsz vakulni";
  39. stock const String:NO_MORE_ACTIVE[] = "Napszemüveg nem használható már";
  40. stock const String:ONLY_BUYZONE[] = "Vásárlási zónában kell lenned,hogy meg tudd vásárolni.";
  41.  
  42. // cvars
  43. new Handle:cvar_price = INVALID_HANDLE;
  44. new Handle:cvar_message = INVALID_HANDLE;
  45. new Handle:cvar_mode = INVALID_HANDLE;
  46. new Handle:cvar_max = INVALID_HANDLE;
  47.  
  48.  
  49. public OnPluginStart()
  50. {
  51. RegConsoleCmd("say",CMD_BUY_SUNGLASSES,"buy sunshit");
  52. RegConsoleCmd("say_team",CMD_BUY_SUNGLASSES,"buy sunshit");
  53.  
  54. // find offsets
  55. g_iMoney = FindSendPropOffs("CCSPlayer", "m_iAccount");
  56. g_iFlashAlpha = FindSendPropOffs("CCSPlayer", "m_flFlashMaxAlpha");
  57. g_inBuyzone = FindSendPropOffs("CCSPlayer","m_bInBuyZone");
  58.  
  59. // register cvars
  60. cvar_price = CreateConVar("sunglasses_price","1100","Napszemüveg ár. Alap:1100");
  61. cvar_message = CreateConVar("sunglasses_msg_mode","1","Kiírások");
  62. cvar_mode = CreateConVar("sunglasses_mode","1","Set sunglasses mode");
  63. cvar_max = CreateConVar("sunglasses_max","4","Hányszor védjen egy körben. Alap: 4");
  64.  
  65. // hook events
  66. HookEvent("player_blind",Event_Flashed);
  67. HookEvent("player_spawn",Event_spawn);
  68. }
  69.  
  70.  
  71. public Action:CMD_BUY_SUNGLASSES(id,args)
  72. {
  73. decl String:SayText[191];
  74. GetCmdArgString(SayText, sizeof(SayText));
  75.  
  76. remove_quotes(SayText);
  77.  
  78. if(StrEqual(SayText,"napszemuveg",false))
  79. {
  80. if(!IsPlayerAlive(id) )
  81. {
  82. PrintToChat(id,PLAYER_BE_ALIVE);
  83. return Plugin_Handled;
  84. }
  85.  
  86. if(g_inBuyzone != 1)
  87. {
  88. if(GetEntData(id,g_inBuyzone) != 1)
  89. {
  90. PrintToChat(id,ONLY_BUYZONE);
  91. return Plugin_Handled;
  92. }
  93. }
  94.  
  95.  
  96. if(get_user_money(id) < GetConVarInt(cvar_price))
  97. {
  98. PrintToChat(id,NOT_ENOUGH_MONEY);
  99. return Plugin_Handled;
  100. }
  101.  
  102. new sPrice = GetConVarInt(cvar_price);
  103. set_user_money(id,get_user_money(id) - sPrice);
  104. PrintToChat(id,SUCC_MSG);
  105.  
  106. had_sunglasses[id] = true;
  107. g_used_count[id]++;
  108. }
  109.  
  110. return Plugin_Continue;
  111.  
  112. }
  113.  
  114.  
  115. public Action:Event_Flashed(Handle:event, const String:name[], bool:dontBroadcast)
  116. {
  117. new client = GetClientOfUserId(GetEventInt(event,"userid"));
  118.  
  119. if (g_iFlashAlpha != -1)
  120. {
  121. if(had_sunglasses[client])
  122. {
  123. if(GetConVarInt(cvar_mode) == 2 && g_used_count[client] >= GetConVarInt(cvar_max) )
  124. {
  125. PrintToChat(client,NO_MORE_ACTIVE);
  126. return;
  127.  
  128. }
  129.  
  130. SetEntDataFloat(client,g_iFlashAlpha,ALPHA_SET);
  131.  
  132. g_used_count[client]++;
  133. }
  134. }
  135. }
  136.  
  137.  
  138. public Action:Event_spawn(Handle:event, const String:name[], bool:dontBroadcast)
  139. {
  140. new client = GetClientOfUserId(GetEventInt(event,"userid"));
  141.  
  142. if(GetConVarInt(cvar_message) == 2)
  143. PrintToChatAll(AD_MESSAGE);
  144.  
  145. had_sunglasses[client] = false;
  146. g_used_count[client] = 0;
  147. }
  148.  
  149.  
  150. public OnClientPutInServer()
  151. {
  152. if(GetConVarInt(cvar_message) > 0)
  153. CreateTimer(15.0,DISPLAY_MSG);
  154. }
  155.  
  156. public Action:DISPLAY_MSG(Handle:timer)
  157. {
  158. PrintToChatAll(AD_MESSAGE);
  159. }
  160.  
  161.  
  162. public bool:OnClientConnect(client)
  163. {
  164. had_sunglasses[client] = false;
  165. g_used_count[client] = 0;
  166. }
  167.  
  168. public OnClientDisconnect(client)
  169. {
  170. had_sunglasses[client] = false;
  171. g_used_count[client] = 0;
  172. }
  173.  
  174.  
  175.  
  176. /** Support functions **/
  177. stock set_user_money(client, amount)
  178. {
  179. if(g_iMoney != -1)
  180. SetEntData(client, g_iMoney, amount);
  181. }
  182.  
  183. stock get_user_money(client)
  184. {
  185. if(g_iMoney != -1)
  186. return GetEntData(client, g_iMoney);
  187.  
  188. return 0;
  189. }
  190.  
  191.  
  192. stock remove_quotes(String:str[])
  193. {
  194. new maxlen = strlen(str);
  195. new i;
  196.  
  197. if(maxlen == 0)
  198. return;
  199.  
  200. if(str[maxlen - 1] == QUOTE_CHAR)
  201. str[--maxlen] = NULL_CHAR;
  202.  
  203. if(str[0] == QUOTE_CHAR)
  204. {
  205. for(i=0; i<=maxlen; i++)
  206. str[i] = str[i+1];
  207.  
  208. str[i-2] = NULL_CHAR;
  209. }
  210. }