hebusletroll |
08-27-2007 07:52 |
Time To Defuse
3 Attachment(s)
Hello friends !
This is my first AmxModX contribution and I hope that you will like it :D
This plugin allow administrator to set bomb defusing time. Required by many players.
There is 3 modes, that you can configure with amx_defusemode :
1 = The bomb will be immedialty defused, either you have a defuser or not.
2 = The bomb will be immedialty defused if you have a defuser, else the plugin use amx_defusetime * amx_defusefactor time (by default 5.0 * 2.0)
3 = The bomb will be defused in amx_defusetime time if you have a defuser. Else needed time is amx_defusetime * amx_defusefactor.
Tested on CS1.6 and CZ. On Windows plateforme. I know that the linux offset is not the same but i don't have any computer running on it.
Please add me in your credits if you use this code for your plugins ;o)
Have fun !
Code:
/**************************************************************************************************/
/* Time To Defuse by Hebusletroll - 30 August 2007 */
/* [email protected] */
/* */
/* This plugin allow to change the default defuse time . */
/* You can use this code to enhance your own plugin, like "Cut the right wire", just think to add */
/* me in your credits :o) */
/* */
/* CVARS : */
/* amx_defusemode <0|1|2|3> : set plugin mode, stopped by default. */
/* 0 = Disabled (default). */
/* 1 = Instant defuse, defuser not required. */
/* 2 = Instant defuse, defuser required, if you don't have a defuser, plugin use */
/* amx_defusetime * amx_defusefactor. */
/* 3 = Timed defuse, using amx_defusetime if you have a defuser, using asv_defusetime*/
/* * sv_defusefactor without it. */
/* sv_defusetime <time in seconds> : set time required to defuse the bomb. */
/* */
/* sv_defusefactor <factor> : set time factor when player is defusing without */
/* defuser. */
/* */
/* Changes : 0.1 (27 August 2007) => First release. */
/* 0.2 (30 August 2007) => Added setting time required to defuse. */
/* => Added setting time factor. */
/* 0.3 (18 September 2007) => Engine requirement removed. */
/* => Using pcvar instead native cvar. */
/* => Removing useless code. */
/* => Added Linux support. */
/* */
/* Important : You cannot set a defuse time more greater than the mp_c4timer cvar. The plugin */
/* scale the time automatically. */
/**************************************************************************************************/
/* */
/* THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN */
/* OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM */
/* "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED */
/* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE */
/* RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE */
/* DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. */
/* */
/**************************************************************************************************/
#include <amxmodx>
#include <fakemeta>
#define AMXX_PLUGIN_NAME "Time To Defuse"
#define AMXX_PLUGIN_AUTHOR "Hebusletroll"
#define AMXX_PLUGIN_VERSION "0.3"
#define WIN32_C4_INSTANTDEFUSE 1.0
#define MODEL_C4 "models/w_c4.mdl"
#define CMD_DEFUSERNOTREQUIRED 1
#define CMD_DEFUSERREQUIRED 2
#define CMD_DEFUSERTIMED 3
new game_progressbar,
sv_defusemode, sv_defusetime, sv_defusefactor, Float:sv_c4timer,
defuseoffset
new bool:defusing
// Here the first called function, registering needed event for the plugin.
public plugin_init()
{
register_plugin(AMXX_PLUGIN_NAME,
AMXX_PLUGIN_AUTHOR,
AMXX_PLUGIN_VERSION)
defuseoffset=is_linux_server()?103:99
//I register this message to prevent bar progress displaying with instant defusing.
game_progressbar = get_user_msgid("BarTime")
//Ok theses event are register and provide easy defuser detection.
register_logevent("on_beginwithoutdefuser", 3, "2=Begin_Bomb_Defuse_Without_Kit")
register_logevent("on_beginwithdefuser", 3, "2=Begin_Bomb_Defuse_With_Kit")
register_logevent("on_roundstart", 2, "1=Round_Start")
//The plugin cvar, plugin disabled by default.
sv_defusemode = register_cvar("sv_defusemode","0",FCVAR_SERVER|FCVAR_ARCHIVE)
sv_defusetime = register_cvar("sv_defusetime","5.0",FCVAR_SERVER|FCVAR_ARCHIVE)
sv_defusefactor = register_cvar("sv_defusefactor","2.0",FCVAR_SERVER|FCVAR_ARCHIVE)
//A client command to get defuse configuration.
register_clcmd("say /defusemode","on_inforequested",0,"Display current defuse mode configuration")
//Forwarding the client prethink.
register_forward(FM_PlayerPreThink,"on_clientprethink",1)
}
//Handled function when player defusing bomb without defuser.
//Can only work if defuser is not required.
public on_beginwithoutdefuser()
defuse(read_data(0),false)
//Handled function when player defusing bomb with defuser.
public on_beginwithdefuser()
defuse(read_data(0),true)
// Setting up c4timer in memory
public on_roundstart()
sv_c4timer=float(get_cvar_num("mp_c4timer"))
//Setting up the bomb for defusing.
stock defuse(id,bool:defuser)
{
//If plugin is disabled, then exiting.
if(!get_pcvar_num(sv_defusemode))
return PLUGIN_CONTINUE
//Searching C4 entity by model.
new c4entity = get_c4entity()
if(c4entity)
{
if(get_pcvar_float(sv_defusefactor)<1.0)
set_pcvar_float(sv_defusefactor,1.0)
if(get_pcvar_float(sv_defusetime)<1.0)
set_pcvar_float(sv_defusetime,1.0)
//Set ennemy that defuse the bomb.
set_pev(c4entity,pev_enemy,id)
set_pev(c4entity,pev_iuser1,defuser)
defusing=true
}
return PLUGIN_CONTINUE
}
//Display current Time To Defuse configuration to all connected players.
public on_inforequested()
{
if(!get_pcvar_num(sv_defusemode))
return PLUGIN_CONTINUE
new message[255]
switch(get_pcvar_num(sv_defusemode))
{
case CMD_DEFUSERNOTREQUIRED:format(message,255,"Instant defusing either you have defuser or not.")
case CMD_DEFUSERREQUIRED:
{
new Float:defusetime = get_pcvar_float(sv_defusetime)*get_pcvar_float(sv_defusefactor)
defusetime = defusetime>sv_c4timer?sv_c4timer:defusetime
format(message,255,"Instant defusing if you have defuser, else %d seconds are needed without it.",floatround(defusetime))
}
case CMD_DEFUSERTIMED:
{
new Float:defusetimewithoutdefuser = (get_pcvar_float(sv_defusetime)*get_pcvar_float(sv_defusefactor))>sv_c4timer?sv_c4timer:get_pcvar_float(sv_defusetime)*get_pcvar_float(sv_defusefactor)
new Float:defusetimewithdefuser = get_pcvar_float(sv_defusetime)>sv_c4timer?sv_c4timer:get_pcvar_float(sv_defusetime)
format(message,255,"Time to defuse bomb with defuser take %d seconds, else %d seconds are needed without it.",floatround(defusetimewithdefuser),floatround(defusetimewithoutdefuser))
}
}
client_print(0,print_chat,"Time To Defuse : %s",message)
return PLUGIN_CONTINUE
}
//Player action : please note that this function is mandatory because set_pdata_float is not
//trigged in defuse function, must be processed in client action.
public on_clientprethink(id)
{
if(!get_pcvar_num(sv_defusemode))
return FMRES_IGNORED
//Defusing the bomb OH YEAH !
if(defusing)
{
//Getting bomb entity
new c4entity = get_c4entity()
if(c4entity)
if(pev(c4entity,pev_enemy)==id)
{
//Ok now processing bomb defusing.
defusing = false
new Float:hacktime,Float:hltime = get_gametime()
switch(get_pcvar_num(sv_defusemode))
{
case CMD_DEFUSERNOTREQUIRED:hacktime=WIN32_C4_INSTANTDEFUSE
case CMD_DEFUSERREQUIRED:hacktime=(pev(c4entity,pev_iuser1)?WIN32_C4_INSTANTDEFUSE:hltime+get_pcvar_float(sv_defusetime)*get_pcvar_float(sv_defusefactor))
case CMD_DEFUSERTIMED:hacktime=(pev(c4entity,pev_iuser1)?hltime+get_pcvar_float(sv_defusetime):hltime+get_pcvar_float(sv_defusetime)*get_pcvar_float(sv_defusefactor))
}
if(hacktime)
{
new defusetime = floatround(hacktime!=WIN32_C4_INSTANTDEFUSE?(hacktime-hltime>=sv_c4timer?sv_c4timer:hacktime-hltime):0.0)
//Displaying new progress bar
message_begin(MSG_ONE,game_progressbar,{0,0,0},id)
write_byte(defusetime)
write_byte(0)
message_end()
//Setting up required bomb time for defusing.
set_pdata_float(c4entity,defuseoffset,hltime+float(defusetime))
}
}
}
return FMRES_IGNORED
}
//Searching the bomb entity.
stock get_c4entity()
return engfunc(EngFunc_FindEntityByString, -1, "model", MODEL_C4)
|