[ZR] GrenadeEffects Model Timer

Broudy Rose

Участник
Сообщения
157
Реакции
22
Сделайте, пожалуйста, так, чтобы модель дымовой гранаты убиралась через 4 секунды, после создания:)

PHP:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <zombiereloaded>
#include <colors>

#define PLUGIN_VERSION "2.0"

#define FLASH 0
#define SMOKE 1

#define SOUND_FREEZE    "physics/glass/glass_impact_bullet4.wav"
#define SOUND_FREEZE_EXPLODE    "ui/freeze_cam.wav"

#define FragColor     {255,0,50,0}
#define FlashColor     {255,255,255,0}
#define SmokeColor    {75,255,75,0}
#define FreezeColor    {30,100,255,0}

new BeamSprite, GlowSprite, g_beamsprite, g_halosprite;

new maxents;

new Handle:Enable;
new Handle:Version;
new Handle:Trails;
new Handle:SmokeFreeze;
new Handle:SmokeFreezeDistance;
new Handle:SmokeFreezeDuration;
new Handle:FlashLight;
new Handle:FlashLightDistance;
new Handle:FlashLightDuration;
new Handle:FreezeTimer[MAXPLAYERS+1];

new SmokeLimit[MAXPLAYERS+1];
new FlashLimit[MAXPLAYERS+1];
new HeLimit[MAXPLAYERS+1];

new bool:IsFreezed[MAXPLAYERS+1];
new bool:enabled, bool:trails, bool:freezegren;

new Float:freezedistance, Float:freezeduration, Float:flashlightdistance, Float:flashlightduration;

public Plugin:myinfo =
{
    name = "Grenade Effects",
    author = "FrozDark (HLModders.ru LLC) & Str1k3r",
    description = "Adds Grenade Special Effects.",
    version = PLUGIN_VERSION,
    url = "http://www.real-gamer.ru/"
}

public OnPluginStart()
{
    Enable = CreateConVar("zr_greneffect_enable", "1", "Enables/Disables the plugin", 0, true, 0.0, true, 1.0);
    Version = CreateConVar("zr_greneffect_version", PLUGIN_VERSION, "Version of the plugin", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
    Trails = CreateConVar("zr_greneffect_trails", "1", "Enables/Disables Grenade Trails", 0, true, 0.0, true, 1.0);
    SmokeFreeze = CreateConVar("zr_greneffect_smoke_freeze", "1", "Enables/Disables a smoke grenade to be a freeze grenade", 0, true, 0.0, true, 1.0);
    SmokeFreezeDistance = CreateConVar("zr_greneffect_smoke_freeze_distance", "600.0", "Freeze grenade distance", 0, true, 100.0);
    SmokeFreezeDuration = CreateConVar("zr_greneffect_smoke_freeze_duration", "4.0", "Freeze grenade duration in seconds", 0, true, 1.0);
    FlashLight = CreateConVar("zr_greneffect_flash_light", "1", "Enables/Disables a flashbang to be a light", 0, true, 0.0, true, 1.0);
    FlashLightDistance = CreateConVar("zr_greneffect_flash_light_distance", "1000.0", "Light distance", 0, true, 100.0);
    FlashLightDuration = CreateConVar("zr_greneffect_flash_light_duration", "15.0", "Light duration in seconds", 0, true, 1.0);
    CreateConVar("zr_greneffect_smokelimit", "1", "Сколько всего игрок может купить дымовых гранат за раунд ? ( 0 = без лимита )", _);
    CreateConVar("zr_greneffect_flashlimit", "1", "Сколько всего игрок может купить световых гранат за раунд ? ( 0 = без лимита )", _);
    CreateConVar("zr_greneffect_helimit", "1", "Сколько всего игрок может купить боевых гранат за раунд ? ( 0 = без лимита )", _);
   
    AutoExecConfig(true, "zombiereloaded/GrenadeEffects");
   
    HookEvent("smokegrenade_detonate", SmokeDetonate);
    HookEvent("round_end", RoundEnd);
    AddNormalSoundHook(NormalSHook);
}

public OnMapStart()
{
    BeamSprite = PrecacheModel("materials/sprites/laserbeam.vmt");
    GlowSprite = PrecacheModel("sprites/blueglow2.vmt");
    g_beamsprite = PrecacheModel("materials/sprites/lgtning.vmt");
    g_halosprite = PrecacheModel("materials/sprites/halo01.vmt");
   
    PrecacheSound(SOUND_FREEZE);
    PrecacheSound(SOUND_FREEZE_EXPLODE);
}

public OnClientPutInServer(client)
{
    SmokeLimit[client] = 0;
    FlashLimit[client] = 0;
    HeLimit[client] = 0;
}

public OnConfigsExecuted()
{
    enabled = GetConVarBool(Enable);
    trails = GetConVarBool(Trails);
    freezegren = GetConVarBool(SmokeFreeze);

    freezedistance = GetConVarFloat(SmokeFreezeDistance);
    freezeduration = GetConVarFloat(SmokeFreezeDuration);
    flashlightdistance = GetConVarFloat(FlashLightDistance);
    flashlightduration = GetConVarFloat(FlashLightDuration);
}

public OnClientDisconnect_Post(client)
{
    IsFreezed[client] = false;
    if (FreezeTimer[client] != INVALID_HANDLE)
    {
        KillTimer(FreezeTimer[client]);
        FreezeTimer[client] = INVALID_HANDLE;
    }
}

public Action:FlashDetonate(Handle:timer, any:edict)
{
    if (!enabled || !freezegren)
        return;
   
    new Float:DetonateOrigin[3];

    GetEntPropVector(edict, Prop_Send, "m_vecOrigin", DetonateOrigin);
    AcceptEntityInput(edict, "Kill");
   
    DetonateOrigin[2] += 30.0;
   
    for (new i = 1; i <= MaxClients; i++)
    {
        if (IsClientInGame(i) && IsPlayerAlive(i) && ZR_IsClientZombie(i))
        {
            new Float:targetOrigin[3];
            GetClientAbsOrigin(i, targetOrigin);
           
            if (GetVectorDistance(DetonateOrigin, targetOrigin) <= freezedistance)
            {
                new Handle:trace = TR_TraceRayFilterEx(DetonateOrigin, targetOrigin, MASK_SHOT, RayType_EndPoint, FilterTarget, i);
           
                if (TR_DidHit(trace))
                {
                    if (TR_GetEntityIndex(trace) == i)
                        Freeze(i, freezeduration);
                }
                else
                {
                    GetClientEyePosition(i, targetOrigin);
                    targetOrigin[2] -= 1.0;
           
                    if (GetVectorDistance(DetonateOrigin, targetOrigin) <= freezedistance)
                    {
                        new Handle:trace2 = TR_TraceRayFilterEx(DetonateOrigin, targetOrigin, MASK_SHOT, RayType_EndPoint, FilterTarget, i);
               
                        if (TR_DidHit(trace2))
                        {
                            if (TR_GetEntityIndex(trace2) == i)
                                Freeze(i, freezeduration);
                        }
                        CloseHandle(trace2);
                    }
                }
                CloseHandle(trace);
            }
        }
    }
   
    TE_SetupBeamRingPoint(DetonateOrigin, 10.0, freezedistance, g_beamsprite, g_halosprite, 1, 10, 1.0, 5.0, 1.0, FreezeColor, 0, 0);
    TE_SendToAll();
    LightCreate(SMOKE, DetonateOrigin);
}

public Action:SmokeDetonate(Handle:event, const String:name[], bool:dontBroadcast)
{
    if (!enabled || !freezegren)
        return;
   
    decl String:EdictName[64];
    new client = GetClientOfUserId(GetEventInt(event, "userid"));
   
    maxents = GetMaxEntities();
   
    for (new edict = MaxClients; edict <= maxents; edict++)
    {
        if (IsValidEdict(edict))
        {
            GetEdictClassname(edict, EdictName, sizeof(EdictName));
            if (!strcmp(EdictName, "smokegrenade_projectile", false))
                if (GetEntPropEnt(edict, Prop_Send, "m_hThrower") == client)
                    AcceptEntityInput(edict, "Kill");
        }
    }
   
    new Float:DetonateOrigin[3];
    DetonateOrigin[0] = GetEventFloat(event, "x");
    DetonateOrigin[1] = GetEventFloat(event, "y");
    DetonateOrigin[2] = GetEventFloat(event, "z");
   
    SpawnEffect(client, DetonateOrigin);
}

public Action:RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
    for (new i = 1; i <= MaxClients; i++)
    {
        if (IsClientInGame(i))
        {
            SmokeLimit[i] = 0;
            FlashLimit[i] = 0;
            HeLimit[i] = 0;
        }
    }
}

stock SpawnEffect(client, Float:location[3])
{
    new ent = CreateEntityByName("prop_physics_override");
    if(!IsValidEntity(ent))
    {
        return -1;
    }
   
    PrecacheModel("models/props/slow/smoke_effect/slow_smoke_effect.mdl");
    SetEntityModel(ent, "models/props/slow/smoke_effect/slow_smoke_effect.mdl");
   
    DispatchSpawn(ent);
    TeleportEntity(ent, location, NULL_VECTOR, NULL_VECTOR);
    SetEntityMoveType(ent, MOVETYPE_NONE);
   
    SetEntProp(ent, Prop_Data, "m_takedamage", 0);
    AcceptEntityInput(ent, "DisableCollision");
    AcceptEntityInput(ent, "EnableCollision");
    SetEntProp(ent, Prop_Data, "m_CollisionGroup", 2, 4);
    SetEntPropEnt(ent, Prop_Send, "m_hOwnerEntity", client);
   
    CreateTimer(0.5, DmgDelay, ent, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);

    return ent;
}

public Action:DmgDelay(Handle:timer, any:iEntity)
{   
    if (!IsValidEdict(iEntity) || !IsValidEntity(iEntity))
    {
        return Plugin_Stop;
    }
    new Float:EntPos[3];
    GetEntPropVector(iEntity, Prop_Send, "m_vecOrigin", EntPos);
    new client = GetEntPropEnt(iEntity, Prop_Send, "m_hOwnerEntity");
    if (!IsClientInGame(client) || !IsPlayerAlive(client) || ZR_IsClientZombie(client))
    {
        AcceptEntityInput(iEntity, "Kill");
        return Plugin_Stop;
    }
    for (new i = 1; i <= MaxClients; i++)
    {
        if (IsClientInGame(i) && IsPlayerAlive(i) && ZR_IsClientZombie(i))
        {
            if (i != client)
            {
                new Float:MyPos[3];
                GetClientAbsOrigin(i, MyPos);
                if (GetVectorDistance(EntPos, MyPos) <= 220)
                {
                    SDKHooks_TakeDamage(i, client, client, 10.0, DMG_GENERIC);
                }
            }
        }
    }
    return Plugin_Continue;
}

public bool:FilterTarget(entity, contentsMask, any:data)
{
    return (data == entity);
}

Freeze(client, Float:time)
{
    if (FreezeTimer[client] != INVALID_HANDLE)
    {
        KillTimer(FreezeTimer[client]);
        FreezeTimer[client] = INVALID_HANDLE;
    }
       
    SetEntityMoveType(client, MOVETYPE_NONE);
    SetEntityRenderColor(client, 0, 0, 255, 190);
   
    new Float:vec[3];
    GetClientEyePosition(client, vec);
    EmitAmbientSound(SOUND_FREEZE, vec, client, SNDLEVEL_RAIDSIREN);

    TE_SetupGlowSprite(vec, GlowSprite, time, 1.5, 50);
    TE_SendToAll();
    IsFreezed[client] = true;
    FreezeTimer[client] = CreateTimer(time, Unfreeze, client);
}

public Action:Unfreeze(Handle:timer, any:client)
{
    if (IsFreezed[client])
    {
        SetEntityMoveType(client, MOVETYPE_WALK);
        SetEntityRenderColor(client, 255, 255, 255, 255);
        IsFreezed[client] = false;
        FreezeTimer[client] = INVALID_HANDLE;
    }
}

public OnEntityCreated(Entity, const String:Classname[])
{
    if (!enabled)
        return;
   
    if(StrEqual(Classname, "hegrenade_projectile"))
        BeamFollowCreate(Entity, FragColor);
       
    else if(StrEqual(Classname, "flashbang_projectile"))
    {
        CreateTimer(1.3, FlashDetonate, Entity, TIMER_FLAG_NO_MAPCHANGE);
        BeamFollowCreate(Entity, FlashColor);
    }
    else if(StrEqual(Classname, "smokegrenade_projectile"))
    {
        BeamFollowCreate(Entity, SmokeColor);
        CreateTimer(1.3, SmokeCreateEvent, Entity, TIMER_FLAG_NO_MAPCHANGE);
    }
    else if(freezegren && StrEqual(Classname, "env_particlesmokegrenade") && freezegren)
        AcceptEntityInput(Entity, "Kill");
}

public Action:SmokeCreateEvent(Handle:timer, any:entity)
{
    if (IsValidEdict(entity) && IsValidEntity(entity))
    {
        decl String:clsname[64];
        GetEdictClassname(entity, clsname, sizeof(clsname));
        if (!strcmp(clsname, "smokegrenade_projectile", false))
        {
            new Float:SmokeOrigin[3];
            GetEntPropVector(entity, Prop_Send, "m_vecOrigin", SmokeOrigin);
            new client = GetEntPropEnt(entity, Prop_Send, "m_hThrower");
            new userid = GetClientUserId(client);
       
            new Handle:event = CreateEvent("smokegrenade_detonate");
       
            SetEventInt(event, "userid", userid);
            SetEventFloat(event, "x", SmokeOrigin[0]);
            SetEventFloat(event, "y", SmokeOrigin[1]);
            SetEventFloat(event, "z", SmokeOrigin[2]);
            FireEvent(event);
        }
    }
}
       
BeamFollowCreate(Entity, Color[4])
{
    if (trails)
    {
        TE_SetupBeamFollow(Entity, BeamSprite,    0, Float:1.0, Float:10.0, Float:10.0, 5, Color);
        TE_SendToAll();   
    }
}

LightCreate(Gren, Float:Pos[3])   
{ 
    new iEntity = CreateEntityByName("light_dynamic");
    DispatchKeyValue(iEntity, "inner_cone", "0");
    DispatchKeyValue(iEntity, "cone", "80");
    DispatchKeyValue(iEntity, "brightness", "1");
    DispatchKeyValueFloat(iEntity, "spotlight_radius", 250.0);
    DispatchKeyValue(iEntity, "pitch", "90");
    DispatchKeyValue(iEntity, "style", "1");
    switch(Gren)
    {
        case FLASH : {
                DispatchKeyValue(iEntity, "_light", "75 75 255 255");
                DispatchKeyValueFloat(iEntity, "distance", flashlightdistance);
                EmitSoundToAll(SOUND_FREEZE_EXPLODE, iEntity, SNDCHAN_WEAPON);
                CreateTimer(1.0, Delete, iEntity, TIMER_FLAG_NO_MAPCHANGE);
            }
        case SMOKE : {
                DispatchKeyValue(iEntity, "_light", "0 255 0 255");
                DispatchKeyValueFloat(iEntity, "distance", freezedistance);
                EmitSoundToAll("items/nvg_on.wav", iEntity, SNDCHAN_WEAPON);
                CreateTimer(flashlightduration, Delete, iEntity, TIMER_FLAG_NO_MAPCHANGE);
            }
    }
    DispatchSpawn(iEntity);
    TeleportEntity(iEntity, Pos, NULL_VECTOR, NULL_VECTOR);
    AcceptEntityInput(iEntity, "TurnOn");
}

public Action:Delete(Handle:timer, any:entity)
{
    if(IsValidEdict(entity))
        AcceptEntityInput(entity, "kill");
}

public Action:NormalSHook(clients[64], &numClients, String:sample[PLATFORM_MAX_PATH], &entity, &channel, &Float:volume, &level, &pitch, &flags)
{
    if(freezegren && StrEqual(sample, "^weapons/smokegrenade/sg_explode.wav"))
        return Plugin_Handled;
    return Plugin_Continue;
}

public Action:CS_OnBuyCommand(client, const String:weapon[])
{
    if (StrEqual(weapon, "smokegrenade", false))
    {
        if (GetConVarInt(FindConVar("zr_greneffect_smokelimit")) > 0)
        {
            if (SmokeLimit[client] < GetConVarInt(FindConVar("zr_greneffect_smokelimit")))
            {
                SmokeLimit[client]++;
            }
            else
            {
                CPrintToChat(client, "{default}[{green}ZR{default}] {lightgreen}Вы не можете больше купить дымовые гранаты, т.к. привышен лимит. (%d / %d)", FlashLimit[client], GetConVarInt(FindConVar("zr_greneffect_smokelimit")));
                return Plugin_Handled;
            }
        }
    }
    else if (StrEqual(weapon, "flashbang", false))
    {
        if (GetConVarInt(FindConVar("zr_greneffect_flashlimit")) > 0)
        {
            if (FlashLimit[client] < GetConVarInt(FindConVar("zr_greneffect_flashlimit")))
            {
                FlashLimit[client]++;
            }
            else
            {
                CPrintToChat(client, "{default}[{green}ZR{default}] {lightgreen}Вы не можете больше купить световые гранаты, т.к. привышен лимит. (%d / %d)", FlashLimit[client], GetConVarInt(FindConVar("zr_greneffect_flashlimit")));
                return Plugin_Handled;
            }
        }
    }
    else if (StrEqual(weapon, "hegrenade", false))
    {
        if (GetConVarInt(FindConVar("zr_greneffect_helimit")) > 0)
        {
            if (HeLimit[client] < GetConVarInt(FindConVar("zr_greneffect_helimit")))
            {
                HeLimit[client]++;
            }
            else
            {
                CPrintToChat(client, "{default}[{green}ZR{default}] {lightgreen}Вы не можете больше купить боевые гранаты, т.к. привышен лимит. (%d / %d)", HeLimit[client], GetConVarInt(FindConVar("zr_greneffect_helimit")));
                return Plugin_Handled;
            }
        }
    }
    return Plugin_Continue;
}
 

Вложения

  • GrenadeEffects.sp
    14 КБ · Просмотры: 31
Сверху Снизу