AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Problem with lasermine, crash the server (https://forums.alliedmods.net/showthread.php?t=193383)

Netsys 08-18-2012 20:30

Problem with lasermine, crash the server
 
Hi, i have a problem with the lasermine, i'm testing the server without lasermine and its run right.

Think:
PHP Code:

/* Lasermine think */
public lasermine_thinkentity )
{
    
/* Lasermine disabled? */
    
if( !get_pcvar_numcvar[CVAR_HUMAN_LASERMINE] ) )
        return;
    
    
/* Check if valid entity */
    
if( !is_valid_ententity ) )
        return;
    
    static 
Float:fCurrTime;
    
fCurrTime get_gametime();
    
    switch( 
entity_get_intentity EV_INT_iuser4 ) ) 
    { 
        case 
0
        { 
            static 
Float:fPowerupTime;
            
fPowerupTime entity_get_floatentity EV_FL_fuser2 );
            
            if( 
fCurrTime fPowerupTime )
            {
                
entity_set_intentity EV_INT_iuser4 );
                
emit_soundentity CHAN_VOICE g_sound_lm[2] , 0.5 ATTN_NORM 175 );
                
                
/* Check if player stuck in the lasermine */
                
static Float:originF[3], classname[32], owneriuser4playerrecovery;
                
entity_get_vectorentity EV_VEC_origin originF );
                
owner entity_get_intentity EV_INT_iuser3 );
                
player = -1;
                
iuser4 1;
                
recovery false;
                
                
                while( ( 
player find_ent_in_sphereplayer originF 7.5 ) ) != )
                {
                    if( !
is_valid_entplayer ) )
                        continue;
                        
                    
entity_get_stringplayer EV_SZ_classname classname charsmaxclassname ) );
                    
                    if( 
equalclassname "player" ) )
                    {
                        if( !
is_user_valid_connectedplayer ) )
                            continue;
                        
                        if( 
owner != player && !recovery )
                        {
                            
g_lm[owner]++;
                            
colored_printowner "^x04[%s]^x01 Has recuperado^x03 1^x01 lasermine"TAG_PRINT );
                            
recovery true;
                        }
                        
                        
iuser4 2;
                    }
                }
                
                
entity_set_intentity EV_INT_solid SOLID_BBOX );
                
entity_set_intentity EV_INT_iuser4 iuser4 );
            }
            
            
/* Set rendering */
            
set_renderingentity kRenderFxGlowShell 255 kRenderNormal );

            
/* Next think */
            
entity_set_floatentity EV_FL_nextthink fCurrTime 0.1 );
        }
        case 
1:
        {
            static 
Float:vEnd[3],Float:vOrigin[3];
            
entity_get_vectorentity EV_VEC_origin vOrigin );
            
entity_get_vectorentity EV_VEC_vuser1 vEnd );
            
            static 
victimFloat:vHitOrigin[3];
            
victim trace_lineentity vOrigin vEnd vHitOrigin );
            
            
/* Is valid victim? */
            
if( is_user_valid_alivevictim ) ) 
            { 
                
/* Is a zombie? */
                
if( g_zombie[victim] ) 
                { 
                    
entity_set_intentity EV_INT_iuser4 );
                    
entity_set_floatentity EV_FL_nextthink fCurrTime 0.01 );
                    return;
                } 
            } 
            else 
                
vEnd vHitOrigin 
            
            
/* Lasermine death by a zombie? */
            
if( entity_get_intentity EV_INT_flags ) & FL_KILLME || entity_get_floatentity EV_FL_health) <= 0.0 
            { 
                
entity_set_intentity EV_INT_iuser4 );
                
entity_set_floatentity EV_FL_nextthink fCurrTime 0.01 );
                return;
            } 
            
            static 
Float:fBeamthinkFloat:laser_end[3];
            
fBeamthink entity_get_floatentity EV_FL_fuser3 );
            
entity_get_vectorentity EV_VEC_vuser2 laser_end );
            
            if( 
fBeamthink fCurrTime || !xs_vec_equallaser_end vEnd ) ) 
            { 
                if( !
xs_vec_equallaser_end vEnd ) ) 
                { 
                    
message_beginMSG_BROADCAST SVC_TEMPENTITY );
                    
write_byte99 );
                    
write_shortentity ); 
                    
message_end( );
                } 
                
                
ShowLaservOrigin vEnd );
                
entity_set_floatentity EV_FL_fuser3 fCurrTime 10.0 ); 
            } 
            
            
entity_set_floatentity EV_FL_nextthink fCurrTime 0.12 );
        }
        case 
2
        { 
            
entity_set_floatentity EV_FL_nextthink 0.0 ); 
            
            
/* Create explosion */
            
CrearDamageentity  );
            
            
emit_soundentity CHAN_BODY g_sound_lm[1] , 0.2 ATTN_NORM SND_STOP PITCH_NORM );
            
emit_soundentity CHAN_VOICE g_sound_lm[2] , 0.5 ATTN_NORM SND_STOP ,  75 );
            
            
/* Remove entity */
            
remove_entityentity ); 
        }
    }


Explosion:
PHP Code:

CrearDamageentity )
{
    
/* Create explosion effect */
    
static Float:originF[3];
    
entity_get_vectorentity EV_VEC_origin originF );
    
    
engfuncEngFunc_MessageBegin MSG_PVS SVC_TEMPENTITY originF);
    
write_byteTE_EXPLOSION );
    
engfuncEngFunc_WriteCoord originF[0] );
    
engfuncEngFunc_WriteCoord originF[1] );
    
engfuncEngFunc_WriteCoord originF[2] );
    
write_shortg_lmExplosionSpr );
    
write_byte30 );
    
write_byte15 );
    
write_byte);
    
message_end( ); 
    
    static 
Float:vic_originF[3],  iddamagethpFloat:distFloat:pos_ptd[3];
    
    for( 
id 1id <= g_maxplayersid++ )
    {
        if( !
is_user_valid_aliveid ) )
            continue;
        
        
/* Get origin of the victim */
        
entity_get_vectorid EV_VEC_origin vic_originF );
        
        
/* Calculate the distance */
        
dist get_distance_foriginFvic_originF );
        
        if( 
dist 220.0 
            continue;
        
        
xs_vec_copyvic_originFpos_ptd );
        
        for(new 
03i++) 
        { 
            
pos_ptd[i] -= originF[i];
            
pos_ptd[i] *= get_pcvar_float(cvar[CVAR_HUMAN_LASERMINE_EXP]);
        } 
        
        
entity_set_vectorid EV_VEC_velocity pos_ptd ); 
        
entity_set_vectorid EV_INT_impulse pos_ptd ); 
        
        
/* If a zombie? */
        
if( !g_zombie[id] )
            continue;
            
        
/* If frozen? */
        
if( g_frozen[id] || g_nodamage[id] )
            continue;
        
        
damaget floatround( ( ( 5000.0 dist ) / 220.0 ) - 5000.0 );
        
damaget = -damaget;
        
        
hp = ( get_user_healthid ) - damaget );
        
        if( 
hp <= 
            
hp 1;
        
        
/* Set the health */
        
set_user_healthid hp );
        
        
message_beginMSG_ONE_UNRELIABLE g_msgDamage id );
        
write_byte21 );
        
write_byte20 ); 
        
write_longDMG_BLAST 
        
engfuncEngFunc_WriteCoord originF[0] );
        
engfuncEngFunc_WriteCoord originF[1] );
        
engfuncEngFunc_WriteCoord originF[2] );
        
message_end( ) 
    }


Show laser:
PHP Code:

ShowLaser( const Float:v_Origin[3] , const Float:v_EndOrigin[3] )

    
message_beginMSG_BROADCAST SVC_TEMPENTITY )
    
write_byteTE_BEAMPOINTS )
    
engfuncEngFunc_WriteCoord v_Origin[0] )
    
engfuncEngFunc_WriteCoord v_Origin[1] )
    
engfuncEngFunc_WriteCoord v_Origin[2] )
    
engfuncEngFunc_WriteCoord v_EndOrigin[0] );
    
engfuncEngFunc_WriteCoord v_EndOrigin[1] );
    
engfuncEngFunc_WriteCoord v_EndOrigin[2] );
    
write_shortg_lmSpr );
    
write_byte);
    
write_byte);
    
write_byte);
    
write_byte);
    
write_byte);
    
write_byte);
    
write_byte);
    
write_byte255 );
    
write_byte100 );
    
write_byte255 );
    
message_end( );


And i was asking if it could be possible to make a better code

claudiuhks 08-19-2012 01:58

Re: Problem with lasermine, crash the server
 
Instead of using that while statement, you may loop using for through all players then check the range with entity_range instead of getting each entity classname.

What kind of error are you talking about? Infinite loop? Then try using for statement.
Segmentation fault? Make sure you are using remove_entity properly.

Netsys 08-19-2012 10:58

Re: Problem with lasermine, crash the server
 
Quote:

Originally Posted by claudiuhks (Post 1775852)
Instead of using that while statement, you may loop using for through all players then check the range with entity_range instead of getting each entity classname.

What kind of error are you talking about? Infinite loop? Then try using for statement.
Segmentation fault? Make sure you are using remove_entity properly.

Is this okay?
PHP Code:

/* Check if player stuck in the lasermine */
static Float:originF[3], owneriuser4recovery;
entity_get_vectorentity EV_VEC_origin originF );
owner entity_get_intentity EV_INT_iuser3 );
iuser4 1;
recovery false;
                
for( new 
player 1player <= g_maxplayersplayer++ )
{
    if( !
is_user_valid_connectedplayer ) || !is_user_valid_aliveplayer ) )
        continue;
                    
    if( 
entity_rangeplayer entity ) > 7.5 )
        continue;
                    
    if( 
owner != player && !recovery )
    {
        
g_lm[owner]++;
        
colored_printowner "^x04[%s]^x01 Has recuperado^x03 1^x01 lasermine"TAG_PRINT );
        
recovery true;
    }
                    
    
iuser4 2;
}
                
entity_set_intentity EV_INT_solid SOLID_BBOX );
entity_set_intentity EV_INT_iuser4 iuser4 ); 

Logs of error: Sys_error: HamFilter

What's the HamFilter problem?

Netsys 08-20-2012 21:50

Re: Problem with lasermine, crash the server
 
Update -> The console closes without error

claudiuhks 08-21-2012 02:28

Re: Problem with lasermine, crash the server
 
I don't know what to say, I think the functions you've posted are alright.
Don't know about the entire code.

Netsys 08-21-2012 10:01

Re: Problem with lasermine, crash the server
 
I know, must be something else, what causes things to close the console without throwing an error?

claudiuhks 08-21-2012 21:46

Re: Problem with lasermine, crash the server
 
Hm, I think removing Worldspawn or remove Player entity.
Changing the player team to spectator while he choosed CT/TERRORIST and didn't choose the Player Model.
Or other errors. You have to mind your algorithm to be as reliable as possible.


All times are GMT -4. The time now is 05:41.

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