Raised This Month: $32 Target: $400
 8% 

Solved InstaDefuse Code Issues


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SytekBox
AlliedModders Donor
Join Date: Feb 2017
Location: 404 not found
Old 09-18-2020 , 11:18   InstaDefuse Code Issues
Reply With Quote #1

I currently run a Retake server and i've been trying to solve an issue with the InstaDefuse plugin from Jacoblairm where the Molotov/Grenade detection is triggered even though no grenade is nearby (It might be a bit closer but nowhere near the bomb).

As it's detecting the nade somewhere, it's giving players a false positive and it will void the instant defuse, was wondering if anybody was able to help removing the Molotov/Grenade Detection as i'm not actually worried about people defusing quick over a molly (Just want the round to end quick).

Code:
#include <sdktools>
#include <cstrike>

new Float:g_c4PlantTime;
new bool:g_DefuseFlag;
new Float:g_activeIncendiary;
new Float:g_bombPosition[3];

public Plugin:myinfo =
{
	name = "Insta-Defuse",
	description = "Plugin to instantly defuse the bomb when no T's are alive and other circumstances",
	author = "Jacoblairm",
	version = "1.2",
	url = "http://steamcommunity.com/id/Jacoblairm"
};


public OnPluginStart()
{
	CreateConVar("sm_instadefuse_enabled", "1", "Whether the plugin is enabled", 0, false, 0.0, false, 0.0);
	HookEvent("bomb_begindefuse", Event_BeginDefuse);
	HookEvent("bomb_planted", Event_BombPlanted);
	HookEvent("round_start", Event_RoundStart);
	HookEvent("molotov_detonate", molotov_explode);
	g_c4PlantTime = -1.0;
	g_activeIncendiary = -1.0;

}


public Action:Event_BeginDefuse(Handle:event, String:name[], bool:dontBroadcast)
{

	new Float:remaining = GetConVarFloat(FindConVar("mp_c4timer")) - (GetGameTime() - g_c4PlantTime);
	new iCount;
	new i = 1;
	while (i <= MaxClients)
	{
		if (IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) == 2)
		{
			iCount++;
		}
		i++;
	}

	if((GetGameTime()-g_activeIncendiary)<7.0)
	{
		PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Active molotov present, Good luck defusing!", "Insta-Defuse");
	}
	
	if (GetConVarInt(FindConVar("sm_instadefuse_enabled")) == 1 && iCount < 1 && g_DefuseFlag && ((GetGameTime()-g_activeIncendiary)>=7.0))
	{

		if (remaining > 10.0 || (remaining > 5.0 && GetEventBool(event, "haskit", false)))
		{

			new userid = GetEventInt(event, "userid");
			CreateTimer(0.0, timer_delay, userid);
			PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 CT's defused the bomb in time! \x0F%.1fs\x01 remaining.", "Insta-Defuse", remaining);
			g_DefuseFlag = false;
		}

		if (remaining < 5.0 || (remaining < 10.0 && !GetEventBool(event, "haskit", false)))
		{

			CS_TerminateRound(1.5, CSRoundEndReason:8, false);
			PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 CT's didn't defuse in time! \x0F%.1fs\x01 remaining.", "Insta-Defuse", remaining);
			g_DefuseFlag = false;
		}
	}
	return Action:0;
}

public Action:Event_BombPlanted(Handle:event, String:name[], bool:dontBroadcast)
{
	g_c4PlantTime = GetGameTime();
	new ent = -1;
	while ((ent = FindEntityByClassname(ent, "planted_c4")) != -1)
	{
		GetEntPropVector(ent, Prop_Send, "m_vecOrigin", g_bombPosition);
	}
	
	return Action:0;
}

public Action:Event_RoundStart(Handle:event, String:name[], bool:dontBroadcast)
{
	g_c4PlantTime = -1.0;
	g_DefuseFlag = true;
	g_activeIncendiary = 0.0;
	return Action:0;
}

public Action:timer_delay(Handle:timer, any:userid)
{
	new client = GetClientOfUserId(userid);

	if(client != 0)
	{
		if(IsPlayerAlive(client))
		{
			new c4 = FindEntityByClassname(MaxClients+1, "planted_c4");
			if(c4 != -1)
			{
				SetEntPropFloat(c4, Prop_Send, "m_flDefuseCountDown", 0);
				SetEntProp(client, Prop_Send, "m_iProgressBarDuration", 0);
			}
		}
	}
}


public molotov_explode(Handle:event, const String:name[], bool:dontBroadcast)
{
	new userid = GetEventInt(event, "userid");
	new client = GetClientOfUserId(userid);
	if(GetClientTeam(client) == 2)
	{
		new Float:f_Pos[3];
		f_Pos[0] = GetEventFloat(event, "x");
		f_Pos[1] = GetEventFloat(event, "y");
		f_Pos[2] = GetEventFloat(event, "z");

		if((FloatAbs(g_bombPosition[0])-FloatAbs(f_Pos[0]) < 170 ) && (FloatAbs(g_bombPosition[1])-FloatAbs(f_Pos[1]) < 170 ) && (FloatAbs(g_bombPosition[2])-FloatAbs(f_Pos[2]) < 170 ) )
		{
			g_activeIncendiary = GetGameTime();
		}
	}
}
I will be forever grateful if anybody can help me with removing that specific check (No Molotov/Grenade check).

Last edited by SytekBox; 09-21-2020 at 19:39.
SytekBox is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-18-2020 , 15:03   Re: InstaDefuse Code Issues
Reply With Quote #2

To disable molotov detection, try comment this line with double slash:
Code:
//HookEvent("molotov_detonate", molotov_explode);
Bacardi is offline
SytekBox
AlliedModders Donor
Join Date: Feb 2017
Location: 404 not found
Old 09-20-2020 , 09:46   Re: InstaDefuse Code Issues
Reply With Quote #3

Quote:
Originally Posted by Bacardi View Post
To disable molotov detection, try comment this line with double slash:
Code:
//HookEvent("molotov_detonate", molotov_explode);
Thanks Bacardi, i'll give that a try
SytekBox is offline
SytekBox
AlliedModders Donor
Join Date: Feb 2017
Location: 404 not found
Old 09-20-2020 , 17:02   Re: InstaDefuse Code Issues
Reply With Quote #4

Quote:
Originally Posted by SytekBox View Post
Thanks Bacardi, i'll give that a try
Gave that a try but still getting the check triggered and the round doesn't end right away (Same behavior as before)
SytekBox is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-21-2020 , 05:23   Re: InstaDefuse Code Issues
Reply With Quote #5

Not sure why not work...

So I script cheap one:

*UPDATE
PHP Code:
/*

Server event "bomb_begindefuse", Tick 14022:
- "userid" = "2"
- "haskit" = "1"


m_flTimerLength 99.000000
m_flDefuseLength 5.000000
m_flDefuseCountDown 586.031250


m_iProgressBarDuration -1
m_flProgressBarStartTime 1598.687500
*/

enum
{
    
unassign,
    
spectators,
    
terrorists,
    
counter_terrorists
}

ConVar sm_instadefuse_enabled;

#include <sdktools>

public void OnPluginStart()
{
    
sm_instadefuse_enabled CreateConVar("sm_instadefuse_enabled""1"__true0.0true1.0);
    
HookEvent("bomb_begindefuse"bomb_begindefuse);
}

public 
void bomb_begindefuse(Event eventchar[] namebool dontBroadcast)
{
    if(!
GetConVarBool(sm_instadefuse_enabled)) return;

    
bool IsTerroristAlive false;

    for(
int i 1<= MaxClientsi++)
    {
        
// Not in game, not in team terrorists, not alive -> skip
        
if(!IsClientInGame(i) || GetClientTeam(i) != terrorists || !IsPlayerAlive(i)) continue;

        
// there is terrorist alive, break loop
        
IsTerroristAlive true;
        break;
    }

    
// stop code
    
if(IsTerroristAlive) return;



    
int c4 = -1;

    
// ...when there are more tha one planted_c4
    
while( (c4 FindEntityByClassname(c4"planted_c4")) != -)
    {
        
// skip defused c4
        
if(GetEntProp(c4Prop_Send"m_bBombDefused")) continue;

        
// Need some delay to get updated data from planted_c4
        
CreateTimer(0.3delayEntIndexToEntRef(c4));
    }
}

public 
Action delay(Handle timerint ref)
{
    
int c4 EntRefToEntIndex(ref);
    
int client GetEntPropEnt(c4Prop_Send"m_hBombDefuser");

    
// planted_c4 doesn't exist anymore or we couldn't get client index
    
if(c4 == -|| client == -1) return;

    
float m_flC4Blow GetEntPropFloat(c4Prop_Send"m_flC4Blow");
    
float m_flDefuseCountDown GetEntPropFloat(c4Prop_Send"m_flDefuseCountDown");
    
    
float result m_flC4Blow m_flDefuseCountDown;

    if(
result 0.0)
    {
        
PrintToChatAll(" \x09[Insta-Defuse]\x01 CT's didn't defuse in time! %.2fs remaining."result);
        
SetEntPropFloat(c4Prop_Send"m_flC4Blow"GetGameTime());
        return;
    }
    
    
PrintToChatAll(" \x09[Insta-Defuse]\x01 CT's defused the bomb in time! %.2fs remaining."result);
    
SetEntPropFloat(c4Prop_Send"m_flDefuseCountDown"GetGameTime());

- When terrorists are dead
- When there is time to defuse
= insta-defuse

- No terrorists alive
- No time to defuse
= insta-blow
__________________
Do not Private Message @me

Last edited by Bacardi; 09-21-2020 at 14:41. Reason: update
Bacardi is offline
SytekBox
AlliedModders Donor
Join Date: Feb 2017
Location: 404 not found
Old 09-21-2020 , 10:48   Re: InstaDefuse Code Issues
Reply With Quote #6

Quote:
Originally Posted by Bacardi View Post
Not sure why not work...

So I script cheap one:
PHP Code:
/*

Server event "bomb_begindefuse", Tick 14022:
- "userid" = "2"
- "haskit" = "1"


m_flTimerLength 99.000000
m_flDefuseLength 5.000000
m_flDefuseCountDown 586.031250


m_iProgressBarDuration -1
m_flProgressBarStartTime 1598.687500
*/

ConVar sm_instadefuse_enabled;

#include <sdktools>

public void OnPluginStart()
{
    
sm_instadefuse_enabled CreateConVar("sm_instadefuse_enabled""1"__true0.0true1.0);
    
HookEvent("bomb_begindefuse"bomb_begindefuse);
}

public 
void bomb_begindefuse(Event eventchar[] namebool dontBroadcast)
{
    if(!
GetConVarBool(sm_instadefuse_enabled)) return;

    
int c4 FindEntityByClassname(-1"planted_c4");

    if(
c4 == -1) return;

    
RequestFrame(frameEntIndexToEntRef(c4));
}

public 
void frame(int ref)
{
    
int c4 EntRefToEntIndex(ref);

    if(
c4 == -1) return;

    
SetEntPropFloat(c4Prop_Send"m_flDefuseCountDown"GetGameTime());

- Works 100% on maps where is only one c4 planted.
As soon as i get back at home from work i'll give this a try, would it be possible to retain the messages feature? Still want to get some sort of visual-chat alert (No need for the time left, just a Could or Couldn't defuse in time basic message).

Sorry to ask for this much spoon-feeding, not usually my go to thing but this is certainly out of my knowledge zone (Working on learning programming myself nonetheless, though i'm just a Junior Front-End Designer at the moment) i_i

Your help and time has been greatly appreciated so far! <3
SytekBox is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-21-2020 , 11:27   Re: InstaDefuse Code Issues
Reply With Quote #7

...ok. I was very lazy when I did that code.
I started now actually read, what that plugin suppose to do. I need rewrite.

- Seem only insta-defuse when terrorists are dead and there is time to defuse till end.

*edit
Updated my previous code

Last edited by Bacardi; 09-21-2020 at 12:01.
Bacardi is offline
SytekBox
AlliedModders Donor
Join Date: Feb 2017
Location: 404 not found
Old 09-21-2020 , 19:39   Re: InstaDefuse Code Issues
Reply With Quote #8

Quote:
Originally Posted by Bacardi View Post
...ok. I was very lazy when I did that code.
I started now actually read, what that plugin suppose to do. I need rewrite.

- Seem only insta-defuse when terrorists are dead and there is time to defuse till end.

*edit
Updated my previous code
Much appreciated! Seems to be working properly now <3
SytekBox is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:49.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode