Raised This Month: $ Target: $400
 0% 

_BBOX crashes server


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
SpannerSpammer
Member
Join Date: Mar 2006
Old 05-28-2016 , 11:37   Re: _BBOX crashes server
Reply With Quote #5

The problem when you create a custom entity in goldsrc and enable takedamage is
that the engine will automatically kill the entity when it's health is less than zero.

You DO NOT want this to happen, you want to fully control when your
custom entity gets removed. To do this you need to set a health mask with
a high enough value that no weapon/explosive in-game can easily destroy it.

Code:
#define HEALTH_MASK  1000000.0
.
.
entity_set_float( entity_stick, EV_FL_health, HEALTH_MASK );
Then, check the health in some function, usually it's think function or a hooked
Takedamage function and then evaluate whether or not you need to kill the entity.
If you do, then perform whatever code cleanup required and then kill the entity.

Code:
public StickThink( ent )
{
    static Float:flHealth;
    flHealth = get_pcvar_float( stick_health );
    if ( flHealth < 1.0 ) flHealth = 1.0;       // idiot proof your HP value
    if ( flHealth > 500.0 ) flHealth = 500.0;

    if ( entity_get_float( ent, EV_FL_health ) <= (HEALTH_MASK - flHealth) )
    {
        // do any code cleanup here
        //
        // new id = entity_get_int( ent, EV_INT_iuser2 );
        // if ( SomeIsValidPlayerIDFunction(id) )   
        //        client_print( id, print_chat, "Your stick was destroyed" );

        remove_entity( ent );
        return PLUGIN_CONTINUE;
    }
    .
    .
    .
    return PLUGIN_CONTINUE;
}
One last thing: If you use CVARs or load settings from a configuration file, don't
plug these values directly into your code. You need to idiot proof these values
before plugging them in, because an invalid setting can sometimes have unpredictable
results, like crashing the server.
__________________
[NeoTF|DEV]SpannerSpammer-[AoE]-
NeoTF Development Team.
http://steamcommunity.com/groups/neotf
SpannerSpammer is offline
 



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 09:30.


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