Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
|
07-23-2022
, 23:28
Re: [L4D2] Nuke - Timer Issue
|
#15
|
Script is working, I added the following:
- ConVar Warning Message > StartWarning = CreateConVar ("l4d2_nuke_warning"
- !Nuke > RegConsoleCmd("sm_nuke", Command_Nuke, "Print Nuke Countdown To Players");
- Explosion > Taken From l4d2_custom_commands
but I had these errors, any ideas?
PHP Code:
L 07/24/2022 - 06:26:45: [SM] Exception reported: Invalid Handle 0 (error 4) L 07/24/2022 - 06:26:45: [SM] Blaming: L4D2_Nuke.smx L 07/24/2022 - 06:26:45: [SM] Call stack trace: L 07/24/2022 - 06:26:45: [SM] [0] SDKCall L 07/24/2022 - 06:26:45: [SM] [1] Line 279, C:\Users\Omar Alasfour\Desktop\Nuke.sp::FlingPlayer L 07/24/2022 - 06:26:45: [SM] [2] Line 257, C:\Users\Omar Alasfour\Desktop\Nuke.sp::CreateExplosion L 07/24/2022 - 06:26:45: [SM] [3] Line 171, C:\Users\Omar Alasfour\Desktop\Nuke.sp::timerStrike
PHP Code:
#pragma newdecls required #pragma semicolon 1 #include <sourcemod> #include <sdktools>
#define NUKE_SOUND "animation/overpass_jets.wav" #define EXPLOSION_SOUND "ambient/explosions/explode_1.wav" #define EXPLOSION_DEBRIS "animation/plantation_exlposion.wav"
#define FIRE_PARTICLE "gas_explosion_ground_fire" #define EXPLOSION_PARTICLE "FluidExplosion_fps"
#define PLUGIN_VERSION "1.1.0"
ConVar StartWarning; Handle g_Timer; float fNuke, fAnnounce, fEnd, g_fSeconds;
bool g_bLeftStartArea; bool g_bStrike; Handle sdkCallPushPlayer;
public Plugin myinfo = { name = "L4D2 Nuke", version = PLUGIN_VERSION, description = "Nuke Players With Countdown After Leaving Saferoom", author = "alasfourom, Grey83", url = "https://forums.alliedmods.net/" }
public void OnPluginStart() { CreateConVar("l4d2_nuke_version", PLUGIN_VERSION, "L4D2 Nuke" ,FCVAR_SPONLY|FCVAR_NOTIFY|FCVAR_DONTRECORD);
ConVar cvar; cvar = CreateConVar("l4d2_nuke_timer", "600.0", "Set The Time At Which Players Will Be Nuked [ Should Be Higher Than Announcer Time ]", _, true, 1.0, true, 3600.0); cvar.AddChangeHook(CVarChange_Nuke); fNuke = cvar.FloatValue;
cvar = CreateConVar("l4d2_nuke_announcer", "90.0", "Set The Time At Which Nuke Countdown Hint Will Be Announced To Players [ Should Be Lower Than Nuke Time, Disable = 0 ]", _, true, 1.0, true, 3600.0); cvar.AddChangeHook(CVarChange_Announce); fAnnounce = cvar.FloatValue; StartWarning = CreateConVar ("l4d2_nuke_warning", "1", "Display Nuke Warning Text When Players Leave Saferoom [ 0 = Disable - 1 = Enable ]", _, true, 0.0, true, 1.0);
AutoExecConfig(true, "L4D2_Nuke");
RegConsoleCmd("sm_nuke", Command_Nuke, "Print Nuke Countdown To Players");
HookEvent("player_left_start_area", Event_LeftStartArea); HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);
PrecacheSound(NUKE_SOUND); PrecacheSound(EXPLOSION_SOUND); PrecacheSound(EXPLOSION_DEBRIS); }
public void CVarChange_Nuke(ConVar cvar, const char[] oldValue, const char[] newValue) { fNuke = cvar.FloatValue; }
public void CVarChange_Announce(ConVar cvar, const char[] oldValue, const char[] newValue) { fAnnounce = cvar.FloatValue; }
public void OnMapStart() { g_bLeftStartArea = false; if(g_Timer) delete g_Timer; }
public void OnMapEnd() { OnMapStart(); }
public void Event_RoundEnd(Event event, const char[] name, bool dontBroadcast) { OnMapStart(); }
public void Event_LeftStartArea(Event event, const char[] name, bool dontBroadcast) { g_fSeconds = GetEngineTime(); if (!g_bLeftStartArea) g_bLeftStartArea = true; if(g_Timer) return;
int client = GetClientOfUserId(GetEventInt(event, "userid")); if(!client) return;
fEnd = GetEngineTime() + fNuke; int time = RoundToNearest(fNuke); PrintToChatAll("\x04[Warning] \x01Nuke Timeleft: \x03%d min %d sec", time / 60, time % 60);
g_Timer = CreateTimer(fAnnounce, Timer_StartCountDown); }
public Action Command_Nuke(int client, int args) { int timestart = RoundToNearest(fNuke); int timeleft = RoundToNearest(fNuke) - RoundToFloor(GetEngineTime() - g_fSeconds); if (!g_bLeftStartArea && GetConVarBool(StartWarning)) PrintToChatAll("\x04[Warning] \x01Nuke Timeleft: \x03%d min %d sec", timestart / 60, timestart % 60); if (g_bLeftStartArea && timeleft > 0) PrintToChatAll("\x04[Warning] \x01Nuke Timeleft: \x03%d min %d sec", timeleft / 60, timeleft % 60); if (g_bLeftStartArea && timeleft <= 0) PrintToChatAll("\x04[Warning] \x01You Have Been \x03Nuked"); return Plugin_Handled; }
public Action Timer_StartCountDown(Handle timer) { g_Timer = CreateTimer(1.0, Timer_CountDown, _, TIMER_REPEAT); TriggerTimer(g_Timer); return Plugin_Stop; }
public Action Timer_CountDown(Handle timer) { float time = fEnd - GetEngineTime(); if(time >= 0.0) { PrintHintTextToAll("Nuke Time: %d", RoundToNearest(time)); return Plugin_Continue; } EmitSoundToAll(NUKE_SOUND); for(int i = 1; i <= MaxClients; i++) if(IsClientInGame(i) && IsPlayerAlive(i) && IsClientSurvivor(i)) { g_bStrike = true; CreateTimer(2.0, timerKillPlayers, i); CreateTimer(6.0, timerStrikeTimeout, i, TIMER_FLAG_NO_MAPCHANGE); CreateTimer(1.0, timerStrike, i, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE); }
g_Timer = null; return Plugin_Stop; }
// Slaying Clients After 2 Seconds Of The Explosion For More Realastic Effect public Action timerKillPlayers(Handle timer, any client) { ForcePlayerSuicide(client); return Plugin_Handled; }
/*=========================================================================== // From Here Taken From l4d2_custom_commands // ===========================================================================*/
public Action timerStrikeTimeout(Handle timer) { g_bStrike = false; return Plugin_Continue; }
public Action timerStrike(Handle timer, any client) { if (!g_bStrike) return Plugin_Stop;
float pos[3]; GetClientAbsOrigin(client, pos); float radius = 1.0; pos[0] += GetRandomFloat(radius*-1, radius); pos[1] += GetRandomFloat(radius*-1, radius); CreateExplosion(pos); return Plugin_Continue; }
void CreateExplosion(float carPos[3]) { static char sRadius[1]; static char sPower[1]; float flMxDistance = 1.0; float power = 1.0; IntToString(1, sRadius, sizeof(sRadius)); IntToString(1, sPower, sizeof(sPower)); int exTrace = CreateEntityByName("info_particle_system"); int exPhys = CreateEntityByName("env_physexplosion"); int exParticle = CreateEntityByName("info_particle_system"); int exEntity = CreateEntityByName("env_explosion"); DispatchKeyValue(exParticle, "effect_name", EXPLOSION_PARTICLE); DispatchSpawn(exParticle); ActivateEntity(exParticle); TeleportEntity(exParticle, carPos, NULL_VECTOR, NULL_VECTOR);
DispatchKeyValue(exTrace, "effect_name", FIRE_PARTICLE); DispatchSpawn(exTrace); ActivateEntity(exTrace); TeleportEntity(exTrace, carPos, NULL_VECTOR, NULL_VECTOR);
DispatchKeyValue(exEntity, "fireballsprite", "sprites/muzzleflash4.vmt"); DispatchKeyValue(exEntity, "iMagnitude", sPower); DispatchKeyValue(exEntity, "iRadiusOverride", sRadius); DispatchKeyValue(exEntity, "spawnflags", "828"); DispatchSpawn(exEntity); TeleportEntity(exEntity, carPos, NULL_VECTOR, NULL_VECTOR);
DispatchKeyValue(exPhys, "radius", sRadius); DispatchKeyValue(exPhys, "magnitude", sPower); DispatchSpawn(exPhys); TeleportEntity(exPhys, carPos, NULL_VECTOR, NULL_VECTOR); EmitAmbientGenericSound(carPos, EXPLOSION_SOUND); EmitAmbientGenericSound(carPos, EXPLOSION_DEBRIS); AcceptEntityInput(exParticle, "Start"); AcceptEntityInput(exTrace, "Start"); AcceptEntityInput(exEntity, "Explode"); AcceptEntityInput(exPhys, "Explode"); float duration = 6.0; static char temp_str[64]; Format(temp_str, sizeof(temp_str), "OnUser1 !self:Kill::%f:1", duration+1.5); SetVariantString(temp_str); AcceptEntityInput(exParticle, "AddOutput"); AcceptEntityInput(exParticle, "FireUser1"); SetVariantString(temp_str); AcceptEntityInput(exEntity, "AddOutput"); AcceptEntityInput(exEntity, "FireUser1"); SetVariantString(temp_str); AcceptEntityInput(exPhys, "AddOutput"); AcceptEntityInput(exPhys, "FireUser1"); Format(temp_str, sizeof(temp_str), "OnUser1 !self:Stop::%f:1", duration); SetVariantString(temp_str); AcceptEntityInput(exTrace, "AddOutput"); AcceptEntityInput(exTrace, "FireUser1"); float survivorPos[3], traceVec[3], resultingFling[3], currentVelVec[3]; for (int i = 1; i <= MaxClients; i++) { if (!IsClientInGame(i) || !IsPlayerAlive(i)) continue;
GetEntPropVector(i, Prop_Data, "m_vecOrigin", survivorPos); if (GetVectorDistance(carPos, survivorPos) <= flMxDistance) { MakeVectorFromPoints(carPos, survivorPos, traceVec); GetVectorAngles(traceVec, resultingFling); resultingFling[0] = Cosine(DegToRad(resultingFling[1])) * power; resultingFling[1] = Sine(DegToRad(resultingFling[1])) * power; resultingFling[2] = power; GetEntPropVector(i, Prop_Data, "m_vecVelocity", currentVelVec); resultingFling[0] += currentVelVec[0]; resultingFling[1] += currentVelVec[1]; FlingPlayer(i, resultingFling, i); } } }
void EmitAmbientGenericSound(float pos[3], const char[] snd_str) { int snd_ent = CreateEntityByName("ambient_generic"); TeleportEntity(snd_ent, pos, NULL_VECTOR, NULL_VECTOR); DispatchKeyValue(snd_ent, "message", snd_str); DispatchKeyValue(snd_ent, "health", "10"); DispatchKeyValue(snd_ent, "spawnflags", "48"); DispatchSpawn(snd_ent); ActivateEntity(snd_ent); AcceptEntityInput(snd_ent, "PlaySound"); AcceptEntityInput(snd_ent, "Kill"); }
void FlingPlayer(int client, float vector[3], int attacker, float stunTime = 3.0) { SDKCall(sdkCallPushPlayer, client, vector, 16, attacker, stunTime); }
stock bool IsClientSurvivor (int client) { return (GetClientTeam(client) == 2); }
Last edited by alasfourom; 07-23-2022 at 23:39.
|
|