Author Topic: Player death, Player nearby plays sound  (Read 3713 times)

When a Player dies, a player nearby (distance in a small radius) Plays a sound. How would this be implemented? As a playertype? A server addon, script addon?

Server sided, probably. I don't see how this could be made any other way.

A radius search, so yea, a server-sided script.

Sweet, im really happy its not a playertype, however, i gave it a shot and failed miserably, i had tried for 2 hours. I need some help here. If you guys where going to do this, what functions and arguments would you guys use?

I'm slightly confused by 'nearby player plays a sound.'

Are they broadcasting a sound to nearby players? To every player on the server?

Or is only the nearby player hearing the sound?

All of these things are scripted differently, so please be as specific as possible.

I'm slightly confused by 'nearby player plays a sound.'

Are they broadcasting a sound to nearby players? To every player on the server?

Or is only the nearby player hearing the sound?

All of these things are scripted differently, so please be as specific as possible.
Or is the sound coming out of nearby players?

Or is the sound coming four of nearby players and only they can hear it?

Alright so heres what im shooting for: When a player dies, if a player close to the other player that died THAT player (Still living) will play a sound (just a regular 3d sound that uses an Audio DataBlock). Heres an example: *Gunfire*  *Team member1 dies* Team member2: "Oh stuff they dropped him!" Something like that. however I want to use a search radius to find a nearby player for the sound to play, not the whole server to hear.

So to initiate a search radius:

initContainerRadiusSearch( center , radius , typemask , exclusions )

It sounds like you'd want to use the $TypeMasks::PlayerObjectType typemask.

Then to loop through:

while(%obj = containerSearchNext())
    //play sound at %obj.getHackPosition()


Finally, to play a sound, use serverPlay3D( Sound_Profile , center )

Is it more efficient to do a radius search, or just loop through the clientgroup? (obviously it wouldn't work with bots though)

Code: [Select]
datablock AudioProfile(Suppressed)
{
   filename    = "./Suppressed.wav";
   description = AudioDefault3d;
   preload = true;
};
initContainerRadiusSearch( center , radius , $typemask , exclusions )
{
$TypeMasks::PlayerObjectType typemask;
while(%obj = containerSearchNext());
    %obj.getHackPosition();
serverPlay3D(Suppressed, center );
}

Im trash at radius'. So im confused with the arguments "Center" and "radius" and especially "exlusions" So far this is what i have. I need further assistance. Also im lost as to what i would call the function. As you can see im so handicapped as to have not included it.

Is it more efficient to do a radius search, or just loop through the clientgroup? (obviously it wouldn't work with bots though)
Position comparisons are string comparisons and thus inherently expensive in TorqueScript. It'd be a tough call, but I think radius searches would be faster.

initContainerRadiusSearch is not a control flow statement, so you can't put a bracket after it. It has to go inside a function, and the while statement I gave to loop through the results is the control flow statement.

Code: [Select]
function Player::playSoundFromNearbyPlayers(%this) {
    initContainerRadiusSearch(%this.getHackPosition(), 20, $TypeMasks::PlayerObjectType, %this);
    while(%obj = containerSearchNext()) {
        serverPlay3D(Supressed, %obj.getHackPosition());
    }
}

"center" is the center of the raycast, then the center of the sound later on. Radius is how wide the search is. Exclusions are objects that are excluded from the search, in this case that's the player at the dead center of the search (the player causing nearby players to play a sound).
« Last Edit: September 28, 2014, 07:31:06 PM by $trinick »

Position comparisons are string comparisons and thus inherently expensive in TorqueScript. It'd be a tough call, but I think radius searches would be faster.

initContainerRadiusSearch is not a control flow statement, so you can't put a bracket after it. It has to go inside a function, and the while statement I gave to loop through the results is the control flow statement.

Code: [Select]
function Player::playSoundFromNearbyPlayers(%this) {
    initContainerRadiusSearch(%this.getHackPosition(), 20, $TypeMasks::PlayerObjectType, %this);
    while(%obj = containerSearchNext()) {
        serverPlay3D(Supressed, %obj.getHackPosition());
    }
}

"center" is the center of the raycast, then the center of the sound later on. Radius is how wide the search is. Exclusions are objects that are excluded from the search, in this case that's the player at the dead center of the search (the player causing nearby players to play a sound).

Okay, sweet, ima give this another shot.