Thread: [Request] Play a sound below X hp

Results 1 to 9 of 9
  1. #1
    Registered User Joce's Avatar
    Join Date
    Feb 2016
    Location
    Paris
    Posts
    101

    [Request] Play a sound below X hp

    Hello,

    I need a plugin that plays a sound for the players having "15HP" or less for example. I'm gonna put the heartbeat sound. I hope it would be possible with AS...

    Note: If the player takes a medkit and has more than "15HP", the sound will stop.

    Thanks
    Last edited by Joce; 29-10-2016 at 07:41 AM.

  2. #2
    warrior spy-warrior's Avatar  
    Contributor
    Join Date
    Nov 2006
    Location
    Europe, France, Paris
    Posts
    2,965

    Re: [Request] Play a sound below X hp

    +1
    Patience is a virtue greatly needed by those who attempt great things.
    La patience est une vertu fort nécessaire à ceux qui tentent de réaliser de grandes choses.

    Server SvenCoop
    I love the mods svencoop
    World time zone & Look clocks

  3. #3
    Registered User Joce's Avatar
    Join Date
    Feb 2016
    Location
    Paris
    Posts
    101

    Re: [Request] Play a sound below X hp

    Help !

  4. #4
    Registered User takedeppo.50cal's Avatar
    Join Date
    Jan 2016
    Location
    Japan
    Posts
    15

    Re: [Request] Play a sound below X hp

    .... Like this? ↓↓↓

    Code:
    /////////////////////////////////////////////
    // Warning Low Health
    /////////////////////////////////////////////
    
    const string SOUND_FILE = "fvox/warning.wav"; // SOUND
    const int FLAG_ENABLED  = 1;
    const int FLAG_DISABLED = 0;
    
    CScheduledFunction@ g_pTimer = null;
    CCVar@ g_pThreshold;
    CCVar@ g_pInterval;
    CCVar@ g_pEnabled;
    
    /** Plugin Init */
    void PluginInit() {
        // ** Set your name and info here....(^^;)b yay
        g_Module.ScriptInfo.SetAuthor("-----YOUR-NAME-------");
        g_Module.ScriptInfo.SetContactInfo("xxxx@mail/url");
        
        // Event hook
        g_Hooks.RegisterHook(Hooks::Game::MapChange, @MapChange);
        
        // CVAR
        @g_pThreshold = CCVar("threshold", 15, "Threshold health value[number]", ConCommandFlag::AdminOnly);
        @g_pInterval  = CCVar("interval", 3.0, "Check interval[seconds]", ConCommandFlag::AdminOnly);
        @g_pEnabled   = CCVar("enabled", FLAG_ENABLED, "0:disabled 1:enabled", ConCommandFlag::AdminOnly);
    }
    
    /** Map Initialize */
    void MapInit() {
        // Precache
        g_Game.PrecacheGeneric("sound/" + SOUND_FILE);
        g_SoundSystem.PrecacheSound(SOUND_FILE);
        
        // Timer
        @g_pTimer = g_Scheduler.SetInterval("HealthCheckTimer", g_pInterval.GetFloat());
    }
    
    /** Map Change */
    HookReturnCode MapChange() {
        if (g_pTimer !is null) {
            g_Scheduler.RemoveTimer(g_pTimer);
        }
        return HOOK_CONTINUE;
    }
    
    /** Timer function */
    void HealthCheckTimer() {
        if (g_pEnabled.GetInt() == FLAG_ENABLED) {
            
            // Check each player
            for (int i = 1; i <= g_Engine.maxClients; i++) {
                CBasePlayer@ pPlayer = g_PlayerFuncs.FindPlayerByIndex(i);
                if ((pPlayer !is null)
                    && (pPlayer.IsConnected())
                    && (pPlayer.IsAlive())
                    && (pPlayer.pev.health <= g_pThreshold.GetInt())
                ) {
                    g_SoundSystem.PlaySound(pPlayer.edict(), CHAN_AUTO, SOUND_FILE, 1.0f, ATTN_NORM, 0, 100);
                }
            }
        }
    }

  5. #5
    Registered User Joce's Avatar
    Join Date
    Feb 2016
    Location
    Paris
    Posts
    101

    Re: [Request] Play a sound below X hp

    Thank you

  6. #6
    Registered User Joce's Avatar
    Join Date
    Feb 2016
    Location
    Paris
    Posts
    101

    Re: [Request] Play a sound below X hp

    Hey,

    I've just noticed that the sound playing is played several times at the same time, whatever the sound.

    Could you fix that ?

  7. #7
    Registered User takedeppo.50cal's Avatar
    Join Date
    Jan 2016
    Location
    Japan
    Posts
    15

    Re: [Request] Play a sound below X hp

    This code is simple code.
    Just check all players every 3 seconds (by default), and play each sound when they are low health.
    so, you will heard duplicate sound at same time when mates who are low health stay close.

    Do you want to play the sound of each player at individual timing?
    Tell me clearly.
    (sry, I can't understand what you wish and problem well.)

    btw, my code is just one of method .... d(^^;) yay

  8. #8
    Registered User Joce's Avatar
    Join Date
    Feb 2016
    Location
    Paris
    Posts
    101

    Re: [Request] Play a sound below X hp

    Quote Originally Posted by takedeppo.50cal View Post
    This code is simple code.
    Just check all players every 3 seconds (by default), and play each sound when they are low health.
    so, you will heard duplicate sound at same time when mates who are low health stay close.

    Do you want to play the sound of each player at individual timing?
    Tell me clearly.
    (sry, I can't understand what you wish and problem well.)

    btw, my code is just one of method .... d(^^ yay
    Hi. Sorry for the delay.

    Nevermind it was a problem with the sound itself, the plugin does work great.

    Last question: I don't want to hear heart of the others players, is it possible to disable this feature ?

  9. #9
    Registered User takedeppo.50cal's Avatar
    Join Date
    Jan 2016
    Location
    Japan
    Posts
    15

    Re: [Request] Play a sound below X hp

    Change this code (→ L.59 ?)
    Code:
    g_SoundSystem.PlaySound(pPlayer.edict(), CHAN_AUTO, SOUND_FILE, 1.0f, ATTN_NORM, 0, 100);
    to ....
    Code:
    g_SoundSystem.PlaySound(pPlayer.edict(), CHAN_AUTO, SOUND_FILE, 1.0f, ATTN_NORM, 0, 100, i);
    According to https://github.com/baso88/SC_AngelSc...stem#playsound ,
    8th argument of this function seems target player for playback.

    I recently noticed. (((( ゚ω゚) I learned something new.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •