AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   No sound emited by entity (https://forums.alliedmods.net/showthread.php?t=250327)

CryWolf 10-22-2014 07:36

No sound emited by entity
 
Hi AM community, i have created an entity binded to a console comand and i want to add sounds to it when players are around , just it doesn't work and i don't know why, some help please

My code
PHP Code:

new const d_sounds [ ] [ ] =
{
    
"barnacle/bcl_alert2.wav",
    
"x/nih_die2.wav",
    
"x/x_pain1.wav",
    
"x/x_pain2.wav",
    
"x/x_pain3.wav"


and plugin_init
PHP Code:

register_forward FM_Think"PmPSound" ); 

now the forward
PHP Code:

public PmPSound entchannel, const sound [ ] )
{
    static 
classname 32 ];
    
pev(ent,pev_classname,classname,31);
    
    if(
equali(classnameitem_name))
    {
        if ( 
get_pcvar_num pCvar_sound ) )
        {
            new 
random sizeof d_sounds ) );
            
emit_sound entCHAN_VOICEd_sounds ], VOL_NORMATTN_NORM0PITCH_NORM );
            return 
FMRES_SUPERCEDE;
        }
    }
    return 
FMRES_IGNORED;


and created entity
PHP Code:

new ent engfunc EngFunc_CreateNamedEntityengfunc EngFunc_AllocString"info_target" ) );
    
set_pev entpev_classnameitem_name );
    
engfunc EngFunc_SetModelentp_model ); 

+ the global
PHP Code:

new const item_name [ ] = "dm_pumplin" 

what's wrong here ? because i hear no sound when i'm around entity.

jimaway 10-22-2014 07:53

Re: No sound emited by entity
 
does your entity even "think"

post full code

red_bull2oo6 10-22-2014 08:02

Re: No sound emited by entity
 
as jimaway said i think here is the problem..
your entity never think

PHP Code:

new ent engfunc EngFunc_CreateNamedEntityengfunc EngFunc_AllocString"info_target" ) );
    
set_pev entpev_classnameitem_name );
    
engfunc EngFunc_SetModelentp_model ); 

->>

PHP Code:

new ent engfunc EngFunc_CreateNamedEntityengfunc EngFunc_AllocString"info_target" ) );
set_pev entpev_classnameitem_name );
engfunc EngFunc_SetModelentp_model ); 
set_pev entpev_nextthinkget_gametime( ) + 0.1 ); 

you need to make it instantly think after you create it.. and you'll set the new 'think delay' in the thinking forward.

-->
PHP Code:

public PmPSound entchannel, const sound [ ] )
{
    static 
classname 32 ];
    
pev(ent,pev_classname,classname,31);
    
    if(
equali(classnameitem_name))
    {
        
set_peventpev_nextthinkget_gametime( ) + 1.0 ); // your delay instead 1.0 
        
        
if ( get_pcvar_num pCvar_sound ) )
        {
            new 
random sizeof d_sounds ) );
            
emit_sound entCHAN_VOICEd_sounds ], VOL_NORMATTN_NORM0PITCH_NORM );
            return 
FMRES_SUPERCEDE;
        }
    }
    return 
FMRES_IGNORED;



CryWolf 10-22-2014 10:01

Re: No sound emited by entity
 
Thanks red it works but don't know why only the first time when spawning the entity.

Intra si tu in pana mea pe steam :))

HamletEagle 10-22-2014 10:44

Re: No sound emited by entity
 
Add this set_pev( ent, pev_nextthink, get_gametime( ) + 1.0 ); // your delay instead 1.0 outside the if( ) check. Also, PmSound is not a good name since it's almost the same as PM_Sound. You may want to choose a better name.

CryWolf 10-23-2014 10:16

Re: No sound emited by entity
 
Thanks guys Solved!
:)

Salutare!


All times are GMT -4. The time now is 19:59.

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