Senior Member
Join Date: Aug 2006
Location: United States
|
05-26-2009
, 16:28
Re: Turn off and Kill Light_dynamic Ent
|
#19
|
I'm still trying to figure out how to remove light_dynamic entities that I've created, or at least get them to actually turn off so they seem like they've been removed. Below is code I've been working on which effectively turns the smoke grenade in Counter Strike Source into a flare ( which happens to smoke a lot when it first goes off, ). The problem of course is that the light_dynamic entities I create are lingering even after the code designed to remove them has fired.
Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <sdktools_trace>
#include <clients>
#include <hacks>
new Handle:h_lightDynamicList;
public OnPluginStart()
{
HookEvent("smokegrenade_detonate", Event_SmokeGrenadeDetonate, EventHookMode_Post);
HookEvent("round_start", Hook_RoundStart);
HookEvent("round_end", Hook_RoundEnd);
}
public Action:Event_SmokeGrenadeDetonate(Handle:event, const String:name[], bool:dontBroadcast)
{
new target_playerID = GetEventInt(event,"userid");
new target_playerClient = GetClientOfUserId(target_playerID);
new Float:target_entityCoordX = GetEventFloat(event, "x");
new Float:target_entityCoordY = GetEventFloat(event, "y");
new Float:target_entityCoordZ = GetEventFloat(event, "z");
CreateFlare(target_playerClient, target_entityCoordX, target_entityCoordY, target_entityCoordZ);
}
public Action:Hook_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
h_lightDynamicList = CreateArray();
}
public Action:Hook_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
ResetLightDynamic();
}
public CreateFlare(any:target_playerClient, Float:target_entityCoordX, Float:target_entityCoordY, Float:target_entityCoordZ)
{
new String:target_entityCoord[50];
Format(target_entityCoord, sizeof(target_entityCoord), "%f %f %f", target_entityCoordX, target_entityCoordY, target_entityCoordZ);
/**
* Make the prop
*/
new target_propIndex = CreateEntityByName("prop_physics_override");
SetEntityModel(target_propIndex, "models/weapons/w_eq_smokegrenade.mdl");
DispatchKeyValue(target_propIndex, "origin", target_entityCoord);
new String:prop[64];
Format(prop, sizeof(prop), "prop%i", target_propIndex);
DispatchKeyValue(target_propIndex, "targetname", prop);
DispatchSpawn(target_propIndex);
SetEntProp(target_propIndex, Prop_Data, "m_CollisionGroup", 2);
SetEntityMoveType(target_propIndex, MOVETYPE_VPHYSICS);
SetEntProp(target_propIndex, Prop_Data, "m_nSolidType", 2);
SetEntProp(target_propIndex, Prop_Data, "m_takedamage", 0);
/**
* Make the flare
*/
new Float:brightness = 6.0;
new String:brightness_s[20];
FloatToString(brightness, brightness_s, sizeof(brightness_s));
new target_flareIndex = CreateEntityByName("light_dynamic");
DispatchKeyValue(target_flareIndex, "_light", "245 0 0");
DispatchKeyValue(target_flareIndex, "origin", target_entityCoord);
DispatchKeyValue(target_flareIndex, "brightness", brightness_s);
DispatchKeyValue(target_flareIndex, "distance", "256");
DispatchKeyValue(target_flareIndex, "style", "6");
new String:flare[64];
Format(flare, sizeof(flare), "flare%i", target_flareIndex);
DispatchKeyValue(target_flareIndex, "targetname", flare);
DispatchKeyValue(target_flareIndex, "paretname", prop);
DispatchSpawn(target_flareIndex);
SetVariantString(prop);
AcceptEntityInput(target_flareIndex, "SetParent");
PushArrayCell(h_lightDynamicList, target_flareIndex);
/**
* Make the glow
*/
new target_glowIndex = CreateEntityByName("env_lightglow");
DispatchKeyValue(target_glowIndex, "rendercolor", "250 0 0");
DispatchKeyValue(target_glowIndex, "VerticalGlowSize", "16");
DispatchKeyValue(target_glowIndex, "HorizontalGlowSize", "16");
DispatchKeyValue(target_glowIndex, "MinDist", "9000");
DispatchKeyValue(target_glowIndex, "MaxDist", "0");
DispatchKeyValue(target_glowIndex, "GlowProxySize", "2.0");
DispatchKeyValue(target_glowIndex, "HDRColorScale", "1.0");
DispatchKeyValue(target_glowIndex, "origin", target_entityCoord);
new String:glow[64];
Format(glow, sizeof(glow), "glow%i", target_glowIndex);
DispatchKeyValue(target_glowIndex, "targetname", glow);
DispatchKeyValue(target_glowIndex, "paretname", prop);
DispatchSpawn(target_glowIndex);
SetVariantString(prop);
AcceptEntityInput(target_glowIndex, "SetParent");
}
public ResetLightDynamic()
{
new target_lightDynamicSpawned = GetArraySize(h_lightDynamicList);
for (new i = 0; i < target_lightDynamicSpawned; i++)
{
new target_entityIndex = GetArrayCell(h_lightDynamicList, i);
UpdateLightDynamic(target_entityIndex);
}
CloseHandle(h_lightDynamicList);
}
public UpdateLightDynamic(any:target_entityIndex)
{
new target_entityValidStatus = IsValidEntity(target_entityIndex);
if (target_entityValidStatus == 1)
{
AcceptEntityInput(target_entityIndex, "TurnOff");
AcceptEntityInput(target_entityIndex, "Kill");
RemoveEdict(target_entityIndex);
PrintToChatAll("removing light dynamic index %i", target_entityIndex);
}
}
|
|