Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sdktools>
- #include <shop>
- #pragma semicolon 1
- #pragma newdecls required
- #define CATEGORY "granades"
- #define ITEM "freezenade"
- ConVar g_cPrice, g_cGoldPrice, g_cGoldSellPrice, g_cSellPrice, g_cTime, g_cTimeGranade, g_cFreezeDist;
- bool g_bSpecialGrenade[MAXPLAYERS+1];
- ItemId id;
- int g_beamsprite, g_halosprite,GlowSprite;
- float g_fTime, g_fFreezeDist;
- Handle h_freeze_timer[MAXPLAYERS+1];
- public Plugin myinfo =
- {
- name = "[Shop] Freeze Nades",
- author = "asdf",
- version = "1.2",
- };
- public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
- {
- MarkNativeAsOptional("Shop_SetItemGoldPrice");
- MarkNativeAsOptional("Shop_SetItemGoldSellPrice");
- return APLRes_Success;
- }
- public void OnPluginStart()
- {
- HookEvent("decoy_firing", Event_Decoy);
- HookEvent("round_start", OnRoundStart);
- HookEvent("player_spawn", Event_Spawn);
- g_cPrice = CreateConVar("sm_shop_freezenade_price", "1000", "Стоимость покупки замораживающей гранаты в кредитах.", 0, true, 0.0); g_cPrice.AddChangeHook(OnCvarChange);
- g_cSellPrice = CreateConVar("sm_shop_freezenade_sellprice", "500", "Стоимость продажи замораживающей гранаты в кредитах.", 0, true, 0.0); g_cSellPrice.AddChangeHook(OnCvarChange);
- g_cGoldPrice = CreateConVar("sm_shop_freezenade_gold_price", "100", "Стоимость покупки замораживающей гранаты в золоте.", 0, true, 0.0); g_cGoldPrice.AddChangeHook(OnCvarChange);
- g_cGoldSellPrice = CreateConVar("sm_shop_freezenade_gold_sellprice", "50", "Стоимость продажи замораживающей гранаты в золоте.", 0, true, 0.0); g_cGoldSellPrice.AddChangeHook(OnCvarChange);
- g_cTimeGranade = CreateConVar("sm_shop_timeusenade", "86400", "Длительность замораживающей гранаты в секундах.", 0, true, 0.0); g_cTimeGranade.AddChangeHook(OnCvarChange);
- g_cTime = CreateConVar("sm_shop_freezetime", "10.0", "Время заморозки игрока", 0, true, 0.0); g_cTime.AddChangeHook(OnCvarChange);
- g_cFreezeDist = CreateConVar("sm_shop_freezedistance", "600", "Радиус в котором заморозит игроков", 0, true, 0.0); g_cFreezeDist.AddChangeHook(OnCvarChange);
- AutoExecConfig(true, "shop_freezenade", "shop");
- if (Shop_IsStarted()) Shop_Started();
- }
- public Action OnRoundStart(Event event, const char[] name, bool dontBroadcast)
- {
- for (int i = 1; i <= MaxClients; ++i) if (h_freeze_timer[i] != INVALID_HANDLE)
- {
- KillTimer(h_freeze_timer[i]);
- h_freeze_timer[i] = INVALID_HANDLE;
- }
- }
- public Action Event_Spawn(Event event, const char[] name, bool dontBroadcast){
- int client = GetClientOfUserId(event.GetInt("userid"));
- if(g_bSpecialGrenade[client] && GetClientTeam(client) > 1 && IsPlayerAlive(client))
- GivePlayerItem(client, "weapon_decoy");
- return Plugin_Continue;
- }
- public void OnConfigsExecuted()
- {
- g_fTime = g_cTime.FloatValue;
- g_fFreezeDist = g_cFreezeDist.FloatValue;
- }
- public void Shop_Started()
- {
- CategoryId category_id = Shop_RegisterCategory(CATEGORY, "Спец.Гранаты", "");
- if (Shop_StartItem(category_id, ITEM))
- {
- Shop_SetInfo("Замораживающая", "Замораживает игроков в радиуса поражения", g_cPrice.IntValue, g_cSellPrice.IntValue, Item_Togglable, g_cTimeGranade.IntValue, g_cGoldPrice.IntValue, g_cGoldSellPrice.IntValue);
- Shop_SetCallbacks(_, OnDecoyNadeUsed);
- Shop_EndItem();
- }
- }
- public void OnMapStart()
- {
- g_beamsprite = PrecacheModel("materials/sprites/lgtning.vmt");
- g_halosprite = PrecacheModel("materials/sprites/halo01.vmt");
- GlowSprite = PrecacheModel("materials/sprites/blueglow1.vmt");
- AddFileToDownloadsTable("materials/models/hypy/hype.vmt");
- AddFileToDownloadsTable("materials/models/spree/spree.vtf");
- AddFileToDownloadsTable("models/spree/spree.mdl");
- AddFileToDownloadsTable("models/spree/spree.phy");
- AddFileToDownloadsTable("models/spree/spree.vvd");
- AddFileToDownloadsTable("models/spree/spree.dx80.vtx");
- AddFileToDownloadsTable("models/spree/spree.dx90.vtx");
- AddFileToDownloadsTable("models/spree/spree.sw.vtx");
- PrecacheModel("models/spree/spree.mdl");
- PrecacheSound("physics/glass/glass_impact_bullet4.wav");
- }
- public void OnCvarChange(ConVar cvar, const char[] oldValue, const char[] newValue)
- {
- if (cvar == g_cPrice && id != INVALID_ITEM)
- {
- Shop_SetItemPrice(id, StringToInt(newValue));
- }
- if (cvar == g_cSellPrice && id != INVALID_ITEM)
- {
- Shop_SetItemSellPrice(id, StringToInt(newValue));
- }
- if (cvar == g_cGoldPrice && id != INVALID_ITEM)
- {
- Shop_SetItemGoldPrice(id, StringToInt(newValue));
- }
- if (cvar == g_cGoldSellPrice && id != INVALID_ITEM)
- {
- Shop_SetItemGoldSellPrice(id, StringToInt(newValue));
- }
- if (cvar == g_cFreezeDist)
- {
- g_fFreezeDist = StringToFloat(newValue);
- }
- if (cvar == g_cTime)
- {
- g_fTime = StringToFloat(newValue);
- }
- }
- public Action Event_Decoy(Event event, const char[] name, bool dontBroadcast)
- {
- int client = GetClientOfUserId(event.GetInt("userid"));
- if (!IsClientInGame(client) || !IsPlayerAlive(client) || !g_bSpecialGrenade[client])
- {
- return Plugin_Continue;
- }
- float fPos[3];
- fPos[0] = event.GetFloat("x");
- fPos[1] = event.GetFloat("y");
- fPos[2] = event.GetFloat("z") + 10.0;
- RemoveEdict(event.GetInt("entityid"));
- 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);
- TE_SendToAll();
- float targetOrigin[3];
- Handle trace;
- for (int i = 1, clientteam = GetClientTeam(client); i <= MaxClients; ++i)
- {
- if (!IsClientInGame(i) || !IsPlayerAlive(i) || GetClientTeam(i) == clientteam)
- {
- continue;
- }
- GetClientAbsOrigin(i, targetOrigin); targetOrigin[2] += 2.0;
- if (GetVectorDistance(fPos, targetOrigin) > g_fFreezeDist)
- {
- continue;
- }
- trace = TR_TraceRayFilterEx(fPos, targetOrigin, MASK_SOLID, RayType_EndPoint, FilterTarget, i);
- if (!TR_DidHit(trace) && TR_GetEntityIndex(trace) != i || GetVectorDistance(fPos, targetOrigin) > 100.0)
- {
- continue;
- }
- Freeze(i);
- }
- delete trace;
- return Plugin_Continue;
- }
- public bool FilterTarget(int entity,int contentsMask, any data)
- {
- return (data == entity);
- }
- void Freeze(int client)
- {
- float NULL_VELOCITY[3] = {0.0, 0.0, 0.0};
- SetEntityMoveType(client, MOVETYPE_NONE);
- SetEntProp(client, Prop_Data, "m_fFlags", GetEntProp(client, Prop_Data, "m_fFlags")|FL_ATCONTROLS);
- TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, NULL_VELOCITY);
- float origin[3];
- GetClientAbsOrigin(client, origin);
- int ent = SpawnPropPhysicsOverrideByOrigin("models/spree/spree.mdl", origin);
- char output[64];
- FormatEx(output, sizeof(output), "OnUser1 !self:kill::%f:1",g_fTime);
- SetVariantString(output);
- AcceptEntityInput(ent, "AddOutput");
- AcceptEntityInput(ent, "FireUser1");
- float vec[3];
- GetClientEyePosition(client, vec);
- vec[2] -= 50.0;
- EmitSoundToAll("physics/glass/glass_impact_bullet4.wav", SOUND_FROM_WORLD, SNDCHAN_AUTO, SNDLEVEL_NORMAL, SND_NOFLAGS, SNDVOL_NORMAL, SNDPITCH_NORMAL, -1, vec);
- TE_SetupGlowSprite(vec, GlowSprite, g_fTime, 2.0, 50);
- TE_SendToAll();
- h_freeze_timer[client] = CreateTimer(g_fTime, Unfreeze, client, TIMER_FLAG_NO_MAPCHANGE);
- }
- int SpawnPropPhysicsOverrideByOrigin(const char[] sModel, const float vOrigin[3], const float vAngles[3]={0.0, 0.0, 0.0})
- {
- int iEntity = CreateEntityByName("prop_dynamic_override");
- if ( IsValidEdict(iEntity) )
- {
- DispatchKeyValueVector(iEntity, "origin", vOrigin);
- DispatchKeyValueVector(iEntity, "angles", vAngles);
- DispatchKeyValue(iEntity, "model", sModel);
- if ( DispatchSpawn(iEntity) ) {
- return iEntity;
- }
- else {
- LogError("Can't dispatch prop_physics_override");
- }
- }
- else {
- LogError("Can't create prop_physics_override");
- }
- return -1;
- }
- public Action Unfreeze(Handle timer, any client)
- {
- if (h_freeze_timer[client] != INVALID_HANDLE)
- {
- SetEntityMoveType(client, MOVETYPE_WALK);
- SetEntProp(client, Prop_Data, "m_fFlags", GetEntProp(client, Prop_Data, "m_fFlags")&~FL_ATCONTROLS);
- h_freeze_timer[client] = INVALID_HANDLE;
- }
- }
- public ShopAction OnDecoyNadeUsed(int client, CategoryId category_id, const char[] category, ItemId item_id, const char[] item, bool isOn, bool elapsed)
- {
- if (isOn || elapsed)
- {
- g_bSpecialGrenade[client] = false;
- return Shop_UseOff;
- }
- g_bSpecialGrenade[client]= true;
- return Shop_UseOn;
- }
- public void OnClientDisconnect(int client)
- {
- if (h_freeze_timer[client] != INVALID_HANDLE)
- {
- KillTimer(h_freeze_timer[client]);
- h_freeze_timer[client] = INVALID_HANDLE;
- }
- }
- public void OnPluginEnd()
- {
- Shop_UnregisterMe();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement