AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Entity killed with CSW_KNIFE -> server crashes (https://forums.alliedmods.net/showthread.php?t=283174)

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] ) {
    
    new 
iEnt fm_create_entityCLASS_GENERIC ); //info_target
    
if ( !pev_valid(iEnt) ) return 0;
    
    new 
modelMODEL_MAX_LENGTH ];
    
ArrayGetStringAvH_Model_Supplyboxrandom_num0ArraySizeAvH_Model_Supplybox ) - ), modelcharsmaxmodel ) );
    
    new 
SupplyBoxHealth get_pcvar_numg_iCvar_Supply_Health );
    
    
entity_set_string(  iEntEV_SZ_classnameg_szSupplyboxClassName  );
    
entity_set_origin(  iEntfOrigin  );
    
entity_set_model(  iEntmodel  );
    
entity_set_int(  iEntEV_INT_movetypeMOVETYPE_NONE  );
    
entity_set_int(  iEntEV_INT_solidSOLID_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_peviEntPEV_NADE_TYPENADE_TYPE_SUPPLY );
    
entity_set_size(  iEntg_flEggMinsg_flEggMaxs  );
    
entity_set_floatiEntEV_FL_takedamage1.0 ); 
    
entity_set_floatiEntEV_FL_healthfloatSupplyBoxHealth ) ); 
    
    
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_EggSupplyiVictimiEntiAttackerFloat:flDamageiDamageBits ) {
    
    if( 
is_user_valid_connectediAttacker ) ) {
        
        switch( 
peviVictimPEV_NADE_TYPE ) ) {
            
            case 
NADE_TYPE_SUPPLY: {
                
                if( 
g_isalieniAttacker ] ) {
                    
                    
Supply_DamageiVictimiAttackerFloat:{ 0.00.00.0 }, flDamage );
                }
            }
        }
    }


PHP Code:

stock Supply_DamageiVictimiAttackerFloat:flHitPos[3], Float:flDamage ) {
    
    static 
Float:flOrigin];
    
peviVictimpev_originflOrigin );
    new 
iSupply 0;
    for( new 
0MAX_SUPPLIESi++ ) {
        
        if( 
iVictim == g_iSupplyEnt] ) {
            
            
iSupply i;
        }
    }
    
g_iSupplyHitsiSupply ][ iAttacker ]++;
    
// blood squirts out of the middle of the egg
    
if( flHitPos] != 0.0 ) {
        
        
UTIL_SparksflHitPos );
    }
    else {
        
        
flOrigin] += 30.0;
        
UTIL_SparksflOrigin );
        
flOrigin] -= 30.0;
    }    
    
    
    
    
    
// check if he destroyed the supply
    
static Float:flHealth;
    
peviVictimpev_healthflHealth );
    
flHealth -= flDamage;
    
set_peviVictimpev_healthflHealth );
    static 
ReadFlags;
    
ReadFlags get_user_flagsiAttacker );
    
// supplybox was destroyed
    
if( flHealth <= 0.0 ) {
        
// give the killer some xp
        
if( ReadFlags VIP_ACCESS ) {
            
            
GiveXPiAttackerSUPPLY_DESTROYED_VIP );
        }
        else {
            
            
GiveXPiAttackerSUPPLY_DESTROYED );
        }
        
// effects, make the supplybox disappear
        /*if( g_isalive[ iAttacker ] && pev_valid( iVictim ) ) {
            
            fm_remove_entity( iVictim );
        }*/
        
Supply_Explode2iVictim );
        
Supply_ExplodeiVictim );
        
        
        
// show a message about the egg being destroyed
        
static szMessage128 ], iLeniAttackers;
        
iLen 0;
        
iAttackers 0;
        for( new 
id 1id <= g_iMaxPlayersid++ ) {
            
            if( 
g_iSupplyHitsiSupply ][ id ] ) {
                
                if( 
id != iAttacker && g_isconnectedid ] ) {
                    
                    static 
ReadFlags2;
                    
ReadFlags2 get_user_flagsid );
                    
                    if( 
ReadFlags2 VIP_ACCESS ) {
                        
                        
GiveXPidSUPPLY_DESTROYED_ASSIST_VIP );
                    }
                    else {
                        
                        
GiveXPidSUPPLY_DESTROYED_ASSIST )
                    }
                }
                if( 
iAttackers++ == ) {
                    
                    
iLen += formatexszMessageiLen ], charsmaxszMessage ) - iLen"A SupplyBox was destroyed by %s"g_iPlayerNameid ] )
                }
                else {
                    
                    
iLen += formatexszMessageiLen ], charsmaxszMessage ) - iLen" and %s"g_iPlayerNameid ] );
                }
            }
        }
        
//set_hudmessage( 0, 191, 255, 0.0, 0.28, _, _, 1.5, _, _, -1 );
        //ShowSyncHudMsg( 0, HUD_SUPPLY, szMessage );
        
SyncHudMessage001912550.00.2810.01.50.00.01szMessage1.0 );
        
reset_supplies_eggs();
    }


PHP Code:

stock Supply_Explode2iEnt ) {
    
    if( 
peviEntPEV_NADE_TYPE ) == NADE_TYPE_SUPPLY ) {
        
        
        
        
        
        static 
Float:flOrigin[3];
        
peviEntpev_originflOrigin );
        
        
        
flOrigin[2] += 20.0;
        
        
UTIL_DLightflOrigin8, {255255255}, 60);
        
UTIL_SparksflOrigin );    
        
        
        
//fm_set_entity_visibility( iEnt, 0 );
        //set_pev( iEnt, pev_solid, SOLID_NOT );
        //set_pev( iEnt, pev_takedamage, DAMAGE_NO );
        
fm_remove_entityiEnt );
    }



SpeeDeeR 05-27-2016 04:06

Re: Entity killed with CSW_KNIFE -> server crashes
 
I'm not 100% sure about this, but I will try to help.
You should consider using only one method for the health. Since you are setting the hp on spawn, hook the kill and dont check it in takedamage. I think the crash happens when you try to remove (fm_remove_entity in your code) an entity that is already dead and rendered for deletion.
From my personal experience:
Set the hp, set pev_takedamage to DAMAGE_AIM, hook ham_killed -> engine has taken care of removing the entity, do your stuff here.


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

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