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_think( entity )
{
/* Lasermine disabled? */
if( !get_pcvar_num( cvar[CVAR_HUMAN_LASERMINE] ) )
return;
/* Check if valid entity */
if( !is_valid_ent( entity ) )
return;
static Float:fCurrTime;
fCurrTime = get_gametime();
switch( entity_get_int( entity , EV_INT_iuser4 ) )
{
case 0:
{
static Float:fPowerupTime;
fPowerupTime = entity_get_float( entity , EV_FL_fuser2 );
if( fCurrTime > fPowerupTime )
{
entity_set_int( entity , EV_INT_iuser4 , 1 );
emit_sound( entity , CHAN_VOICE , g_sound_lm[2] , 0.5 , ATTN_NORM , 1, 75 );
/* Check if player stuck in the lasermine */
static Float:originF[3], classname[32], owner, iuser4, player, recovery;
entity_get_vector( entity , EV_VEC_origin , originF );
owner = entity_get_int( entity , EV_INT_iuser3 );
player = -1;
iuser4 = 1;
recovery = false;
while( ( player = find_ent_in_sphere( player , originF , 7.5 ) ) != 0 )
{
if( !is_valid_ent( player ) )
continue;
entity_get_string( player , EV_SZ_classname , classname , charsmax( classname ) );
if( equal( classname , "player" ) )
{
if( !is_user_valid_connected( player ) )
continue;
if( owner != player && !recovery )
{
g_lm[owner]++;
colored_print( owner , "^x04[%s]^x01 Has recuperado^x03 1^x01 lasermine", TAG_PRINT );
recovery = true;
}
iuser4 = 2;
}
}
entity_set_int( entity , EV_INT_solid , SOLID_BBOX );
entity_set_int( entity , EV_INT_iuser4 , iuser4 );
}
/* Set rendering */
set_rendering( entity , kRenderFxGlowShell , 0 , 0 , 255 , kRenderNormal , 5 );
/* Next think */
entity_set_float( entity , EV_FL_nextthink , fCurrTime + 0.1 );
}
case 1:
{
static Float:vEnd[3],Float:vOrigin[3];
entity_get_vector( entity , EV_VEC_origin , vOrigin );
entity_get_vector( entity , EV_VEC_vuser1 , vEnd );
static victim, Float:vHitOrigin[3];
victim = trace_line( entity , vOrigin , vEnd , vHitOrigin );
/* Is valid victim? */
if( is_user_valid_alive( victim ) )
{
/* Is a zombie? */
if( g_zombie[victim] )
{
entity_set_int( entity , EV_INT_iuser4 , 2 );
entity_set_float( entity , EV_FL_nextthink , fCurrTime + 0.01 );
return;
}
}
else
vEnd = vHitOrigin
/* Lasermine death by a zombie? */
if( entity_get_int( entity , EV_INT_flags ) & FL_KILLME || entity_get_float( entity , EV_FL_health) <= 0.0 )
{
entity_set_int( entity , EV_INT_iuser4 , 2 );
entity_set_float( entity , EV_FL_nextthink , fCurrTime + 0.01 );
return;
}
static Float:fBeamthink, Float:laser_end[3];
fBeamthink = entity_get_float( entity , EV_FL_fuser3 );
entity_get_vector( entity , EV_VEC_vuser2 , laser_end );
if( fBeamthink < fCurrTime || !xs_vec_equal( laser_end , vEnd ) )
{
if( !xs_vec_equal( laser_end , vEnd ) )
{
message_begin( MSG_BROADCAST , SVC_TEMPENTITY );
write_byte( 99 );
write_short( entity );
message_end( );
}
ShowLaser( vOrigin , vEnd );
entity_set_float( entity , EV_FL_fuser3 , fCurrTime + 10.0 );
}
entity_set_float( entity , EV_FL_nextthink , fCurrTime + 0.12 );
}
case 2:
{
entity_set_float( entity , EV_FL_nextthink , 0.0 );
/* Create explosion */
CrearDamage( entity );
emit_sound( entity , CHAN_BODY , g_sound_lm[1] , 0.2 , ATTN_NORM , SND_STOP , PITCH_NORM );
emit_sound( entity , CHAN_VOICE , g_sound_lm[2] , 0.5 , ATTN_NORM , SND_STOP , 75 );
/* Remove entity */
remove_entity( entity );
}
}
}
Explosion:
PHP Code:
CrearDamage( entity )
{
/* Create explosion effect */
static Float:originF[3];
entity_get_vector( entity , EV_VEC_origin , originF );
engfunc( EngFunc_MessageBegin , MSG_PVS , SVC_TEMPENTITY , originF, 0 );
write_byte( TE_EXPLOSION );
engfunc( EngFunc_WriteCoord , originF[0] );
engfunc( EngFunc_WriteCoord , originF[1] );
engfunc( EngFunc_WriteCoord , originF[2] );
write_short( g_lmExplosionSpr );
write_byte( 30 );
write_byte( 15 );
write_byte( 0 );
message_end( );
static Float:vic_originF[3], id, damaget, hp, Float:dist, Float:pos_ptd[3];
for( id = 1; id <= g_maxplayers; id++ )
{
if( !is_user_valid_alive( id ) )
continue;
/* Get origin of the victim */
entity_get_vector( id , EV_VEC_origin , vic_originF );
/* Calculate the distance */
dist = get_distance_f( originF, vic_originF );
if( dist > 220.0 )
continue;
xs_vec_copy( vic_originF, pos_ptd );
for(new i = 0; i < 3; i++)
{
pos_ptd[i] -= originF[i];
pos_ptd[i] *= get_pcvar_float(cvar[CVAR_HUMAN_LASERMINE_EXP]);
}
entity_set_vector( id , EV_VEC_velocity , pos_ptd );
entity_set_vector( id , 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_health( id ) - damaget );
if( hp <= 0 )
hp = 1;
/* Set the health */
set_user_health( id , hp );
message_begin( MSG_ONE_UNRELIABLE , g_msgDamage , _ , id );
write_byte( 21 );
write_byte( 20 );
write_long( DMG_BLAST )
engfunc( EngFunc_WriteCoord , originF[0] );
engfunc( EngFunc_WriteCoord , originF[1] );
engfunc( EngFunc_WriteCoord , originF[2] );
message_end( )
}
}
Show laser:
PHP Code:
ShowLaser( const Float:v_Origin[3] , const Float:v_EndOrigin[3] )
{
message_begin( MSG_BROADCAST , SVC_TEMPENTITY )
write_byte( TE_BEAMPOINTS )
engfunc( EngFunc_WriteCoord , v_Origin[0] )
engfunc( EngFunc_WriteCoord , v_Origin[1] )
engfunc( EngFunc_WriteCoord , v_Origin[2] )
engfunc( EngFunc_WriteCoord , v_EndOrigin[0] );
engfunc( EngFunc_WriteCoord , v_EndOrigin[1] );
engfunc( EngFunc_WriteCoord , v_EndOrigin[2] );
write_short( g_lmSpr );
write_byte( 0 );
write_byte( 0 );
write_byte( 1 );
write_byte( 5 );
write_byte( 0 );
write_byte( 0 );
write_byte( 0 );
write_byte( 255 );
write_byte( 100 );
write_byte( 255 );
message_end( );
}
And i was asking if it could be possible to make a better code
|