Skip to content

Commit

Permalink
Fixed valve votemaps
Browse files Browse the repository at this point in the history
Fixed valve votemaps not working at the end of the round.
  • Loading branch information
Sarrus1 committed Oct 9, 2020
1 parent 5d09c53 commit 1b1a20c
Showing 1 changed file with 54 additions and 72 deletions.
126 changes: 54 additions & 72 deletions scripting/retakes_instadefuse.sp
Expand Up @@ -6,20 +6,19 @@
#pragma newdecls required

#define MESSAGE_PREFIX "[\x04InstantDefuse\x01]"

Handle hEndIfTooLate = null;
Handle hDefuseIfTime = null;
Handle hInfernoDuration = null;
Handle hTimer_MolotovThreatEnd = null;
ConVar hMaxrounds = null;

Handle fw_OnInstantDefusePre = null;
Handle fw_OnInstantDefusePost = null;

float g_c4PlantTime = 0.0;
bool g_bAlreadyComplete = false;
bool g_bWouldMakeIt = false;

public Plugin myinfo =
{
name = "[Retakes] Instant Defuse",
Expand All @@ -37,16 +36,14 @@ public void OnPluginStart()
HookEvent("bomb_planted", Event_BombPlanted, EventHookMode_Pre);
HookEvent("molotov_detonate", Event_MolotovDetonate);
HookEvent("hegrenade_detonate", Event_AttemptInstantDefuse, EventHookMode_Post);

HookEvent("player_death", Event_AttemptInstantDefuse, EventHookMode_PostNoCopy);
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);


hInfernoDuration = CreateConVar("instant_defuse_inferno_duration", "7.0", "If Valve ever changed the duration of molotov, this cvar should change with it.");
hEndIfTooLate = CreateConVar("instant_defuse_end_if_too_late", "1.0", "End the round if too late.", _, true, 0.0, true, 1.0);
hDefuseIfTime = CreateConVar("instant_defuse_if_time", "1.0", "Instant defuse if there is time to do so.", _, true, 0.0, true, 1.0);
hMaxrounds = FindConVar("mp_maxrounds");


// Added the forwards to allow other plugins to call this one.
fw_OnInstantDefusePre = CreateGlobalForward("InstantDefuse_OnInstantDefusePre", ET_Event, Param_Cell, Param_Cell);
fw_OnInstantDefusePost = CreateGlobalForward("InstantDefuse_OnInstantDefusePost", ET_Ignore, Param_Cell, Param_Cell);
Expand All @@ -61,21 +58,13 @@ public Action Event_RoundStart(Handle event, const char[] name, bool dontBroadca
{
g_bAlreadyComplete = false;
g_bWouldMakeIt = false;

if (hTimer_MolotovThreatEnd != null)
{
delete hTimer_MolotovThreatEnd;
}
}

public Action Event_RoundEnd(Handle event, const char[] name, bool dontBroadcast)
{
if ((CS_GetTeamScore(CS_TEAM_T) + CS_GetTeamScore(CS_TEAM_CT)) >= hMaxrounds.IntValue)
{
ForceEnd();
}
}

public Action Event_BombPlanted(Handle event, const char[] name, bool dontBroadcast)
{
g_c4PlantTime = GetGameTime();
Expand All @@ -87,18 +76,18 @@ public Action Event_BombBeginDefuse(Handle event, const char[] name, bool dontBr
{
return Plugin_Handled;
}

RequestFrame(Event_BombBeginDefusePlusFrame, GetEventInt(event, "userid"));

return Plugin_Continue;
}

public void Event_BombBeginDefusePlusFrame(int userId)
{
g_bWouldMakeIt = false;

int client = GetClientOfUserId(userId);

if (IsValidClient(client))
{
AttemptInstantDefuse(client);
Expand All @@ -111,51 +100,51 @@ void AttemptInstantDefuse(int client, int exemptNade = 0)
{
return;
}

int StartEnt = MaxClients + 1;

int c4 = FindEntityByClassname(StartEnt, "planted_c4");

if (c4 == -1)
{
return;
}

bool hasDefuseKit = HasDefuseKit(client);
float c4TimeLeft = GetConVarFloat(FindConVar("mp_c4timer")) - (GetGameTime() - g_c4PlantTime);

if (!g_bWouldMakeIt)
{
g_bWouldMakeIt = (c4TimeLeft >= 10.0 && !hasDefuseKit) || (c4TimeLeft >= 5.0 && hasDefuseKit);
}

if (GetConVarInt(hEndIfTooLate) == 1 && !g_bWouldMakeIt)
{
if (!OnInstandDefusePre(client, c4))
{
return;
}

for (int i = 0; i <= MaxClients; i++)
{
if (IsValidClient(i))
{
PrintToChat(i, "%T", "InstaDefuseUnsuccessful", i, MESSAGE_PREFIX, c4TimeLeft);
}
}

g_bAlreadyComplete = true;

// Force Terrorist win because they do not have enough time to defuse the bomb.
EndRound(CS_TEAM_T);

return;
}
else if (GetConVarInt(hDefuseIfTime) != 1 || GetEntityFlags(client) && !FL_ONGROUND)
{
return;
}

int ent;
if ((ent = FindEntityByClassname(StartEnt, "hegrenade_projectile")) != -1 || (ent = FindEntityByClassname(StartEnt, "molotov_projectile")) != -1)
{
Expand All @@ -168,10 +157,10 @@ void AttemptInstantDefuse(int client, int exemptNade = 0)
PrintToChat(i, "%T", "LiveNadeSomewhere", i, MESSAGE_PREFIX);
}
}

return;
}
}
}
else if (hTimer_MolotovThreatEnd != null)
{
for (int i = 0; i <= MaxClients; i++)
Expand All @@ -181,40 +170,40 @@ void AttemptInstantDefuse(int client, int exemptNade = 0)
PrintToChat(i, "%T", "MolotovTooClose", i, MESSAGE_PREFIX);
}
}

return;
}

if (!OnInstandDefusePre(client, c4))
{
return;
}

for (int i = 0; i <= MaxClients; i++)
{
if (IsValidClient(i))
{
PrintToChat(i, "%T", "InstaDefuseSuccessful", i, MESSAGE_PREFIX, c4TimeLeft);
}
}

g_bAlreadyComplete = true;

EndRound(CS_TEAM_CT);

OnInstantDefusePost(client, c4);
}

public Action Event_AttemptInstantDefuse(Handle event, const char[] name, bool dontBroadcast)
{
int defuser = GetDefusingPlayer();

int ent = 0;

if (StrContains(name, "detonate") != -1 && defuser != 0)
{
ent = GetEventInt(event, "entityid");

AttemptInstantDefuse(defuser, ent);
}
}
Expand All @@ -225,36 +214,36 @@ public Action Event_MolotovDetonate(Handle event, const char[] name, bool dontBr
Origin[0] = GetEventFloat(event, "x");
Origin[1] = GetEventFloat(event, "y");
Origin[2] = GetEventFloat(event, "z");

int c4 = FindEntityByClassname(MaxClients + 1, "planted_c4");

if (c4 == -1)
{
return;
}

float C4Origin[3];
GetEntPropVector(c4, Prop_Data, "m_vecOrigin", C4Origin);

if (GetVectorDistance(Origin, C4Origin, false) > 150)
{
return;
}

if (hTimer_MolotovThreatEnd != null)
{
delete hTimer_MolotovThreatEnd;
}

hTimer_MolotovThreatEnd = CreateTimer(GetConVarFloat(hInfernoDuration), Timer_MolotovThreatEnd, _, TIMER_FLAG_NO_MAPCHANGE);
}

public Action Timer_MolotovThreatEnd(Handle timer)
{
hTimer_MolotovThreatEnd = null;

int defuser = GetDefusingPlayer();

if (defuser != 0)
{
AttemptInstantDefuse(defuser);
Expand All @@ -264,10 +253,10 @@ public Action Timer_MolotovThreatEnd(Handle timer)
void OnInstantDefusePost(int client, int c4)
{
Call_StartForward(fw_OnInstantDefusePost);

Call_PushCell(client);
Call_PushCell(c4);

Call_Finish();
}

Expand All @@ -276,21 +265,21 @@ void EndRound(int team, bool waitFrame = true)
if (waitFrame)
{
RequestFrame(Frame_EndRound, team);

return;
}

Frame_EndRound(team);
}

void Frame_EndRound(int team)
{
int RoundEndEntity = CreateEntityByName("game_round_end");

DispatchSpawn(RoundEndEntity);

SetVariantFloat(1.0);

if (team == CS_TEAM_CT)
{
AcceptEntityInput(RoundEndEntity, "EndRound_CounterTerroristsWin");
Expand All @@ -299,17 +288,10 @@ void Frame_EndRound(int team)
{
AcceptEntityInput(RoundEndEntity, "EndRound_TerroristsWin");
}

AcceptEntityInput(RoundEndEntity, "Kill");
}

void ForceEnd()
{
int gameEndEntity = CreateEntityByName("game_end");

AcceptEntityInput(gameEndEntity, "EndGame");
}

stock int GetDefusingPlayer()
{
for (int i = 1; i <= MaxClients; i++)
Expand All @@ -319,19 +301,19 @@ stock int GetDefusingPlayer()
return i;
}
}

return 0;
}

stock bool OnInstandDefusePre(int client, int c4)
{
Action response;

Call_StartForward(fw_OnInstantDefusePre);
Call_PushCell(client);
Call_PushCell(c4);
Call_Finish(response);

return !(response != Plugin_Continue && response != Plugin_Changed);
}

Expand All @@ -350,7 +332,7 @@ stock bool HasAlivePlayer(int team)
return true;
}
}

return false;
}

Expand Down

0 comments on commit 1b1a20c

Please sign in to comment.