Re: [Help] Don't camp near the bomb
Quote:
Originally Posted by tuty
(Post 2366529)
check if is a valid entity?:) pev_valid
|
No, I don't added valid entity, thank you for advise.
Quote:
Originally Posted by Bugsy
(Post 2366583)
I made the following changes: - Removed PreThink and using a task instead with an interval of 1 second. PreThink was a terrible idea for something like this.
- Added a pev_valid() check to see if that fixes the error.
- Made the task only create if the current map has a 'de' prefix (de_dust, de_dust2, etc).
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <fakemeta_util>
#include <engine>
#define MAX_PLAYERS 32
new const Float:CheckInterval = 1.0;
new const HUDMessage[] = "Nekempi u bomby!";
new g_msgFade , CvarDistance;
public plugin_init()
{
register_plugin( "Dont Bomb Camp" , "1.1b" , "naven/bugsy" );
new szMap[ 3 ];
get_mapname( szMap , charsmax( szMap ) );
if ( szMap[ 0 ] == 'd' && szMap[ 1 ] == 'e' )
{
g_msgFade = get_user_msgid("ScreenFade");
CvarDistance = register_cvar("gb_distance", "300.0");
set_task( CheckInterval , "BombCheckTask" , .flags="b" );
}
}
public BombCheckTask()
{
new Float:fOrigin[ 3 ] , weapbox, bomb , id , playersList[32] , playersCount;
bomb = fm_find_ent_by_class( -1 , "weapon_c4" );
if ( bomb && !( 1 <= ( weapbox = pev( bomb , pev_owner ) ) <= MAX_PLAYERS ) && pev_valid( weapbox ) )
{
pev( weapbox , pev_origin , fOrigin );
playersCount = find_sphere_class( 0 , "player" , get_pcvar_float( CvarDistance ) , playersList , sizeof( playersList ) , fOrigin );
for ( new i = 0 ; i < playersCount ; i++ )
{
id = playersList[ i ];
message_begin(MSG_ONE, g_msgFade, {0,0,0}, id);
write_short(1<<12);
write_short( FixedUnsigned16( CheckInterval , 1 << 12 ) );
write_short(0);
write_byte(0);
write_byte(0);
write_byte(0);
write_byte(255);
message_end();
set_hudmessage(255, 0, 0, -1.0, 0.20, 0, 0.1, CheckInterval, _, _, -1)
show_hudmessage(id, HUDMessage );
}
}
}
FixedUnsigned16(Float:flValue, iScale)
{
new iOutput;
iOutput = floatround(flValue * iScale);
if ( iOutput < 0 )
iOutput = 0;
if ( iOutput > 0xFFFF )
iOutput = 0xFFFF;
return iOutput;
}
|
I love you Bugsy :D It is great code, thank you for helpfulness
|