| Hunter4all |
05-27-2016 02:50 |
Entity killed with CSW_KNIFE -> server crashes
Hello everyone.
I have the following code:
PHP Code:
public CreateSupply( const Float:fOrigin[ 3 ] ) {
new iEnt = fm_create_entity( CLASS_GENERIC ); //info_target
if ( !pev_valid(iEnt) ) return 0;
new model[ MODEL_MAX_LENGTH ];
ArrayGetString( AvH_Model_Supplybox, random_num( 0, ArraySize( AvH_Model_Supplybox ) - 1 ), model, charsmax( model ) );
new SupplyBoxHealth = get_pcvar_num( g_iCvar_Supply_Health );
entity_set_string( iEnt, EV_SZ_classname, g_szSupplyboxClassName );
entity_set_origin( iEnt, fOrigin );
entity_set_model( iEnt, model );
entity_set_int( iEnt, EV_INT_movetype, MOVETYPE_NONE );
entity_set_int( iEnt, EV_INT_solid, SOLID_BBOX );
//entity_set_int(iEnt, EV_INT_solid, SOLID_SLIDEBOX)
//entity_set_int(iEnt, EV_INT_movetype, MOVETYPE_PUSHSTEP)
//set_pev(iEnt, pev_iuser4, 0)
set_pev( iEnt, PEV_NADE_TYPE, NADE_TYPE_SUPPLY );
entity_set_size( iEnt, g_flEggMins, g_flEggMaxs );
entity_set_float( iEnt, EV_FL_takedamage, 1.0 );
entity_set_float( iEnt, EV_FL_health, float( SupplyBoxHealth ) );
fm_drop_to_floor( iEnt );
return 1;
}
Ingame, if i destroy the supply with a knife, the server crashes BUT if i destroy it with any other weapons, it wont crash.
My questions are:
1. Why does it crash only when its destroyed with the knife ?
2. What am i doing wrong ?
Please help me understand. This problem is really really bugging me !
EDIT: Forgot to mention.
This only happens when in my Supply_Explode function i add fm_remove_entity( iEnt );
PHP Code:
public HAM_TakeDamage_EggSupply( iVictim, iEnt, iAttacker, Float:flDamage, iDamageBits ) {
if( is_user_valid_connected( iAttacker ) ) {
switch( pev( iVictim, PEV_NADE_TYPE ) ) {
case NADE_TYPE_SUPPLY: {
if( g_isalien[ iAttacker ] ) {
Supply_Damage( iVictim, iAttacker, Float:{ 0.0, 0.0, 0.0 }, flDamage );
}
}
}
}
}
PHP Code:
stock Supply_Damage( iVictim, iAttacker, Float:flHitPos[3], Float:flDamage ) {
static Float:flOrigin[ 3 ];
pev( iVictim, pev_origin, flOrigin );
new iSupply = 0;
for( new i = 0; i < MAX_SUPPLIES; i++ ) {
if( iVictim == g_iSupplyEnt[ i ] ) {
iSupply = i;
}
}
g_iSupplyHits[ iSupply ][ iAttacker ]++;
// blood squirts out of the middle of the egg
if( flHitPos[ 0 ] != 0.0 ) {
UTIL_Sparks( flHitPos );
}
else {
flOrigin[ 2 ] += 30.0;
UTIL_Sparks( flOrigin );
flOrigin[ 2 ] -= 30.0;
}
// check if he destroyed the supply
static Float:flHealth;
pev( iVictim, pev_health, flHealth );
flHealth -= flDamage;
set_pev( iVictim, pev_health, flHealth );
static ReadFlags;
ReadFlags = get_user_flags( iAttacker );
// supplybox was destroyed
if( flHealth <= 0.0 ) {
// give the killer some xp
if( ReadFlags & VIP_ACCESS ) {
GiveXP( iAttacker, SUPPLY_DESTROYED_VIP );
}
else {
GiveXP( iAttacker, SUPPLY_DESTROYED );
}
// effects, make the supplybox disappear
/*if( g_isalive[ iAttacker ] && pev_valid( iVictim ) ) {
fm_remove_entity( iVictim );
}*/
Supply_Explode2( iVictim );
Supply_Explode( iVictim );
// show a message about the egg being destroyed
static szMessage[ 128 ], iLen, iAttackers;
iLen = 0;
iAttackers = 0;
for( new id = 1; id <= g_iMaxPlayers; id++ ) {
if( g_iSupplyHits[ iSupply ][ id ] ) {
if( id != iAttacker && g_isconnected[ id ] ) {
static ReadFlags2;
ReadFlags2 = get_user_flags( id );
if( ReadFlags2 & VIP_ACCESS ) {
GiveXP( id, SUPPLY_DESTROYED_ASSIST_VIP );
}
else {
GiveXP( id, SUPPLY_DESTROYED_ASSIST )
}
}
if( iAttackers++ == 0 ) {
iLen += formatex( szMessage[ iLen ], charsmax( szMessage ) - iLen, "A SupplyBox was destroyed by %s", g_iPlayerName[ id ] )
}
else {
iLen += formatex( szMessage[ iLen ], charsmax( szMessage ) - iLen, " and %s", g_iPlayerName[ id ] );
}
}
}
//set_hudmessage( 0, 191, 255, 0.0, 0.28, _, _, 1.5, _, _, -1 );
//ShowSyncHudMsg( 0, HUD_SUPPLY, szMessage );
SyncHudMessage( 0, 0, 191, 255, 0.0, 0.28, 1, 0.0, 1.5, 0.0, 0.0, 1, szMessage, 1.0 );
reset_supplies_eggs();
}
}
PHP Code:
stock Supply_Explode2( iEnt ) {
if( pev( iEnt, PEV_NADE_TYPE ) == NADE_TYPE_SUPPLY ) {
static Float:flOrigin[3];
pev( iEnt, pev_origin, flOrigin );
flOrigin[2] += 20.0;
UTIL_DLight( flOrigin, 8, {255, 255, 255}, 60, 0 );
UTIL_Sparks( flOrigin );
//fm_set_entity_visibility( iEnt, 0 );
//set_pev( iEnt, pev_solid, SOLID_NOT );
//set_pev( iEnt, pev_takedamage, DAMAGE_NO );
fm_remove_entity( iEnt );
}
}
|