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

C4 Explode Chance without Defuse Kit


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ark_Procession
Senior Member
Join Date: Jun 2020
Location: Argentina
Old 11-26-2022 , 12:52   C4 Explode Chance without Defuse Kit
Reply With Quote #1

Hi, i am using this plugin.

It makes c4 explode if you defuse without kit, with a configurable chance of happening.

It doesnt feel the 50% chance i gave it is working, since this rarely happens when someone try to defuse without kit.

Can someone check if it works correctly?
Can it be optimized somehow, and keep in mind bots from zero?

Edit: tested with 100% chance, still not happening.

HTML Code:
/* Plugin generated by AMXX-Studio */

// Defuse Mistake 1.4 for Counter-strike and Condition Zero by Redshift187
//
// This is my first plugin.  I would like to thank VEN for the code on when the bomb defusing was
// cancelled and how to properly trigger the explosion, Hebusletroll for snippets I borrowed from
// Time To Defuse, SweatyBanana for snippets I borrowed from Random Bomb Timer, The Specialist for
// snippets I borrowed from Cut The Right Wire and Cheap Suit for snippets I borrowed from C4 Timer.
//
// Feel free to use any of this code in your own plugin, as long as you mention me.
// If you have any questions about what any of it does, feel free to ask (I'll do my best).
//
// The idea behind this plugin is that persons trying to defuse without a kit might make a mistake
// and detonate the bomb early.
//
// This plugin will pick a random number between 1 and dfmis_odds X 8.  This will give a possibility
// of dfmis_odds percent chance that the number is less than the time to defuse without a kit.  If
// you are defusing without a kit, the bomb will explode the random number of seconds into the
// defuse.  If you stop and restart the defuse, the random number is chosen again (just to make you
// second guess yourself! <evil grin>).
//
// Use:
//
//	dfmis_odds (1 - 100)	- default 10, sets the odds that the bomb will detonate during defuse
//				  set to 0 to disable
//
// Changelog:
//	1.4	Odds calculation mistake... it was always 100%.
//	1.3	Fixed odds calculation.  Now it really is percent chance.
//		Removed engine in favour of fakemeta.
//	1.2	Removed the chance that the mistake will happen within 1 second of defusing.
//		Sometimes the explosion would happen immediately after defusing.
//	1.1	Updates suggested by Emp`
//


#include <amxmodx>
#include <fakemeta>


#define PLUGIN "Defuse Mistake"
#define VERSION "1.4"
#define AUTHOR "Redshift187"


#define TASK_ID         86
#define TASK_ID2        69
#define NO_KIT_TIME      9
#define CHANCE         100
#define MAX_NAME_LENGTH 31


new g_pRisk


// Initialize plugin
public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	// Get the odds CVAR
	g_pRisk = register_cvar("dfmis_odds", "10")

	// Check if the map has a bombsite entity in it
	if(engfunc(EngFunc_FindEntityByString, -1, "classname", "func_bomb_target") > 0)
	{
		register_logevent("bomb_defuse_no_kit", 3, "2=Begin_Bomb_Defuse_Without_Kit")
		register_event("BarTime", "bomb_defuse_cancelled", "b", "1=0")
		register_logevent("normal_detonation", 6, "3=Target_Bombed")
	}

	return PLUGIN_CONTINUE
}

// Stopped defusing
public bomb_defuse_cancelled()
{
	// Cancel the task (timer)
	remove_task(TASK_ID)

	return PLUGIN_CONTINUE
}

public normal_detonation()
{
	// Cancel the task (timer)
	remove_task(TASK_ID)

	return PLUGIN_CONTINUE
}

// Defusing without a kit
public bomb_defuse_no_kit()
{
	new id = get_loguser_index()
	new risk = get_pcvar_num(g_pRisk)

	// Check risk
	if (risk >= 1)
	{
		// Convert dfmis_odds to a percent
		new percent = CHANCE / min(risk, CHANCE) * NO_KIT_TIME

		// Get a random number between 1 and dfmis_odds
		new mistake = random_num(1, percent)

		// Check that the random time was less than it will take to defuse
		if (mistake <= (NO_KIT_TIME))
		{
			new g_args[1]

			g_args[0] = id

			// Set a task (timer) for the random number of seconds
			set_task(float(mistake), "bomb_explosion", TASK_ID, g_args, 1)
		}
	}

	return PLUGIN_CONTINUE
}

// detonate C4
public bomb_explosion(args[])
{
	new bombent = engfunc(EngFunc_FindEntityByString, -1, "model", "models/w_c4.mdl")

	set_pdata_float(bombent, 100, get_gametime());
	set_task(3.0, "display_msg", TASK_ID2, args, 1)

	return PLUGIN_CONTINUE
}

public display_msg(args[])
{
	new message[128]
	new def_name[MAX_NAME_LENGTH + 1]

	get_user_name(args[0], def_name, MAX_NAME_LENGTH)
	formatex(message, 127, "Looks like %s cut the wrong wire", def_name)
	set_hudmessage(255, 100, 0, -1.0, 0.40, 0, 6.0, 24.0, 0.1, 0.2, 0)
	show_dhudmessage(0, message)
	
	return PLUGIN_CONTINUE
}

// function to get user index from log events
public get_loguser_index() 
{
	new loguser[80], name[32]

	read_logargv(0, loguser, 79)
	parse_loguser(loguser, name, 31)

	return get_user_index(name)
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
*/

Last edited by Ark_Procession; 11-26-2022 at 13:02. Reason: obligatory edit
Ark_Procession is offline
Stefanos
Senior Member
Join Date: May 2020
Old 11-26-2022 , 22:20   Re: C4 Explode Chance without Defuse Kit
Reply With Quote #2

dfmis_odds (1 - 100) - default 10, sets the odds that the bomb will detonate during defuse


g_pRisk = register_cvar("dfmis_odds", "10")

Its 10%?
Stefanos is offline
Ark_Procession
Senior Member
Join Date: Jun 2020
Location: Argentina
Old 11-26-2022 , 23:45   Re: C4 Explode Chance without Defuse Kit
Reply With Quote #3

Quote:
Originally Posted by Stefanos View Post
dfmis_odds (1 - 100) - default 10, sets the odds that the bomb will detonate during defuse


g_pRisk = register_cvar("dfmis_odds", "10")

Its 10%?
Hey! thanks for helping.

Yeah that would be the default.
It seems to work with 10 no matter what i change the cvar.
As my initial post said but better explained, 50% and 100% feels like 10%, like it makes no difference whatsoever
Ark_Procession is offline
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 11-27-2022 , 03:16   Re: C4 Explode Chance without Defuse Kit
Reply With Quote #4

Code:
// Convert dfmis_odds to a percent new percent = CHANCE / min(risk, CHANCE) * NO_KIT_TIME // Get a random number between 1 and dfmis_odds
new mistake = random_num(1, percent)
Although setting it to 100% ensures that it will fail to disarm.
This occurs randomly in the gauge.
__________________
GitHub
SteamWishlist

六四天安門事件
+ARUKARI- is offline
Ark_Procession
Senior Member
Join Date: Jun 2020
Location: Argentina
Old 11-27-2022 , 12:56   Re: C4 Explode Chance without Defuse Kit
Reply With Quote #5

Quote:
Originally Posted by +ARUKARI- View Post
Code:
// Convert dfmis_odds to a percent new percent = CHANCE / min(risk, CHANCE) * NO_KIT_TIME // Get a random number between 1 and dfmis_odds
new mistake = random_num(1, percent)
Although setting it to 100% ensures that it will fail to disarm.
This occurs randomly in the gauge.
I see, thanks ARUKARI, you are the best thanks again for the revival plugin btw
If you or anyone can somehow try to fix this plugin... let me know.


Ark_Procession is offline
Reply


Thread Tools
Display Modes

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 16:10.


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