AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Sometimes it throws sometimes not!! (https://forums.alliedmods.net/showthread.php?t=249771)

HENNESSY 10-11-2014 20:15

Sometimes it throws sometimes not!!
 
I'm using the throw knife entity code from throwing knives plugin.

the problem is when i type /throw, sometimes it throw's a knife and sometimes no.

Why is that?

This is the code:

PHP Code:

public ThrowKnifeiIndex )
{
    static 
Float:flOrigin], Float:flVelocity], Float:flAngles], iEnt;
    
    
entity_get_vectoriIndexEV_VEC_originflOrigin );
    
entity_get_vectoriIndexEV_VEC_v_angleflAngles );
    
    
iEnt create_entity"info_target" );
    
    if( !
is_valid_entiEnt ) )
    {
        return;
    }
        
    
entity_set_stringiEntEV_SZ_classnameKNIFE_ENT );
    
entity_set_modeliEntKNIFE_MODEL );
        
    
entity_set_sizeiEntFloat:{ -1.0, -7.0, -1.0 }, Float:{ 1.07.01.0 } );
    
entity_set_originiEntflOrigin );
    
    
flAngles] -= 90.0;
    
entity_set_vectoriEntEV_VEC_anglesflAngles );
    
    
entity_set_intiEntEV_INT_effects32 );
    
entity_set_intiEntEV_INT_solidSOLID_TRIGGER );
    
entity_set_intiEntEV_INT_movetypeMOVETYPE_TOSS );
    
    
entity_set_edictiEntEV_ENT_owneriIndex );
    
    
set_renderingiEntkRenderFxGlowShell02500kRenderNormal25 );
    
    
VelocityByAimiIndexKNIFE_SPEEDflVelocity );
    
entity_set_vectoriEntEV_VEC_velocityflVelocity );


In the touch forward i just removed the entity with remove_entity( iEntity );

Thanks for help! :)

HamletEagle 10-12-2014 02:46

Re: Sometimes it throws sometimes not!!
 
Show us the full code. I can think only that you are trying to drop too fast or whatever and the entity is somehow not valid at this point. I can't see something wrong.
Code:
iEnt = create_entity( "info_target" );           if( !is_valid_ent( iEnt ) )     {         return;     }

Your code basically create another entity, set to it the knife model, set a size so it will be solid and you can touch it, and then set a velocity on this entity. The entity is not created or the velocity is not set ?

HENNESSY 10-12-2014 06:32

Re: Sometimes it throws sometimes not!!
 
Quote:

Originally Posted by HamletEagle (Post 2210049)
Show us the full code. I can think only that you are trying to drop too fast or whatever and the entity is somehow not valid at this point. I can't see something wrong.
Code:
iEnt = create_entity( "info_target" );           if( !is_valid_ent( iEnt ) )     {         return;     }

Your code basically create another entity, set to it the knife model, set a size so it will be solid and you can touch it, and then set a velocity on this entity. The entity is not created or the velocity is not set ?

i checked that out by adding some debug messages to the code.

the result is that the entity is created successfully tough the knife isn't thrown.

HamletEagle 10-12-2014 07:00

Re: Sometimes it throws sometimes not!!
 
Again, give us the full code or a simple one that has the same problem.

HENNESSY 10-12-2014 07:33

Re: Sometimes it throws sometimes not!!
 
Quote:

Originally Posted by HamletEagle (Post 2210115)
Again, give us the full code or a simple one that has the same problem.

Here you go :)

PHP Code:

public UpdateClientData_Postidsendweaponscd_handle )
{
    if ( !
is_user_alive(id) )
    return 
FMRES_IGNORED;
    
    if( 
get_user_weaponid ) != CSW_KNIFE )
        return 
FMRES_IGNORED;

    
set_cd(cd_handleCD_flNextAttackget_gametime( ) + 0.1 );
    
    return 
FMRES_HANDLED;
}

public 
fwd_CmdStart(iduc_handleseed)
{
    if(!
is_user_alive(id))
        return 
FMRES_IGNORED
        
    
if( get_user_weaponid ) != CSW_KNIFE )
        return 
FMRES_IGNORED;
    
    static 
iButton;
    
iButton get_ucuc_handleUC_Buttons );
    
    if( 
iButton IN_ATTACK )
    {
        
set_ucuc_handleUC_ButtonsiButton & ~IN_ATTACK );
        
        if( !
g_bRoundStarted )
            return 
FMRES_HANDLED;
        
        
ThrowKnifeid );
    }
    
    if( 
iButton IN_ATTACK2 )
    {
        
set_ucuc_handleUC_ButtonsiButton & ~IN_ATTACK2 );
    }
    
    return 
FMRES_HANDLED
}

public 
ThrowKnifeiIndex )
{
    new 
Float:flGametime;
    
flGametime get_gametime( );
    
    if( 
g_flDelayiIndex ] > flGametime KNIFE_DELAY )
        return;
        
    
g_flDelayiIndex ] = flGametime;
    
    new 
Float:flOrigin], Float:flVelocity], Float:flAngles], iEnt;
    
    
entity_get_vectoriIndexEV_VEC_originflOrigin );
    
entity_get_vectoriIndexEV_VEC_v_angleflAngles );
    
    
iEnt create_entity"info_target" );
    
    if( !
iEnt )
    {
        
log_amx"ERROR: Entity isn't valid(%d)!"iEnt );
        return;
    }
        
    
entity_set_stringiEntEV_SZ_classnameKNIFE_ENT );
    
entity_set_modeliEntKNIFE_MODEL );
        
    new 
Float:MinBox] = { -1.0, -7.0, -1.0 };
    new 
Float:MaxBox] = { 1.07.01.0 };
        
    
entity_set_sizeiEntMinBoxMaxBox );
    
    
flAngles] -= 90.0;
    
    
entity_set_originiEntflOrigin );
    
entity_set_vectoriEntEV_VEC_anglesflAngles );
    
    
entity_set_intiEntEV_INT_effects);
    
entity_set_intiEntEV_INT_solid);
    
entity_set_intiEntEV_INT_movetype);
    
    
entity_set_edictiEntEV_ENT_owneriIndex );
    
    
set_renderingiEntkRenderFxGlowShell02500kRenderNormal25 );
    
    
VelocityByAimiIndexKNIFE_SPEEDflVelocity );
    
entity_set_vectoriEntEV_VEC_velocityflVelocity );




All times are GMT -4. The time now is 17:44.

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