Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.42 KB | None | 0 0
  1. #include <sdktools>
  2. #include <shop>
  3.  
  4. #pragma semicolon 1
  5. #pragma newdecls required
  6.  
  7. #define CATEGORY "granades"
  8. #define ITEM "freezenade"
  9.  
  10. ConVar g_cPrice, g_cGoldPrice, g_cGoldSellPrice, g_cSellPrice, g_cTime, g_cTimeGranade, g_cFreezeDist;
  11.  
  12. bool g_bSpecialGrenade[MAXPLAYERS+1];
  13. ItemId id;
  14. int g_beamsprite, g_halosprite,GlowSprite;
  15. float g_fTime, g_fFreezeDist;
  16.  
  17. Handle h_freeze_timer[MAXPLAYERS+1];
  18.  
  19. public Plugin myinfo =
  20. {
  21. name = "[Shop] Freeze Nades",
  22. author = "asdf",
  23. version = "1.2",
  24. };
  25.  
  26. public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
  27. {
  28. MarkNativeAsOptional("Shop_SetItemGoldPrice");
  29. MarkNativeAsOptional("Shop_SetItemGoldSellPrice");
  30. return APLRes_Success;
  31. }
  32.  
  33. public void OnPluginStart()
  34. {
  35. HookEvent("decoy_firing", Event_Decoy);
  36. HookEvent("round_start", OnRoundStart);
  37. HookEvent("player_spawn", Event_Spawn);
  38.  
  39. g_cPrice = CreateConVar("sm_shop_freezenade_price", "1000", "Стоимость покупки замораживающей гранаты в кредитах.", 0, true, 0.0); g_cPrice.AddChangeHook(OnCvarChange);
  40. g_cSellPrice = CreateConVar("sm_shop_freezenade_sellprice", "500", "Стоимость продажи замораживающей гранаты в кредитах.", 0, true, 0.0); g_cSellPrice.AddChangeHook(OnCvarChange);
  41. g_cGoldPrice = CreateConVar("sm_shop_freezenade_gold_price", "100", "Стоимость покупки замораживающей гранаты в золоте.", 0, true, 0.0); g_cGoldPrice.AddChangeHook(OnCvarChange);
  42. g_cGoldSellPrice = CreateConVar("sm_shop_freezenade_gold_sellprice", "50", "Стоимость продажи замораживающей гранаты в золоте.", 0, true, 0.0); g_cGoldSellPrice.AddChangeHook(OnCvarChange);
  43. g_cTimeGranade = CreateConVar("sm_shop_timeusenade", "86400", "Длительность замораживающей гранаты в секундах.", 0, true, 0.0); g_cTimeGranade.AddChangeHook(OnCvarChange);
  44. g_cTime = CreateConVar("sm_shop_freezetime", "10.0", "Время заморозки игрока", 0, true, 0.0); g_cTime.AddChangeHook(OnCvarChange);
  45. g_cFreezeDist = CreateConVar("sm_shop_freezedistance", "600", "Радиус в котором заморозит игроков", 0, true, 0.0); g_cFreezeDist.AddChangeHook(OnCvarChange);
  46. AutoExecConfig(true, "shop_freezenade", "shop");
  47.  
  48. if (Shop_IsStarted()) Shop_Started();
  49. }
  50.  
  51. public Action OnRoundStart(Event event, const char[] name, bool dontBroadcast)
  52. {
  53. for (int i = 1; i <= MaxClients; ++i) if (h_freeze_timer[i] != INVALID_HANDLE)
  54. {
  55. KillTimer(h_freeze_timer[i]);
  56. h_freeze_timer[i] = INVALID_HANDLE;
  57. }
  58. }
  59.  
  60. public Action Event_Spawn(Event event, const char[] name, bool dontBroadcast){
  61. int client = GetClientOfUserId(event.GetInt("userid"));
  62. if(g_bSpecialGrenade[client] && GetClientTeam(client) > 1 && IsPlayerAlive(client))
  63. GivePlayerItem(client, "weapon_decoy");
  64. return Plugin_Continue;
  65. }
  66.  
  67. public void OnConfigsExecuted()
  68. {
  69. g_fTime = g_cTime.FloatValue;
  70. g_fFreezeDist = g_cFreezeDist.FloatValue;
  71. }
  72.  
  73. public void Shop_Started()
  74. {
  75. CategoryId category_id = Shop_RegisterCategory(CATEGORY, "Спец.Гранаты", "");
  76. if (Shop_StartItem(category_id, ITEM))
  77. {
  78. Shop_SetInfo("Замораживающая", "Замораживает игроков в радиуса поражения", g_cPrice.IntValue, g_cSellPrice.IntValue, Item_Togglable, g_cTimeGranade.IntValue, g_cGoldPrice.IntValue, g_cGoldSellPrice.IntValue);
  79. Shop_SetCallbacks(_, OnDecoyNadeUsed);
  80. Shop_EndItem();
  81. }
  82. }
  83.  
  84. public void OnMapStart()
  85. {
  86. g_beamsprite = PrecacheModel("materials/sprites/lgtning.vmt");
  87. g_halosprite = PrecacheModel("materials/sprites/halo01.vmt");
  88. GlowSprite = PrecacheModel("materials/sprites/blueglow1.vmt");
  89. AddFileToDownloadsTable("materials/models/hypy/hype.vmt");
  90. AddFileToDownloadsTable("materials/models/spree/spree.vtf");
  91. AddFileToDownloadsTable("models/spree/spree.mdl");
  92. AddFileToDownloadsTable("models/spree/spree.phy");
  93. AddFileToDownloadsTable("models/spree/spree.vvd");
  94. AddFileToDownloadsTable("models/spree/spree.dx80.vtx");
  95. AddFileToDownloadsTable("models/spree/spree.dx90.vtx");
  96. AddFileToDownloadsTable("models/spree/spree.sw.vtx");
  97. PrecacheModel("models/spree/spree.mdl");
  98. PrecacheSound("physics/glass/glass_impact_bullet4.wav");
  99. }
  100.  
  101. public void OnCvarChange(ConVar cvar, const char[] oldValue, const char[] newValue)
  102. {
  103. if (cvar == g_cPrice && id != INVALID_ITEM)
  104. {
  105. Shop_SetItemPrice(id, StringToInt(newValue));
  106. }
  107. if (cvar == g_cSellPrice && id != INVALID_ITEM)
  108. {
  109. Shop_SetItemSellPrice(id, StringToInt(newValue));
  110. }
  111. if (cvar == g_cGoldPrice && id != INVALID_ITEM)
  112. {
  113. Shop_SetItemGoldPrice(id, StringToInt(newValue));
  114. }
  115. if (cvar == g_cGoldSellPrice && id != INVALID_ITEM)
  116. {
  117. Shop_SetItemGoldSellPrice(id, StringToInt(newValue));
  118. }
  119. if (cvar == g_cFreezeDist)
  120. {
  121. g_fFreezeDist = StringToFloat(newValue);
  122. }
  123. if (cvar == g_cTime)
  124. {
  125. g_fTime = StringToFloat(newValue);
  126. }
  127. }
  128.  
  129. public Action Event_Decoy(Event event, const char[] name, bool dontBroadcast)
  130. {
  131. int client = GetClientOfUserId(event.GetInt("userid"));
  132. if (!IsClientInGame(client) || !IsPlayerAlive(client) || !g_bSpecialGrenade[client])
  133. {
  134. return Plugin_Continue;
  135. }
  136.  
  137. float fPos[3];
  138. fPos[0] = event.GetFloat("x");
  139. fPos[1] = event.GetFloat("y");
  140. fPos[2] = event.GetFloat("z") + 10.0;
  141.  
  142. RemoveEdict(event.GetInt("entityid"));
  143.  
  144. TE_SetupBeamRingPoint(fPos, 10.0, g_fFreezeDist, g_beamsprite, g_halosprite, 1, 1, 0.2, 100.0, 1.0, {0, 217, 255, 255}, 0, 0);
  145. TE_SendToAll();
  146.  
  147. float targetOrigin[3];
  148. Handle trace;
  149. for (int i = 1, clientteam = GetClientTeam(client); i <= MaxClients; ++i)
  150. {
  151. if (!IsClientInGame(i) || !IsPlayerAlive(i) || GetClientTeam(i) == clientteam)
  152. {
  153. continue;
  154. }
  155.  
  156. GetClientAbsOrigin(i, targetOrigin); targetOrigin[2] += 2.0;
  157. if (GetVectorDistance(fPos, targetOrigin) > g_fFreezeDist)
  158. {
  159. continue;
  160. }
  161.  
  162. trace = TR_TraceRayFilterEx(fPos, targetOrigin, MASK_SOLID, RayType_EndPoint, FilterTarget, i);
  163.  
  164. if (!TR_DidHit(trace) && TR_GetEntityIndex(trace) != i || GetVectorDistance(fPos, targetOrigin) > 100.0)
  165. {
  166. continue;
  167. }
  168. Freeze(i);
  169. }
  170.  
  171. delete trace;
  172.  
  173. return Plugin_Continue;
  174. }
  175.  
  176. public bool FilterTarget(int entity,int contentsMask, any data)
  177. {
  178. return (data == entity);
  179. }
  180.  
  181. void Freeze(int client)
  182. {
  183. float NULL_VELOCITY[3] = {0.0, 0.0, 0.0};
  184. SetEntityMoveType(client, MOVETYPE_NONE);
  185. SetEntProp(client, Prop_Data, "m_fFlags", GetEntProp(client, Prop_Data, "m_fFlags")|FL_ATCONTROLS);
  186. TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, NULL_VELOCITY);
  187.  
  188. float origin[3];
  189. GetClientAbsOrigin(client, origin);
  190. int ent = SpawnPropPhysicsOverrideByOrigin("models/spree/spree.mdl", origin);
  191.  
  192. char output[64];
  193. FormatEx(output, sizeof(output), "OnUser1 !self:kill::%f:1",g_fTime);
  194. SetVariantString(output);
  195. AcceptEntityInput(ent, "AddOutput");
  196. AcceptEntityInput(ent, "FireUser1");
  197.  
  198. float vec[3];
  199. GetClientEyePosition(client, vec);
  200. vec[2] -= 50.0;
  201. EmitSoundToAll("physics/glass/glass_impact_bullet4.wav", SOUND_FROM_WORLD, SNDCHAN_AUTO, SNDLEVEL_NORMAL, SND_NOFLAGS, SNDVOL_NORMAL, SNDPITCH_NORMAL, -1, vec);
  202.  
  203. TE_SetupGlowSprite(vec, GlowSprite, g_fTime, 2.0, 50);
  204. TE_SendToAll();
  205.  
  206. h_freeze_timer[client] = CreateTimer(g_fTime, Unfreeze, client, TIMER_FLAG_NO_MAPCHANGE);
  207. }
  208.  
  209.  
  210. int SpawnPropPhysicsOverrideByOrigin(const char[] sModel, const float vOrigin[3], const float vAngles[3]={0.0, 0.0, 0.0})
  211. {
  212. int iEntity = CreateEntityByName("prop_dynamic_override");
  213. if ( IsValidEdict(iEntity) )
  214. {
  215. DispatchKeyValueVector(iEntity, "origin", vOrigin);
  216. DispatchKeyValueVector(iEntity, "angles", vAngles);
  217. DispatchKeyValue(iEntity, "model", sModel);
  218.  
  219. if ( DispatchSpawn(iEntity) ) {
  220. return iEntity;
  221. }
  222. else {
  223. LogError("Can't dispatch prop_physics_override");
  224. }
  225. }
  226. else {
  227. LogError("Can't create prop_physics_override");
  228. }
  229.  
  230. return -1;
  231. }
  232.  
  233. public Action Unfreeze(Handle timer, any client)
  234. {
  235. if (h_freeze_timer[client] != INVALID_HANDLE)
  236. {
  237. SetEntityMoveType(client, MOVETYPE_WALK);
  238. SetEntProp(client, Prop_Data, "m_fFlags", GetEntProp(client, Prop_Data, "m_fFlags")&~FL_ATCONTROLS);
  239. h_freeze_timer[client] = INVALID_HANDLE;
  240. }
  241. }
  242.  
  243. public ShopAction OnDecoyNadeUsed(int client, CategoryId category_id, const char[] category, ItemId item_id, const char[] item, bool isOn, bool elapsed)
  244. {
  245. if (isOn || elapsed)
  246. {
  247. g_bSpecialGrenade[client] = false;
  248. return Shop_UseOff;
  249. }
  250. g_bSpecialGrenade[client]= true;
  251. return Shop_UseOn;
  252. }
  253.  
  254. public void OnClientDisconnect(int client)
  255. {
  256. if (h_freeze_timer[client] != INVALID_HANDLE)
  257. {
  258. KillTimer(h_freeze_timer[client]);
  259. h_freeze_timer[client] = INVALID_HANDLE;
  260. }
  261. }
  262.  
  263. public void OnPluginEnd()
  264. {
  265. Shop_UnregisterMe();
  266. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement