AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Help] Don't camp near the bomb (https://forums.alliedmods.net/showthread.php?t=275266)

Mirk 11-26-2015 03:54

[Help] Don't camp near the bomb
 
Hello guys,
Could you help me fix this plugin, please?

Writes that this error:
L 11/26/2015 - 09:48:41: [AMXX] [0] dont_bomb_camp.sma::PlayerPreThink (line 36)
L 11/26/2015 - 09:48:41: [ENGINE] Invalid entity 83
L 11/26/2015 - 09:48:41: [AMXX] Displaying debug trace (plugin "dont_bomb_camp.amxx")

- In the line 36 is code
HTML Code:

entity_get_vector(weapbox, EV_VEC_origin, fOrigin);
PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <cstrike>
#include <fakemeta_util>
#include <engine>

#define PLUGIN "Dont Bomb Camp"
#define VERSION "1.1"
#define AUTHOR "naven"

#define FADE_IN            (1<<0)
#define FADE_OUT        (1<<1)
#define FADE_HOLD        (1<<2)
#define FADE_LENGTH_PERM    (1<<0)

new g_msgFade;
new 
CvarDistance;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
g_msgFade get_user_msgid("ScreenFade");
    
    
register_forward(FM_PlayerPreThink"PlayerPreThink");
    
    
CvarDistance register_cvar("gb_distance""300.0")
}

public 
PlayerPreThink(id)
{
    new 
Float:fOrigin[3], FloatfPlayerOrigin[3];
    new 
weapboxbomb fm_find_ent_by_class(-1"weapon_c4");
    if(
bomb && (weapbox pev(bombpev_owner)) > get_maxplayers())
    {
        
entity_get_vector(weapboxEV_VEC_originfOrigin);
        
entity_get_vector(idEV_VEC_originfPlayerOrigin);
        
        if(
get_distance_f(fOriginfPlayerOrigin) < get_pcvar_float(CvarDistance))
        {
            new 
FloatpunishPercentage 1.0;
            new 
duration = (punishPercentage == 1.0) ? FADE_LENGTH_PERM 1<<12;
            new 
holdTime = (punishPercentage == 1.0) ? FADE_LENGTH_PERM 1<<8;
            new 
fadeType = (punishPercentage == 1.0) ? FADE_HOLD FADE_IN;
            new 
blindness 127 floatround(128.0 punishPercentage);
            
            
message_begin(MSG_ONEg_msgFade, {0,0,0}, id);
            
write_short(duration);
            
write_short(holdTime);
            
write_short(fadeType);
            
write_byte(0);
            
write_byte(0);
            
write_byte(0);
            
write_byte(blindness);
            
message_end();
            
            
set_hudmessage(25500, -1.00.2000.10.5__, -1);
            
show_hudmessage(id"Nekempi u bomby!");
        } else {
            
punish_blind_stop(id);
        }
    }
}

public 
punish_blind_stop(id)
{
    
message_begin(MSG_ONEg_msgFade, {0,0,0}, id);
    
write_short(0);
    
write_short(1<<8);
    
write_short(FADE_OUT);
    
write_byte(0);
    
write_byte(0);
    
write_byte(0);
    
write_byte(255);
    
message_end();



tuty 11-26-2015 09:28

Re: [Help] Don't camp near the bomb
 
check if is a valid entity?:) pev_valid

Bugsy 11-26-2015 12:19

Re: [Help] Don't camp near the bomb
 
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];
    
get_mapnameszMap charsmaxszMap ) );
    
    if ( 
szMap] == 'd' && szMap] == 'e' )
    {
        
g_msgFade get_user_msgid("ScreenFade");
        
CvarDistance register_cvar("gb_distance""300.0");
        
set_taskCheckInterval "BombCheckTask" , .flags="b" );
    }
}

public 
BombCheckTask()
{
    new 
Float:fOrigin] , weapboxbomb id playersList[32] , playersCount;
    
    
bomb fm_find_ent_by_class( -"weapon_c4" );
    
    if ( 
bomb && !( <= ( weapbox pevbomb pev_owner ) ) <= MAX_PLAYERS ) && pev_validweapbox ) )
    {
        
pevweapbox pev_origin fOrigin );

        
playersCount find_sphere_class"player" get_pcvar_floatCvarDistance ) , playersList sizeofplayersList ) , fOrigin );
            
        for ( new 
playersCount i++ )
        {
            
id playersList];
            
            
message_begin(MSG_ONEg_msgFade, {0,0,0}, id);
            
write_short(1<<12);
            
write_shortFixedUnsigned16CheckInterval << 12 ) );
            
write_short(0);
            
write_byte(0);
            
write_byte(0);
            
write_byte(0);
            
write_byte(255);
            
message_end();
            
            
set_hudmessage(25500, -1.00.2000.1CheckInterval__, -1)
            
show_hudmessage(idHUDMessage );
        }
    }
}

FixedUnsigned16(Float:flValueiScale)
{
    new 
iOutput;

    
iOutput floatround(flValue iScale);

    if ( 
iOutput )
        
iOutput 0;

    if ( 
iOutput 0xFFFF )
        
iOutput 0xFFFF;

    return 
iOutput;



Mirk 11-26-2015 17:36

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];
    
get_mapnameszMap charsmaxszMap ) );
    
    if ( 
szMap] == 'd' && szMap] == 'e' )
    {
        
g_msgFade get_user_msgid("ScreenFade");
        
CvarDistance register_cvar("gb_distance""300.0");
        
set_taskCheckInterval "BombCheckTask" , .flags="b" );
    }
}

public 
BombCheckTask()
{
    new 
Float:fOrigin] , weapboxbomb id playersList[32] , playersCount;
    
    
bomb fm_find_ent_by_class( -"weapon_c4" );
    
    if ( 
bomb && !( <= ( weapbox pevbomb pev_owner ) ) <= MAX_PLAYERS ) && pev_validweapbox ) )
    {
        
pevweapbox pev_origin fOrigin );

        
playersCount find_sphere_class"player" get_pcvar_floatCvarDistance ) , playersList sizeofplayersList ) , fOrigin );
            
        for ( new 
playersCount i++ )
        {
            
id playersList];
            
            
message_begin(MSG_ONEg_msgFade, {0,0,0}, id);
            
write_short(1<<12);
            
write_shortFixedUnsigned16CheckInterval << 12 ) );
            
write_short(0);
            
write_byte(0);
            
write_byte(0);
            
write_byte(0);
            
write_byte(255);
            
message_end();
            
            
set_hudmessage(25500, -1.00.2000.1CheckInterval__, -1)
            
show_hudmessage(idHUDMessage );
        }
    }
}

FixedUnsigned16(Float:flValueiScale)
{
    new 
iOutput;

    
iOutput floatround(flValue iScale);

    if ( 
iOutput )
        
iOutput 0;

    if ( 
iOutput 0xFFFF )
        
iOutput 0xFFFF;

    return 
iOutput;



I love you Bugsy :D It is great code, thank you for helpfulness

tuty 11-27-2015 06:57

Re: [Help] Don't camp near the bomb
 
Quote:

Originally Posted by Mirk (Post 2366671)
No, I don't added valid entity, thank you for advise.

what? Bugsy, explain kindly to this lad, what i have just said and what you have done.

Bugsy 11-27-2015 11:47

Re: [Help] Don't camp near the bomb
 
Quote:

Originally Posted by tuty (Post 2366529)
check if is a valid entity?:) pev_valid

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. <- tuty said to do this, which I did for you.
  • Made the task only create if the current map has a 'de' prefix (de_dust, de_dust2, etc).

Quote:

Originally Posted by Mirk (Post 2366671)
No, I don't added valid entity, thank you for advise.

Quote:

Originally Posted by tuty (Post 2366782)
what? Bugsy, explain kindly to this lad, what i have just said and what you have done.



All times are GMT -4. The time now is 18:10.

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