AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
|
06-16-2014
, 12:48
Re: Bomb Status
|
#38
|
Quote:
Originally Posted by EthicalHacker007
Tested this plugin. There's a bug / suggestion.
After I planted the c4 and after it's successful explosion. Planter: EH007 changed to Carrier: EH007. I think you should add this one
Code:
Status: Dropped/Carried/Bombed
I also found out a bug. Take 2 players. A and B. A has spawned with c4 on first round, now round starts after few seconds (5-7) I enter this cvar sv_restart 1 and game restarts. Now bomb carrier is B but still it shows A. Understood? When you restart the game the plugin doesn't update the info. Rest is fine.
Regards,
EH007
|
Thanks for testing, now I'm going to fix this.
PHP Code:
/*Copyleft 2014
Plugin thread: https://forums.alliedmods.net/showthread.php?t=241320
Bomb Status
========
Description: Shows a hud message with the following information about the bomb:
Bomb Planted : Yes/No
BombSite : A/B/No
Status : Dropped/Carried
Carrier/Planter : Name/ No ( if the bomb was planted will show Planter: Name )
Distance To Bomb: Distance/No
Let's explain better:
BombPlanted: if the bomb is planted, it will show Yes, otherwise it will show NO.
BombSites: if the bomb is not planted will show No, otherwise it will show A / B.
Status: will show Dropped if the bomb is on the ground, Carried if a player has the bomb.
Carrier: if the bomb is not on the ground will show the name of the player who has it, otherwise will show No. In the case which the bomb is planted , will shows the name of player who planted it.
Distance To Bomb: if planted will display the distance, else will show NO.
Changelog:
V 0.1:
+ Initial Release.
V 0.2:
+ Add two versions: dhud / HUD classic.
+ Fix bug when name was displayed incorrectly.
V 0.3:
+ Add cvar bomb_status_team (which them see the hud)
+ Optimization for detecting the distance to the bomb site.
V 0.4:
+ Now there is only one version with HUD and dhud.
+ Adding cvar bomb_hud_type
+ Big optimization for checking the distance between the bomb and the bomb site
+ Arrange the code
V 0.5:
+ Lowered the hold time for hud messages
+ Now HudSyncObjects are cached
+ Added is_user_connected check in GetName function
V 0.6:
+ Renamed almost all variables.
+ Now the plugin will be paused if we aren't running a map with bomb sites.
+ Removed some useless blocks of code.
+ Solved some problems with arrays.
+ Added a global task.
+ Fixed some problems in formatex.
+ Lowered the hold time for hud.
+ Increased the task time ( now it's 1.0 ).
+ Removed an useless var in GetName stock.
+ Fixed a bug when bomb status is displayed incorrectly.
V 0.7:
+ Removed dhudmessages, now only normal hud messages are used.
+ Remove hud type cvar.
+ Optimized show hud function
V 0.8:
+ Added posibility to change hud color by cvar.
+ Added /hudon & /hudoff for turning hud on/off.
+ Added a spam protection for commands.
+ Added a new swapped map: de_train.
+ Added a new file where you can write on which map plugin should not run.
+ Moved all files in Bomb Status folder.
+ Added a cvar to enable/ disable commands
+ Added logs.
+ Added a cvar to control logs ( default 0 )
+ Optimized a bit ShowHud function.
*/
#include < amxmodx >
#include < amxmisc >
#include < fakemeta >
#include < engine >
#include < csx >
#include < cstrike >
#define SPAM_TIME 10.0
new bool: g_bMapHasBombSites, bool: g_bIsMapSwapped, bool: g_bBombPlanted, bool: g_bHudOn [ 33 ], bool: g_bBlocked [ 33 ],
bool: g_bCommandsOn , bool: g_bBombExploded
new g_iBombSites [ 2 ], g_iValue = 0, g_iStatus ,szName[ 33 ] , g_iTeam , g_HudSync, g_iFile [ 2 ] [ 128 ],
szPath [ 128 ], g_HudColor [ 3 ], g_iColor [ 3 ] , g_iCommandsStatus , g_iLogsStatus
new const g_szFileNames [ ] [ ] = {
"swapped_maps.ini",
"blocked_maps.ini"
}
new const g_szFolderName [ ] = "Bomb Status";
new Float: g_fBombSitesOrigins [ 2 ] [ 3 ] , Float: g_fBombOrigins [ 3 ]
public plugin_init ( ) {
register_plugin ( "Bomb Status" , "0.8" , "HamletEagle" )
register_logevent("Logevent_BombDropped", 3, "2=Dropped_The_Bomb")
register_logevent("Logevent_BombCollected", 3, "2=Got_The_Bomb")
register_logevent("Logevent_SpawnedWithBomb", 3, "2=Spawned_With_The_Bomb")
register_logevent("Logevent_RoundEnd", 2, "1=Round_End")
register_event("HLTV", "event_new_round", "a", "1=0", "2=0")
g_iTeam = register_cvar ( "bomb_status_team" , "0" )
/*
0 - everyone can see the hud
1 - only t can see the hud
2 - only ct can see the hud
*/
/* Color for hud in rgb format */
g_HudColor [ 0 ] = register_cvar ( "hud_r_color" , "0" )
g_HudColor [ 1 ] = register_cvar ( "hud_g_color" , "255" )
g_HudColor [ 2 ] = register_cvar ( "hud_b_color" , "85" )
g_iCommandsStatus = register_cvar ( "bomb_status_commands", "1" )
/*
0 - deactivated
1- activated
*/
g_iLogsStatus = register_cvar ( "bomb_status_logs" , "0" )
/*
0 - no logs
1 - logs on
*/
g_HudSync = CreateHudSyncObj ( )
set_task( 1.0, "ShowHud", _ , _, _, "b" )
register_clcmd ( "say /hudon" , "CmdHudOn" )
register_clcmd ( "say /hudoff" , "CmdHudOff" )
}
public plugin_cfg ( ) {
new Dir[ 64 ];
get_configsdir ( Dir, sizeof ( Dir ) - 1 )
formatex ( szPath , sizeof ( szPath ) -1, "%s/%s", Dir, g_szFolderName );
for ( new i = 0 ; i < 2 ; i++ )
formatex ( g_iFile [ i ] , 127 , "%s/%s", szPath , g_szFileNames [ i ]);
if ( ! dir_exists ( szPath ) )
mkdir ( szPath )
if( ! file_exists( g_iFile [ 0 ] ) )
{
write_file( g_iFile [ 0 ], ";Here you will write the swapped maps." )
write_file( g_iFile [ 0 ], ";A map is swapped when it has inversed bomb site." )
write_file( g_iFile [ 0 ], ";If the plugin display incorectly the Bomb Site where the bomb is planted" )
write_file( g_iFile [ 0 ], ";add the map name here." )
write_file( g_iFile [ 0 ], "de_dust2" )
write_file( g_iFile [ 0 ], "de_chateau" )
write_file(g_iFile [ 0 ], "de_train" )
}
if ( ! file_exists ( g_iFile [ 1 ] ) )
{
write_file( g_iFile [ 1 ], ";Here you will write maps on which plugin is disabled" )
write_file( g_iFile [ 1 ], ";If you want to restrict pluin in de_dust2 you will here" )
write_file( g_iFile [ 1 ], ";de_dust2 ( without ; )" )
}
for ( new i = 0 ; i < 3 ; i ++ )
g_iColor [ i ] = get_pcvar_num ( g_HudColor [ i ] )
if ( get_pcvar_num ( g_iCommandsStatus ) ==1 )
g_bCommandsOn = true
LoadFile ( )
CheckAndFindBombSites ( )
}
public event_new_round ( ) {
for ( new i = 0 ; i < 3 ; i ++ )
g_iColor [ i ] = get_pcvar_num ( g_HudColor [ i ] )
if ( get_pcvar_num ( g_iCommandsStatus ) ==1 )
g_bCommandsOn = true
g_bBombExploded = false
}
public LoadFile ( ) {
new szMapName [ 33]
get_mapname ( szMapName, sizeof ( szMapName ) -1 )
new szData[ 128 ],szLine[ 32 ]
new iFile [ 2 ]
for ( new i ; i < 2 ; i ++ ) {
iFile [ i ] = fopen( g_iFile [ i ], "rt" );
if ( iFile [ i ] ) {
while( !feof( iFile [ i ] ) )
{
fgets( iFile [ i ] , szData, sizeof ( szData ) -1 )
if( !szData[ 0 ] || szData[ 0 ] == ';' || ( szData[ 0 ] == '/' && szData[ 1 ] == '/' ) )
continue
parse( szData, szLine, sizeof ( szLine ) -1 )
if( equal( szMapName, szLine ) ) {
if ( i == 0) {
g_bIsMapSwapped = true
if ( get_pcvar_num ( g_iLogsStatus ) == 1 )
log_amx ( "Detected a swapped map." )
}
else {
if ( get_pcvar_num ( g_iLogsStatus ) == 1 )
log_amx ( "Plugin is restricted on this map, stopped" )
pause ( "a" )
}
}
}
}
fclose ( iFile [ i ] )
}
}
public CheckAndFindBombSites ( ) {
if ( g_bIsMapSwapped ) {
g_iBombSites [ 1 ] = find_ent_by_class ( -1 , "func_bomb_target" )
g_iBombSites [ 0 ] = find_ent_by_class ( g_iBombSites [ 1 ] , "func_bomb_target" )
}
else {
g_iBombSites [ 0 ] = find_ent_by_class ( -1 , "func_bomb_target" )
g_iBombSites [ 1 ] = find_ent_by_class ( g_iBombSites [ 0 ] , "func_bomb_target" )
}
if ( pev_valid ( g_iBombSites [ 0 ] ) || pev_valid ( g_iBombSites [ 1 ] ) )
g_bMapHasBombSites = true
if ( ! g_bMapHasBombSites ) {
if ( get_pcvar_num ( g_iLogsStatus ) == 1 )
log_amx ( "No bomb sites, plugin paused" )
pause ( "a" )
}
if ( pev_valid ( g_iBombSites [ 0 ] ) )
get_brush_entity_origin ( g_iBombSites [ 0 ] , g_fBombSitesOrigins [ 0 ] )
if ( pev_valid ( g_iBombSites [ 1 ] ) )
get_brush_entity_origin ( g_iBombSites [ 1 ] , g_fBombSitesOrigins [ 1 ] )
}
public bomb_planted ( planter ) {
new Bomb = find_ent_by_model ( -1, "grenade", "models/w_c4.mdl" )
if ( pev_valid ( Bomb ) )
pev ( Bomb , pev_origin , g_fBombOrigins )
g_bBombPlanted = true
new Float:iDist [ 2 ]
for ( new i = 0 ; i < 2 ; i ++ )
iDist [ i ] = get_distance_f ( g_fBombOrigins , g_fBombSitesOrigins [ i ] )
if ( iDist [ 0 ] < iDist [ 1 ] )
g_iValue = 1
else
g_iValue = 2
get_user_name ( planter , szName, sizeof ( szName ) -1 )
g_iStatus = 1
}
public Logevent_BombDropped ( )
g_iStatus = 1
public Logevent_BombCollected ( ) {
set_task ( 0.1 ,"GetName" )
g_iStatus = 0
}
public Logevent_SpawnedWithBomb ( )
set_task ( 0.1 , "GetName" )
public ShowHud ( ) {
new Float:PlayerOrigins[3]
new HudMessage [ 128 ]
if ( ! g_bBombPlanted && ! g_bBombExploded ) {
if ( g_iStatus == 1 )
formatex ( HudMessage, sizeof ( HudMessage ) -1 , "Bomb Planted :No^nBombSite: No^nStatus:Dropped ^nCarrier:No^nDistante To Bomb: No" )
else
formatex ( HudMessage, sizeof ( HudMessage ) -1 , "Bomb Planted :No^nBombSite: No^nStatus:Carried^nCarrier:%s^nDistante To Bomb:No",szName)
}
if ( g_bBombExploded && ! g_bBombPlanted )
formatex ( HudMessage, sizeof ( HudMessage ) -1 , "Bomb Planted :No^nBombSite: No^nStatus:Bombed ^nCarrier:No^nDistante To Bomb: No" )
static iPlayers[ 32 ] , iPlayersNum, id, i
switch ( get_pcvar_num ( g_iTeam ) ) {
case 1: get_players( iPlayers, iPlayersNum, "ce", "TERRORIST" )
case 2: get_players( iPlayers, iPlayersNum, "ce", "CT" )
default: get_players( iPlayers,iPlayersNum, "c" )
}
if( !iPlayersNum )
return;
for( i = 0; i < iPlayersNum; i++ )
{
id = iPlayers[ i ];
if ( ! g_bHudOn [ id ] )
continue
if ( g_bBombPlanted ) {
pev(id, pev_origin, PlayerOrigins)
formatex ( HudMessage, sizeof ( HudMessage ) -1 , "Bomb Planted :Yes^nBombSite: %s^nStatus:Planted^nPlanter:%s^nDistante To Bomb: %i",g_iValue == 1 ? "A" :"B", szName, floatround ( get_distance_f (PlayerOrigins, g_fBombOrigins) / 100 ) )
}
set_hudmessage( g_iColor [ 0 ], g_iColor [ 1 ], g_iColor [ 2 ], 0.0, 0.15, 0, 6.0, 3.0)
ShowSyncHudMsg( id , g_HudSync , HudMessage)
}
}
public client_putinserver ( id )
g_bHudOn [ id ] = true
public CmdHudOn ( id ) {
if ( !g_bCommandsOn )
client_print ( id , print_chat , "[ AMXX ] This command is disabled" )
else if ( g_bBlocked [ id ] )
client_print ( id , print_chat , "[ AMXX ] You have to wait %.1f seconds to use this command again" , SPAM_TIME )
else if ( g_bHudOn [ id ] )
client_print ( id , print_chat , "[ AMXX ] Hud is already on" )
else {
g_bHudOn [ id ] = true
client_print ( id , print_chat , "[ AMXX ] You have just enabled your hud" )
g_bBlocked [ id ] = true
set_task ( SPAM_TIME , "RemoveBlock", id )
}
}
public CmdHudOff ( id ) {
if ( !g_bCommandsOn )
client_print ( id , print_chat , "[ AMXX ] This command is disabled" )
else if ( g_bBlocked [ id ] )
client_print ( id , print_chat , "[ AMXX ] You have to wait %.1f seconds to use this command again" , SPAM_TIME )
else if ( ! g_bHudOn [ id ] )
client_print ( id , print_chat , "[ AMXX ] Hud is already off" )
else {
g_bHudOn [ id ] = false
client_print ( id , print_chat , "[ AMXX ] You have just disabled your hud" )
g_bBlocked [ id ] = true
set_task ( SPAM_TIME , "RemoveBlock", id )
}
}
public RemoveBlock ( id ) {
g_bBlocked [ id ] = false
remove_task ( id )
}
public bomb_explode ( ) {
g_bBombPlanted = false
g_bBombExploded = true
}
public bomb_defused ( )
g_bBombPlanted = false
public Logevent_RoundEnd ( ) {
g_bBombPlanted = false
g_iStatus = 0
}
public GetName ( ) {
new EntOwner, iBomb
iBomb = find_ent_by_class(-1, "weapon_c4")
if ( pev_valid ( iBomb ) ) {
EntOwner = pev(iBomb, pev_owner)
if ( is_user_connected ( EntOwner ) )
get_user_name ( EntOwner , szName , sizeof ( szName ) -1 )
}
}
Test it, if it's working I will uplod it to main post. I can't test now
Last edited by HamletEagle; 06-16-2014 at 13:31.
|
|