Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
|
11-18-2022
, 06:10
Re: [L4D2] Help fix the Game Crash when chainsaw on witch
|
#5
|
Yeah, seems like using Chainsaw + Explosion with this method below , will make game crash when killing a witch, at least for windows
Code:
void Explosion(int client, float vPos[3])
{
int entity = CreateEntityByName("prop_physics");
if (!IsValidEntity(entity)) return;
DispatchKeyValue(entity, "model", "models/props_junk/propanecanister001a.mdl");
DispatchSpawn(entity);
SetEntProp(entity, Prop_Send, "m_CollisionGroup", 1);
TeleportEntity(entity, vPos, NULL_VECTOR, NULL_VECTOR);
AcceptEntityInput(entity, "break");
}
Use this instead: Tested > Working Fine
PHP Code:
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#define PLUGIN_VERSION "1.0"
#define SOUND "ambient/explosions/explode_1.wav"
ConVar g_Cvar_Enable;
ConVar g_Cvar_Damage;
ConVar g_Cvar_Radius;
public void OnPluginStart()
{
CreateConVar ("l4d_witch_death_explosion_version", PLUGIN_VERSION, "l4d witch death explosion", FCVAR_SPONLY | FCVAR_NOTIFY | FCVAR_DONTRECORD);
g_Cvar_Enable = CreateConVar("l4d_witch_death_explodsion_enable", "1", "Enable l4d2 witch death explosion", FCVAR_NOTIFY, true, 0.0, true, 1.0);
g_Cvar_Damage = CreateConVar("l4d_witch_death_explodsion_damage", "20", "Set explosion damage after killing witches", FCVAR_NOTIFY);
g_Cvar_Radius = CreateConVar("l4d_witch_death_explodsion_radius", "300", "Set explosion radius after killing witches", FCVAR_NOTIFY);
AutoExecConfig(true, "l4d_witch_death_explosion");
HookEvent("witch_killed", Event_WitchKilled);
}
public void OnMapStart()
{
PrecacheSound(SOUND, false);
}
void Event_WitchKilled(Event event, const char[] name, bool dontBroadcast)
{
float vPos[3];
int witchid = event.GetInt("witchid");
if(!IsValidEntity(witchid) || !g_Cvar_Enable.BoolValue) return;
GetEntPropVector(witchid, Prop_Send, "m_vecOrigin", vPos);
ExplosionEffect(vPos);
PushForceEffect(vPos);
}
// From Earendil: https://forums.alliedmods.net/showthread.php?p=2747814
void ExplosionEffect(float vPos[3])
{
int entity = CreateEntityByName("env_explosion");
TeleportEntity(entity, vPos, NULL_VECTOR, NULL_VECTOR);
DispatchKeyValueFloat(entity, "iMagnitude", g_Cvar_Damage.FloatValue);
DispatchKeyValueFloat(entity, "iRadiusOverride", g_Cvar_Radius.FloatValue);
DispatchKeyValue(entity, "rendermode", "5");
DispatchKeyValue(entity, "spawnflags", "128");
DispatchKeyValue(entity, "fireballsprite", "sprites/zerogxplode.spr");
DispatchSpawn(entity);
SetVariantString("OnUser1 !self:Explode::0.01:1)");
AcceptEntityInput(entity, "Addoutput");
AcceptEntityInput(entity, "FireUser1");
EmitSoundToAll(SOUND, _, SNDCHAN_AUTO, SNDLEVEL_RAIDSIREN, SND_NOFLAGS, SNDVOL_NORMAL, SNDPITCH_LOW, -1, NULL_VECTOR, NULL_VECTOR, true, 0.0);
}
void PushForceEffect(float vPos[3])
{
float vTarg[3];
for (int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && IsPlayerAlive(i))
{
GetClientAbsOrigin(i, vTarg);
if(GetVectorDistance(vPos, vTarg) <= g_Cvar_Radius.FloatValue)
StaggerClient(GetClientUserId(i), vPos);
}
}
}
// From Silvers: https://forums.alliedmods.net/showthread.php?t=322063
void StaggerClient(int client, const float fPos[3])
{
static int iScriptLogic = INVALID_ENT_REFERENCE;
if(iScriptLogic == INVALID_ENT_REFERENCE || !IsValidEntity(iScriptLogic))
{
iScriptLogic = EntIndexToEntRef(CreateEntityByName("logic_script"));
if(iScriptLogic == INVALID_ENT_REFERENCE || !IsValidEntity(iScriptLogic)) return;
DispatchSpawn(iScriptLogic);
}
static char sBuffer[96];
Format(sBuffer, sizeof(sBuffer), "GetPlayerFromUserID(%d).Stagger(Vector(%d,%d,%d))", client, RoundFloat(fPos[0]), RoundFloat(fPos[1]), RoundFloat(fPos[2]));
SetVariantString(sBuffer);
AcceptEntityInput(iScriptLogic, "RunScriptCode");
RemoveEntity(iScriptLogic);
}
__________________
Last edited by alasfourom; 11-18-2022 at 10:41.
|
|