Author Topic: Playing Sounds Through Player  (Read 2055 times)

I know its possible but I was wondering how. How do you play sounds through a player. Like this.

Code: [Select]
serverCmdTest(%client)
  {
     if(isObject(%client.player))
      %client.Play2D(F3_LevelUp);
  }

Code doesn't work but what would? Just wondering.

Code: [Select]
serverPlay3D(soundProfile,%client.player.getPosition());

Didn't work. Anyone else know? Here's my code.

Code: [Select]
datablock AudioProfile(F3_LevelUp)
{
filename = "./F3_LevelUp.wav";
description = AudioClosest3d;
preload = true;
};


function LevelUp(%client)

  if(%client.exp >= %client.needexp)
  { 
  %client.level++; %client.exp = 0; %client.needexp = 100 * %client.level;
  serverPlay3D(F3_LevelUp,%client.player.getPosition());
  }
}

%client.play2D(%sound)
Will play a sound datablock to a client, nobody else will hear it.

serverPlay2D(%sound)
Will play a sound datablock to all clients on the server, given that its downloaded of course.

If both of these don't work, you've probably got something wrong with the sound file. Make sure its mono.

I'd guess there's something wrong with your "experience" logic elsewhere in the script. Post the whole thing.

%client.play2D(%sound)
Will play a sound datablock to a client, nobody else will hear it.

serverPlay2D(%sound)
Will play a sound datablock to all clients on the server, given that its downloaded of course.

If both of these don't work, you've probably got something wrong with the sound file. Make sure its mono.

He's talking about 3D though, which, however, is just as simple:
Well not necessarily, but it would seem so (kind of).
In any case, for reference:

GameConnection::play3D(AudioProfile sound, Vector3F origin)
Plays a sound at the specified position, however only the client will be able to hear it.

serverPlay3D(AudioProfile sound, Vector3F origin)
Runs GameConnection::play3D for everyone on the server with the given arguments.

Can you give an example of playing audio inside of a function?


Ripped from Space Guy's playSound extensions mod:
Play a sound to a single client:
%client.play2D(%sound);

Play a sound from a player object (hearable to players around them)
serverplay3d(%sound,%player.getHackPosition() SPC "0 0 1 0");

Also:
Play a sound to the entire server:
ServerPlay2D(%sound);

Play a sound to everyone in a minigame:
for(%i=0;%i<%mini.numMembers;%i++)
{
    %client=%mini.member[%i];
    //check for hacky dedicated minigame mods or AIConnections
    if(isObject(%client) && %client.getClassName() $= "GameConnection")
    {
         %client.play2d(%sound);
    }
}


I used most of this stuff in the renderman mod, so it definitely works. If I made any errors typing it up here I'm sure someone will graciously point them out.

Unable to find play2D. Whats the issue?

Unable to find play2D. Whats the issue?

You're probably calling it on the player. Call it on the client.

Isn't there also: %client.player.playAudio(AUDIO); ??

Isn't there also: %client.player.playAudio(AUDIO); ??

Yes, that's mainly for longer sounds (or looping sounds) in case you want the source of the sound to stay on the player.
For example, I used it in my TF2 gamemode for looping a "crit boost" sound on the player.

%player.playAudio(1, critBoostLoopSound);

Alright, I got it to work. Thanks for the help guys!