Author Topic: [SCRIPT] Randomized Sounds on Spawn/Death/Kill  (Read 2285 times)

Hoping this would be a simple script, but basically if a user is in a minigame, play random sounds.

So how would I do this if I ONLY want to play sounds to the client and not touch the spawn/death functions? Like, reduced so pseudo-code:

Code: (Example Pseudo-code) [Select]
onPlayerSpawn {
    if client.inMinigame {
        client.playSound(Datablock)
    };
};
onPlayerDeath {
    if client.inMinigame {
        client.playRandomSound(Datablock2, Datablock3, Datablock4)
    };
};
onPlayerKill {
    if client(killer).inMinigame {
        client(killer).playRandomSound(Datablock5, Datablock6, Datablock7)
    };
};

That's it.
« Last Edit: October 25, 2019, 01:27:14 PM by SWAT One »

the default spawning and death sounds might overwhelm the client-sided sound you're playing, depending on what kind of sound it is

Added in that the player death sound should not play. But I already mentioned before that the default player spawning sound should not play.

seems like all the spawn stuff is in one function
Code: [Select]
function GameConnection::createPlayer(%client, %spawnPoint)
{
[...]

%p = new Projectile ()
{
dataBlock       = spawnProjectile;
initialVelocity = "0 0 0";
initialPosition = %player.getHackPosition();
sourceObject    = %player;
sourceSlot      = 0;
client          = %client;
};

[...]
}

so i guess for that either need to remove/change how the spawn explosion works
or overwrite all of the spawning code?

Added in that the player death sound should not play. But I already mentioned before that the default player spawning sound should not play.
so all death and respawn sounds will just be completely silent except to the one who respawns/dies? like, if you just erase the death sound and play your custom sound to the client, it will kinda be awkward for everyone else because you'll just shoot someone and they'll fall over and die silently

changing/randomizing the death sound is easy because all you have to do is overwrite player::playDeathCry to do literally nothing and then simply play an sfx at the player position when gameConnection::onDeath is called.
Code: [Select]
//Death Sounds
datablock AudioProfile(RanDeathSFX1)
{
    fileName = "./randeath1.wav";
    description = AudioDefault3d;
    preload = false;
};
//All others are inherited from above to save on datablocks - not enough people do this!
datablock AudioProfile(RanDeathSFX2 : RanDeathSFX1)
{
    fileName = "./randeath2.wav";
};
datablock AudioProfile(RanDeathSFX3 : RanDeathSFX1)
{
    fileName = "./randeath3.wav";
};
datablock AudioProfile(RanDeathSFX4 : RanDeathSFX1)
{
    fileName = "./randeath4.wav";
};
package RanDeathSFX
{
    //Get a random sound when the player dies
    function gameConnection::onDeath(%this)
    {
serverplay3d("randeathsfx" @ getRandom(1,4) , %this.player.getHackPosition() SPC "0 0 1 0");
return parent::onDeath(%this);
    }
    //Play the death SFX's
    function player::playDeathCry(%this)
    {
        //do nothing
    }
};
activatepackage(RanDeathSFX);

Editing the player body remove(poof!) and spawn sounds are a little more complicated. 




So how would I do this if I ONLY want to play sounds to the client and not touch the spawn/death functions? Like, reduced so pseudo-code:

Code: (Example Pseudo-code) [Select]
onPlayerSpawn {
    if client.inMinigame {
        client.playSound(Datablock)
    };
};
onPlayerDeath {
    if client.inMinigame {
        client.playRandomSound(Datablock2, Datablock3, Datablock4)
    };
};
onPlayerKill {
    if client(killer).inMinigame {
        client(killer).playRandomSound(Datablock5, Datablock6, Datablock7)
    };
};
« Last Edit: October 24, 2019, 02:55:50 PM by SWAT One »

if I ONLY want to play sounds to the client
do you mean with the defaults, or removing the defaults

playing with the defaults should be easy
playing without the defaults would require removing the defaults somehow
you might be able to overwrite the default sounds, similar to how you can do that with textures

Nah I mean, what if I don't want to mess with the defaults at all. Tbh, it's not hugely important. The random sound-playing aspect is what's most important to me.
« Last Edit: October 24, 2019, 07:45:19 PM by SWAT One »

do you mean with the defaults, or removing the defaults

playing with the defaults should be easy
playing without the defaults would require removing the defaults somehow
you might be able to overwrite the default sounds, similar to how you can do that with textures
There is a function stopAudio(); but I haven't done any extensive testing using it to end default sounds/rewriting default functions to end the audio prematurely

Updated op. Not asking for overwriting functions or stopping audio any more. Just wanting to play randomized sounds off of the player objects.

there's a lot of randomized death sound mods like the tourettes guy one, you could modify to play another set of sounds from the killer player

and can probably modify that to also work on spawn

So to be clear, you're okay with the default spawn and death sounds, you just want to add sounds to the client onSpawn, and onDeath, and 'onKill' (which is still the onDeath function, we just play a sound to the sourceClient aka the killer)
« Last Edit: November 21, 2019, 03:25:25 PM by Goth77 »

the easiest way is to change the sound filename references of the default death poof and spawn poof sound effects to a very short completely silent sound before the game finishes loading, then simply package removeBody and createPlayer and add your sound things to it

the default sounds will still 'play' but they will be a completely silent sound