AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Use sound when action done. (https://forums.alliedmods.net/showthread.php?t=130114)

SaM.ThE.MaN 06-20-2010 11:39

Use sound when action done.
 
Hi,

hmm , i would like to know how to play a sound , a custom sound when i do something .

Example 1: I jump and the sound plays (HE JUMPED)
Example 2: I shoot and the sound plays (HE SHOT)
etc . etc

wrecked_ 06-20-2010 12:23

Re: Use sound when action done.
 
Code:
#include <amxmodx> #include <fakemeta> #include <hamsandwich> new sound[] = "lala.wav" public plugin_precache() {     precache_sound( sound ) } public plugin_init() {     register_plugin( "Jump Shoot Ex", "1.0", "Wrecked" )         new wname[32]     for( new i = CSW_P228; i < CSW_P90; i++ )     {         if( i != 2 )         {             get_weaponname( i, wname, 31 )             RegisterHam( Ham_Weapon_PrimaryAttack, wname, "HamWeaponAttackPost", 1 )         }     }         RegisterHam( Ham_Player_Jump, "player", "HamJumpPost", 1 ) } public HamJumpPost( id ) {     if( !( pev( id, pev_oldbuttons ) & IN_JUMP ) && is_user_alive( id ) )     {         client_cmd( id, "spk %s", sound )     } } public HamWeaponAttackPost( wep ) {     new id = pev( wep, pev_owner )     if( !( pev( id, pev_oldbuttons ) & IN_ATTACK ) )     {         client_cmd( id, "spk %s", sound )     } }

SaM.ThE.MaN 06-20-2010 13:49

Re: Use sound when action done.
 
oh thanx thanx , another question ,

What if there is a menu,

consisting 2 items :

1. Cow
2. Goat

when i select cow , the sound plays moooo.
and goat it says maaaa.

example :D

drekes 06-20-2010 13:54

Re: Use sound when action done.
 
PHP Code:

#include <amxmodx>

#pragma semicolon 1

new cow[] = "sound/cow.wav";
new 
goat[] = "sound/goat.wav";

public 
plugin_init()
{
    
register_plugin("rofl""1337""Drekes");
    
    
register_clcmd("say /menu""mainmenu");
}

public 
plugin_precache()
{
    
precache_sound(cow);
    
precache_sound(goat);
}

public 
mainmenu(id)
{
    new 
menu menu_create("Animal Menu""sub_mainmenu");
    
    
menu_additem(menu"Cow""1"0);
    
menu_additem(menu"goat""2"0);
    
    
menu_setprop(menuMPROP_EXITMEXIT_ALL);
    
menu_display(idmenu);
}

public 
sub_mainmenu(idmenuitem)
{
    if (
item == MENU_EXIT)
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
    new 
Data[7], Name[64];
    new 
AccessCallback;
    
menu_item_getinfo(menuitemAccessData,5Name63Callback);
    
    new 
Key str_to_num(Data);
    
    switch(
Key)
    {
        case 
1:
            
client_cmd(id"spk ^"%s^""cow);
            
        case 
2:
            
client_cmd(id"spk ^"%s^"");
    }
    
    return 
PLUGIN_HANDLED;



SaM.ThE.MaN 06-20-2010 14:14

Re: Use sound when action done.
 
what is this for : #pragma semicolon 1

wrecked_ 06-20-2010 14:35

Re: Use sound when action done.
 
Quote:

Originally Posted by SaM.ThE.MaN (Post 1214517)
what is this for : #pragma semicolon 1

It makes you put a semicolon at the end of every statement or function or stuff or junk. Search for it, you'll find some topics about it; I actually think I started one a while back.

SaM.ThE.MaN 06-20-2010 16:42

Re: Use sound when action done.
 
Quote:

spk sound/goat.wav
unknown command spk sound/goat.wav

even when i enter a valid address , exp : sound\ambience\cow.wav

it says the same thing.

i think invalid command , anyways not working 4 me

RedRobster 06-20-2010 16:57

Re: Use sound when action done.
 
On this subject, what is the difference between "spk" and "echo"? I have seen both used, but never got the difference.

**If I'm not mistaken, you will also have to precache the sounds for them to work.

drekes 06-20-2010 17:00

Re: Use sound when action done.
 
Quote:

Originally Posted by RedRobster (Post 1214722)
On this subject, what is the difference between "spk" and "echo"? I have seen both used, but never got the difference.

**If I'm not mistaken, you will also have to precache the sounds for them to work.

spk is to play .wav files, echo is to print something in console afaik.

yes, you need to precache them.

Edit: I changed the code, try now


All times are GMT -4. The time now is 14:55.

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